text
stringlengths 0
2.2M
|
---|
ASSERT(sizeof(my_Class) == Z.numBytesInUse());
|
z.deleteObject(pC);
|
ASSERT(1 == counter);
|
ASSERT(0 == Z.numBytesInUse());
|
}break;
|
case 3: {
|
// --------------------------------------------------------------------
|
// CTOR / DTOR TEST
|
//
|
// Concerns:
|
// 1) Verify that the proctor object properly deletes different types
|
// of managed objects on destruction using the allocator supplied at
|
// construction. The concerns are:
|
//
|
// a) Single inheritance object with derived class pointer
|
// b) Single inheritance object with base class pointer
|
// c) Multiple inheritance object with derived class pointer
|
//
|
// 2) When an allocator (or pool) not inherited from
|
// 'bslma::Allocator' is supplied to the 'bslma::RawDeleterProctor',
|
// the destructor of the managed object and 'deallocate' method of
|
// the allocator (or pool) supplied is still invoked.
|
//
|
// Plan:
|
// Create a 'myChild' object, which increments a counter every time
|
// it is destructed, using a 'bslma::TestAllocator' which keeps track
|
// of how many bytes are allocated. Next create a
|
// 'bslma::RawDeleterGuard' object to guard the created 'myChild'
|
// object. When the guard object goes out of scope, verify that both
|
// the counter is incremented and memory is deallocated. Next,
|
// repeat by creating 'myParent' object to address concern 1b. Next,
|
// repeat by creating 'myMostDerived' object to address concern 1c.
|
//
|
// Finally, repeat all three steps above using 'my_Pool' as the
|
// parameterized 'ALLCOATOR' type, which does not inherit from
|
// 'bslma::Allocator'.
|
//
|
// Testing:
|
// bslma::RawDeleterProctor<TYPE, ALLOCATOR>(obj, allocator);
|
// ~bslma::RawDeleterProctor<TYPE, ALLOCATOR>();
|
// Concern: the (non-virtual) 'deallocate' method for pools is also
|
// invoked
|
// --------------------------------------------------------------------
|
if (verbose) printf("\nCTOR / DTOR TEST"
|
"\n================\n");
|
bslma::TestAllocator z(veryVeryVeryVerbose);
|
const bslma::TestAllocator& Z = z;
|
int counter = 0;
|
if (verbose) printf("\nTesting with bslma::TestAllocator\n");
|
{
|
if (verbose) printf("\tTesting single inheritance with derived "
|
"class pointer\n");
|
{
|
myChild *pC = new(z) myChild(&counter);
|
ASSERT(0 == counter);
|
ASSERT(sizeof(myChild) == Z.numBytesInUse());
|
bslma::RawDeleterProctor<myChild, bslma::Allocator>
|
proctor(pC, &z);
|
ASSERT(0 == counter);
|
ASSERT(sizeof(myChild) == Z.numBytesInUse());
|
}
|
ASSERT(1 == counter);
|
ASSERT(0 == Z.numBytesInUse());
|
counter = 0; // reset counter
|
if (verbose) printf("\tTesting single inheritance with base "
|
"class pointer\n");
|
{
|
myParent *pP = new(z) myChild(&counter);
|
ASSERT(0 == counter);
|
ASSERT(sizeof(myChild) == Z.numBytesInUse());
|
bslma::RawDeleterProctor<myParent, bslma::Allocator>
|
proctor(pP, &z);
|
ASSERT(0 == counter);
|
ASSERT(sizeof(myChild) == Z.numBytesInUse());
|
}
|
ASSERT(1 == counter);
|
ASSERT(0 == Z.numBytesInUse());
|
counter = 0; // reset counter
|
if (verbose) printf("\tTesting multiple inheritance with derived "
|
"class pointer\n");
|
{
|
myMostDerived *pMD = new(z) myMostDerived(&counter);
|
ASSERT(0 == counter);
|
ASSERT(sizeof(myMostDerived) == Z.numBytesInUse());
|
bslma::RawDeleterProctor<myMostDerived, bslma::Allocator>
|
proctor(pMD, &z);
|
ASSERT(0 == counter);
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.