cover and verify detaching from ScopedPtrVect
This commit is contained in:
parent
13b795016b
commit
0a1256f4e3
2 changed files with 45 additions and 4 deletions
|
|
@ -134,6 +134,7 @@ namespace lib {
|
|||
* Otherwise, NULL will be returned and the
|
||||
* collection of managed objects remains unaltered
|
||||
* @note EX_STRONG
|
||||
* @todo TICKET #856 better return a Maybe<T&> instead of a pointer?
|
||||
*/
|
||||
T*
|
||||
detach (void* objAddress)
|
||||
|
|
@ -177,8 +178,8 @@ namespace lib {
|
|||
typedef ConstIterType const_iterator;
|
||||
|
||||
iterator begin() { return iterator (allPtrs()); }
|
||||
const_iterator begin() const { return const_iterator::build_by_cast (allPtrs()); }
|
||||
iterator end() { return iterator ( RIter() ); }
|
||||
const_iterator begin() const { return const_iterator::build_by_cast (allPtrs()); }
|
||||
const_iterator end() const { return const_iterator::nil(); }
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -43,7 +43,9 @@ namespace test{
|
|||
|
||||
/********************************************************************
|
||||
* @test ScopedPtrVect manages the lifecycle of a number of objects.
|
||||
* @todo implement detaching of objects
|
||||
* The API is similar to a vector and allows for element access
|
||||
* and iteration. Individual elements can be detached and thus
|
||||
* removed from the responsibility of the container.
|
||||
*/
|
||||
class ScopedPtrVect_test : public Test
|
||||
{
|
||||
|
|
@ -53,7 +55,7 @@ namespace test{
|
|||
{
|
||||
simpleUsage();
|
||||
iterating();
|
||||
// detaching();
|
||||
detaching();
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -91,7 +93,7 @@ namespace test{
|
|||
holder.manage (new Dummy);
|
||||
holder.manage (new Dummy);
|
||||
CHECK (9 == holder.size());
|
||||
CHECK (0!=checksum);
|
||||
CHECK (0 < checksum);
|
||||
}
|
||||
CHECK (0==checksum);
|
||||
}
|
||||
|
|
@ -143,8 +145,46 @@ namespace test{
|
|||
CHECK (0==checksum);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
detaching()
|
||||
{
|
||||
int id2, id3;
|
||||
Dummy* extracted(0);
|
||||
CHECK (0==checksum);
|
||||
{
|
||||
VectD holder;
|
||||
CHECK (0 == checksum);
|
||||
CHECK (isnil (holder));
|
||||
|
||||
holder.manage (new Dummy);
|
||||
holder.manage (new Dummy);
|
||||
holder.manage (new Dummy);
|
||||
holder.manage (new Dummy);
|
||||
holder.manage (new Dummy);
|
||||
CHECK (5 == holder.size());
|
||||
CHECK (0 < checksum);
|
||||
|
||||
id2 = holder[2].getVal();
|
||||
id3 = holder[3].getVal();
|
||||
|
||||
extracted = holder.detach(& holder[2]);
|
||||
CHECK (id2 == extracted->getVal());
|
||||
CHECK (id3 == holder[2].getVal());
|
||||
CHECK (4 == holder.size());
|
||||
}
|
||||
CHECK (0 < checksum); // not all dummies are dead
|
||||
CHECK (id2 == checksum); // #2 is alive!
|
||||
|
||||
extracted->setVal(id2+id3);
|
||||
CHECK (id2+id3 == checksum);
|
||||
|
||||
delete extracted;
|
||||
CHECK (0 == checksum);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
LAUNCHER (ScopedPtrVect_test, "unit common");
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue