text
stringlengths 0
2.2M
|
---|
// Create 'my_Class' objects and assign to each object a counter
|
// variable initialized to 0. Verify that the counter is incremented
|
// after each 'my_Class' object is destroyed.
|
//
|
// Next create 'my_Pool' objects and assign to each object a counter
|
// variable initialized to 0. Invoke the 'deallocate' method and
|
// verify that the counter is incremented.
|
//
|
// Testing:
|
// Helper Class: 'my_Class'
|
// Helper Class: 'my_Pool'
|
// --------------------------------------------------------------------
|
if (verbose) printf("\nHELPER CLASS TEST"
|
"\n=================\n");
|
if (verbose) printf("\nTesting 'my_Class'.\n");
|
if (verbose) printf("\tTesting default ctor and dtor.\n");
|
{
|
int counter = 0;
|
const int NUM_TEST = 5;
|
for (int i = 0; i < NUM_TEST; ++i) {
|
LOOP_ASSERT(i, counter == i);
|
my_Class mx(&counter);
|
}
|
ASSERT(NUM_TEST == counter);
|
}
|
if (verbose) printf("\nTesting 'my_Pool'.\n");
|
if (verbose) printf("\tTesting default ctor and 'deallocate'.\n");
|
{
|
int counter = 0;
|
const int NUM_TEST = 5;
|
for (int i = 0; i < NUM_TEST; ++i) {
|
LOOP_ASSERT(i, i == counter);
|
my_Pool mx(&counter);
|
mx.deallocate(0);
|
LOOP_ASSERT(i, i + 1 == counter);
|
}
|
ASSERT(NUM_TEST == counter);
|
}
|
}break;
|
case 1: {
|
// --------------------------------------------------------------------
|
// BREATHING TEST
|
//
|
// Concerns:
|
// 1) The 'bslma::RawDeleterProctor' can be constructed and
|
// destructed gracefully.
|
// 1) The allocator's 'deallocate' method is invoked.
|
// 2) The (managed) object's destructor is invoked.
|
//
|
// Plan:
|
// Allocate a 'std::string' with a 'bslma::TestAllocator' and guard
|
// it with 'bslma::RawDeleterProctor' to show that both the
|
// destructor and 'deallocate' is called (by verifying all memory is
|
// returned to the 'bslma::TestAllocator').
|
//
|
// Testing:
|
// Breathing Test
|
// --------------------------------------------------------------------
|
if (verbose) printf("\nBREATHING TEST"
|
"\n==============\n");
|
using std::string;
|
bslma::TestAllocator allocator(veryVeryVeryVerbose);
|
const bslma::TestAllocator& Z = allocator;
|
if (verbose) printf("\tTesting with 'string' object\n");
|
{
|
string *s = (string *)new(allocator)string();
|
ASSERT(0 < Z.numBytesInUse());
|
*s = "Hello World!";
|
bslma::RawDeleterProctor<string, bslma::Allocator> guard(
|
s,
|
&allocator);
|
}
|
ASSERT(0 == Z.numBytesInUse());
|
} break;
|
default: {
|
fprintf(stderr, "WARNING: CASE `%d' NOT FOUND.\n", test);
|
testStatus = -1;
|
}
|
}
|
if (testStatus > 0) {
|
fprintf(stderr, "Error, non-zero test status = %d.\n", testStatus);
|
}
|
return testStatus;
|
}
|
// ----------------------------------------------------------------------------
|
// Copyright 2013 Bloomberg Finance L.P.
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.