text
stringlengths
0
2.2M
// Must use 'TA' so that behavior is the same in C++98 mode (copy,
// uses default allocator) and C++11 mode (move, copies '*srcPtr'
// allocator).
TEST_OP(3, destructiveMove(objPtr, TA, srcPtr), 3, TA);
ASSERT(k_DESTROYED == rawBuf.d_value);
ASSERT(0 == rawBuf.d_allocator_p);
}
if (verbose) printf("Exception testing.\n");
if (verbose) printf("\t...pair with allocators\n");
BSLMA_TESTALLOCATOR_EXCEPTION_TEST_BEGIN(testAllocator) {
my_ClassDef rawBuf[4];
my_PairAA_4_4 *srcPtr = rawBuf[0].as<my_PairAA_4_4>();
Util::construct(srcPtr, TA, PAAV4V4);
bslma::AutoDestructor<my_PairAA_4_4> guard(srcPtr, 1);
my_PairAA_4_4 *objPtr = rawBuf[2].as<my_PairAA_4_4>();
Util::destructiveMove(objPtr, TA, srcPtr);
guard.release();
ASSERT(k_DESTROYED == rawBuf[0].d_value);
ASSERT(0 == rawBuf[0].d_allocator_p);
ASSERT(k_DESTROYED == rawBuf[1].d_value);
ASSERT(0 == rawBuf[1].d_allocator_p);
ASSERT(4 == rawBuf[2].d_value);
ASSERT(TA == rawBuf[2].d_allocator_p);
ASSERT(4 == rawBuf[3].d_value);
ASSERT(TA == rawBuf[3].d_allocator_p);
objPtr->~my_PairAA_4_4();
} BSLMA_TESTALLOCATOR_EXCEPTION_TEST_END
if (verbose) printf("Trait selection testing.\n");
{
my_ClassDef rawBuf[2];
const int DI = my_ClassFussy::s_destructorInvocations;
my_ClassFussy *srcPtr = rawBuf[0].as<my_ClassFussy>();
Util::construct(srcPtr, XA, VF);
my_ClassFussy *objPtr = rawBuf[1].as<my_ClassFussy>();
Util::destructiveMove(objPtr, XA, srcPtr);
ASSERT(DI == my_ClassFussy::s_destructorInvocations);
ASSERT(5 == rawBuf[0].d_value);
ASSERT(0 == rawBuf[0].d_allocator_p);
ASSERT(5 == rawBuf[1].d_value);
ASSERT(0 == rawBuf[1].d_allocator_p);
if (veryVerbose) {
P_(rawBuf[0].d_value); PP(rawBuf[0].d_allocator_p);
P_(rawBuf[1].d_value); PP(rawBuf[1].d_allocator_p);
}
objPtr->~my_ClassFussy();
}
{
my_ClassDef rawBuf[2];
const int DI = my_ClassFussy2::s_destructorInvocations;
my_ClassFussy2 *srcPtr = rawBuf[0].as<my_ClassFussy2>();
Util::construct(srcPtr, XA, VF2);
const int CCI = my_ClassFussy2::s_copyConstructorInvocations;
my_ClassFussy2 *objPtr = rawBuf[1].as<my_ClassFussy2>();
Util::destructiveMove(objPtr, XA, srcPtr);
ASSERT(DI == my_ClassFussy2::s_destructorInvocations);
ASSERT(CCI == my_ClassFussy2::s_copyConstructorInvocations);
ASSERT(6 == rawBuf[0].d_value);
ASSERT(0 == rawBuf[0].d_allocator_p);
ASSERT(6 == rawBuf[1].d_value);
ASSERT(0 == rawBuf[1].d_allocator_p);
if (veryVerbose) {
P_(rawBuf[0].d_value); PP(rawBuf[0].d_allocator_p);
P_(rawBuf[1].d_value); PP(rawBuf[1].d_allocator_p);
}
objPtr->~my_ClassFussy2();
}
} break;
case 6: {
// --------------------------------------------------------------------
// TESTING 'construct'
//
// Concerns:
//: 1 That arguments are forwarded in the proper order and
//: number (typos could easily make a10 become the 11th argument to
//: the constructor).
//:
//: 2 That allocators are forwarded appropriately according to the
//: traits and to the type ('bslma::Allocator *' or 'void *').
//
// Plan:
//: 1 Construct an object in some uninitialized buffer, and verify
//: that the value and allocator is as expected. In order to
//: ascertain the proper forwarding of the arguments, use different
//: types and values.
//
// Testing:
// construct(T *dst, A[1--N]..., *a)
// --------------------------------------------------------------------
if (verbose) printf("\nTESTING 'construct'"
"\n===================\n");
bslma::Allocator *const DA = bslma::Default::allocator();
bslma::TestAllocator testAllocator(veryVeryVeryVerbose);
bslma::TestAllocator *const TA = &testAllocator;