text
stringlengths 0
2.2M
|
---|
//=============================================================================
|
// TEST PLAN
|
//-----------------------------------------------------------------------------
|
// Overview
|
// --------
|
// We are testing a proctor object to ensure that it destroys the managed
|
// objects and deallocates memory used if release is not called before the
|
// proctor object goes out of scope. We achieve this goal by creating objects
|
// of a user-defined type that are each initialized with the address of a
|
// unique counter, using a 'bslma::TestAllocator'. As each object is
|
// destroyed, its destructor increments the counter held by the object,
|
// indicating the number of times the object's destructor is called. After
|
// the proctor is destroyed, we verify that the corresponding counters of the
|
// object managed by the proctor are modified, and all allocated memory are
|
// deallocated.
|
//-----------------------------------------------------------------------------
|
// [3] bslma::RawDeleterProctor<TYPE, ALLOCATOR>(obj, allocator);
|
// [3] ~bslma::RawDeleterProctor<TYPE, ALLOCATOR>();
|
// [4] void release();
|
// [5] void reset(obj);
|
//-----------------------------------------------------------------------------
|
// [1] Breathing Test
|
// [2] Helper Class: 'my_Class'
|
// [2] Helper Class: 'my_Pool'
|
// [3] Concern: the (non-virtual) 'deallocate' method for pools is also invoked
|
// [6] Usage Example
|
//=============================================================================
|
// ============================================================================
|
// STANDARD BSL ASSERT TEST FUNCTION
|
// ----------------------------------------------------------------------------
|
namespace {
|
int testStatus = 0;
|
void aSsErT(bool condition, const char *message, int line)
|
{
|
if (condition) {
|
printf("Error " __FILE__ "(%d): %s (failed)\n", line, message);
|
if (0 <= testStatus && testStatus <= 100) {
|
++testStatus;
|
}
|
}
|
}
|
} // close unnamed namespace
|
// ============================================================================
|
// STANDARD BSL TEST DRIVER MACRO ABBREVIATIONS
|
// ----------------------------------------------------------------------------
|
#define ASSERT BSLS_BSLTESTUTIL_ASSERT
|
#define ASSERTV BSLS_BSLTESTUTIL_ASSERTV
|
#define LOOP_ASSERT BSLS_BSLTESTUTIL_LOOP_ASSERT
|
#define LOOP0_ASSERT BSLS_BSLTESTUTIL_LOOP0_ASSERT
|
#define LOOP1_ASSERT BSLS_BSLTESTUTIL_LOOP1_ASSERT
|
#define LOOP2_ASSERT BSLS_BSLTESTUTIL_LOOP2_ASSERT
|
#define LOOP3_ASSERT BSLS_BSLTESTUTIL_LOOP3_ASSERT
|
#define LOOP4_ASSERT BSLS_BSLTESTUTIL_LOOP4_ASSERT
|
#define LOOP5_ASSERT BSLS_BSLTESTUTIL_LOOP5_ASSERT
|
#define LOOP6_ASSERT BSLS_BSLTESTUTIL_LOOP6_ASSERT
|
#define Q BSLS_BSLTESTUTIL_Q // Quote identifier literally.
|
#define P BSLS_BSLTESTUTIL_P // Print identifier and value.
|
#define P_ BSLS_BSLTESTUTIL_P_ // P(X) without '\n'.
|
#define T_ BSLS_BSLTESTUTIL_T_ // Print a tab (w/o newline).
|
#define L_ BSLS_BSLTESTUTIL_L_ // current Line number
|
// ============================================================================
|
// NEGATIVE-TEST MACRO ABBREVIATIONS
|
// ----------------------------------------------------------------------------
|
#define ASSERT_SAFE_PASS(EXPR) BSLS_ASSERTTEST_ASSERT_SAFE_PASS(EXPR)
|
#define ASSERT_SAFE_FAIL(EXPR) BSLS_ASSERTTEST_ASSERT_SAFE_FAIL(EXPR)
|
#define ASSERT_PASS(EXPR) BSLS_ASSERTTEST_ASSERT_PASS(EXPR)
|
#define ASSERT_FAIL(EXPR) BSLS_ASSERTTEST_ASSERT_FAIL(EXPR)
|
#define ASSERT_OPT_PASS(EXPR) BSLS_ASSERTTEST_ASSERT_OPT_PASS(EXPR)
|
#define ASSERT_OPT_FAIL(EXPR) BSLS_ASSERTTEST_ASSERT_OPT_FAIL(EXPR)
|
//=============================================================================
|
// GLOBAL TYPEDEFS/CONSTANTS FOR TESTING
|
//-----------------------------------------------------------------------------
|
//=============================================================================
|
// HELPER CLASS FOR TESTING
|
//-----------------------------------------------------------------------------
|
class my_Pool {
|
// This class provides a 'deallocate' method, used to exercise the
|
// contract promised by the destructor of the 'bslma::RawDeleterGuard'.
|
// This object indicates that its 'deallocate' method is called by
|
// incrementing the global counter (supplied at construction) that it
|
// *holds*.
|
// DATA
|
int *d_counter_p; // counter to be incremented when 'deallocate' is called
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.