text
stringlengths 0
2.2M
|
---|
// Plan:
|
// Create a 'my_Class' object using a 'bslma::TestAllocator' and
|
// initialize it with a counter. Next create another 'my_Class'
|
// object and initialize it with a different counter. Finally
|
// initialize a 'bslma::RawDeleterProctor' object with the first
|
// object and 'bslma::TestAllocator'. Call 'reset' on the proctor
|
// with the second object before it goes out of scope. Once the
|
// proctor goes out of scope, verify that only the second counter is
|
// incremented, and only the memory allocated by the second test
|
// allocator is deallocated.
|
//
|
// Testing:
|
// void reset(obj);
|
// --------------------------------------------------------------------
|
if (verbose) printf("\n'reset' TEST"
|
"\n============\n");
|
bslma::TestAllocator z(veryVeryVeryVerbose);
|
const bslma::TestAllocator& Z = z;
|
int counter1 = 0;
|
int counter2 = 0;
|
if (verbose) printf("\nTesting the 'reset' method\n");
|
my_Class *pC1;
|
{
|
pC1 = new(z) my_Class(&counter1);
|
my_Class *pC2 = new(z) my_Class(&counter2);
|
ASSERT(0 == counter1);
|
ASSERT(0 == counter2);
|
ASSERT(2 * sizeof(my_Class) == Z.numBytesInUse());
|
bslma::RawDeleterProctor<my_Class, bslma::Allocator> proctor(pC1,
|
&z);
|
ASSERT(0 == counter1);
|
ASSERT(0 == counter2);
|
ASSERT(2 * sizeof(my_Class) == Z.numBytesInUse());
|
proctor.reset(pC2);
|
ASSERT(0 == counter1);
|
ASSERT(0 == counter2);
|
ASSERT(2 * sizeof(my_Class) == Z.numBytesInUse());
|
}
|
ASSERT(0 == counter1);
|
ASSERT(1 == counter2);
|
ASSERT(sizeof(my_Class) == Z.numBytesInUse());
|
z.deleteObject(pC1);
|
ASSERT(1 == counter1);
|
ASSERT(1 == counter2);
|
ASSERT(Z.numBytesInUse() == 0);
|
}break;
|
case 4: {
|
// --------------------------------------------------------------------
|
// 'release' TEST
|
//
|
// Concerns:
|
// Verify that when the 'release' method is called, the proctor
|
// object properly releases from management the object currently
|
// managed by this proctor.
|
//
|
// Plan:
|
// Create 'my_Class' objects using 'bslma::TestAllocator' and
|
// initialize it with a counter. Next initialize a
|
// 'bslma::RawDeleterProctor' object with the corresponding
|
// 'my_Class' object and 'bslma::TestAllocator'. Call 'release' on
|
// the proctor before it goes out of scope. Verify that the counter
|
// is not incremented, and the memory allocated by the test
|
// allocator is not deallocated.
|
//
|
// Testing:
|
// void release();
|
// --------------------------------------------------------------------
|
if (verbose) printf("\n'release' TEST"
|
"\n==============\n");
|
bslma::TestAllocator z(veryVeryVeryVerbose);
|
const bslma::TestAllocator& Z = z;
|
int counter = 0;
|
if (verbose) printf("\nTesting the 'release' method\n");
|
my_Class *pC;
|
{
|
pC = new(z) my_Class(&counter);
|
ASSERT(0 == counter);
|
ASSERT(sizeof(my_Class) == Z.numBytesInUse());
|
bslma::RawDeleterProctor<my_Class, bslma::Allocator>
|
proctor(pC, &z);
|
ASSERT(0 == counter);
|
ASSERT(sizeof(my_Class) == Z.numBytesInUse());
|
proctor.release();
|
ASSERT(0 == counter);
|
ASSERT(sizeof(my_Class) == Z.numBytesInUse());
|
}
|
ASSERT(0 == counter);
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.