text
stringlengths
0
2.2M
// an allocator as a second argument. In production code, a constructor proxy
// that checks the traits of 'TYPE' (to determine whether 'TYPE' uses
// 'bslma::Allocator') should be used (see bslalg_constructorproxy).
//=============================================================================
// MAIN PROGRAM
//-----------------------------------------------------------------------------
int main(int argc, char *argv[])
{
int test = argc > 1 ? atoi(argv[1]) : 0;
bool verbose = argc > 2;
bool veryVerbose = argc > 3;
bool veryVeryVerbose = argc > 4;
bool veryVeryVeryVerbose = argc > 5;
(void)veryVerbose; // suppress unused variable warning
(void)veryVeryVerbose; // suppress unused variable warning
printf("TEST " __FILE__ " CASE %d\n", test);
switch (test) { case 0: // Zero is always the leading case.
case 6: {
// --------------------------------------------------------------------
// USAGE EXAMPLE
//
// Concerns:
// The usage example provided in the component header file must
// compile, link, and run on all platforms as shown.
//
// Plan:
// Run the usage example and exercise the creators and manipulators
// of 'my_List' using a 'bslma::TestAllocator' to verify that memory
// is allocated and deallocated properly.
//
// Testing:
// Usage example
// --------------------------------------------------------------------
if (verbose) printf("\nUSAGE EXAMPLE"
"\n=============\n");
#if !defined(BDE_BUILD_TARGET_EXC)
if (verbose) printf("Test not run without exception support.\n");
#else
bslma::TestAllocator z(veryVeryVeryVerbose);
const bslma::TestAllocator &Z = z;
int counter = 0;
{
bsls::Types::Int64 numBytesUsed = 0;
// Initialize the list with some objects
my_List<my_Class> list(&z);
list.append(my_Class(&counter));
list.append(my_Class(&counter));
list.append(my_Class(&counter));
// Verify that the destructor is called for each of the
// temporaries.
ASSERT(3 == counter);
try {
numBytesUsed = Z.numBytesInUse();
// Make sure the allocation for the 'link' fails.
z.setAllocationLimit(1);
list.append(my_Class(&counter));
ASSERT(0); // should never get here
}
catch (...) {
// Verify that the destructor of 'my_Class' is called for both
// the temporary and the one created within the 'list' object.
ASSERT(5 == counter);
// Verify that the memory allocated for the construction of
// 'my_Class' is properly deallocated.
ASSERT(numBytesUsed == Z.numBytesInUse());
}
}
// Verify that the destructor for the other 3 objects used to
// initialize the list is called.
ASSERT(8 == counter);
// Verify all allocated memory are deallocated.
ASSERT(0 == Z.numBytesInUse());
#endif
} break;
case 5: {
// --------------------------------------------------------------------
// 'reset' TEST
//
// Concerns:
// Verify that when the 'reset' method is called, the proctor
// object properly manages a different object.
//