text
stringlengths
0
2.2M
// --------------------------------------------------------------------
// TESTING 'destructiveMove'
//
// Concerns:
//: 1 That the move constructor properly forwards the allocator when
//: appropriate.
//:
//: 2 That the move constructor uses 'memcpy' when appropriate.
//
// Plan:
// The test plan is identical to 'copyConstruct', except that we
// operate the move from a temporary copy created with the (already
// tested) 'copyConstruct' so as not to affect the constants of this
// test driver. We are also careful (for the exception testing) that
// this temporary is not destroyed if it has been moved successfully.
// Finally, we verify that the original object has been destroyed,
// unless it was bitwise-movable.
//
// Testing:
// destructiveMove(T *dst, T *src, *a)
// --------------------------------------------------------------------
if (verbose) printf("\nTESTING 'destructiveMove'"
"\n=========================\n");
bslma::TestAllocator testAllocator(veryVeryVeryVerbose);
bslma::TestAllocator *const TA = &testAllocator;
int dummyAllocator; // not a 'bslma' allocator
int *const XA = &dummyAllocator;
if (verbose) printf("Value and allocator testing.\n");
// my_Class # Operation Val Alloc
// ========== ==================================== === =====
{
my_ClassDef rawBuf;
my_Class1 *srcPtr = rawBuf.as<my_Class1>();
Util::construct(srcPtr, TA, V1);
TEST_OP(1, destructiveMove(objPtr, TA, srcPtr), 1, 0);
ASSERT(k_DESTROYED == rawBuf.d_value);
ASSERT(0 == rawBuf.d_allocator_p);
}
{
my_ClassDef rawBuf;
my_Class2 *srcPtr = rawBuf.as<my_Class2>();
Util::construct(srcPtr, TA, V2);
TEST_OP(2, destructiveMove(objPtr, TA, srcPtr), 2, TA);
ASSERT(k_DESTROYED == rawBuf.d_value);
ASSERT(0 == rawBuf.d_allocator_p);
}
{
my_ClassDef rawBuf;
my_Class2a *srcPtr = rawBuf.as<my_Class2a>();
Util::construct(srcPtr, TA, V2A);
TEST_OP(2a, destructiveMove(objPtr, TA, srcPtr), 0x2a, TA);
ASSERT(k_DESTROYED == rawBuf.d_value);
ASSERT(0 == rawBuf.d_allocator_p);
}
{
my_ClassDef rawBuf;
my_Class3 *srcPtr = rawBuf.as<my_Class3>();
Util::construct(srcPtr, TA, V3);
TEST_OP(3, destructiveMove(objPtr, TA, srcPtr), 3, TA);
ASSERT(k_DESTROYED == rawBuf.d_value);
ASSERT(0 == rawBuf.d_allocator_p);
}
{
my_ClassDef rawBuf;
my_Class1 *srcPtr = rawBuf.as<my_Class1>();
Util::construct(srcPtr, TA, V1);
TEST_OP(1, destructiveMove(objPtr, XA, srcPtr), 1, 0);
ASSERT(k_DESTROYED == rawBuf.d_value);
ASSERT(0 == rawBuf.d_allocator_p);
}
{
my_ClassDef rawBuf;
my_Class2 *srcPtr = rawBuf.as<my_Class2>();
Util::construct(srcPtr, TA, V2);
// 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(2, destructiveMove(objPtr, TA, srcPtr), 2, TA);
ASSERT(k_DESTROYED == rawBuf.d_value);
ASSERT(0 == rawBuf.d_allocator_p);
}
{
my_ClassDef rawBuf;
my_Class2a *srcPtr = rawBuf.as<my_Class2a>();
Util::construct(srcPtr, TA, V2A);
// 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(2a, destructiveMove(objPtr, TA, srcPtr), 0x2a, TA);
ASSERT(k_DESTROYED == rawBuf.d_value);
ASSERT(0 == rawBuf.d_allocator_p);
}
{
my_ClassDef rawBuf;
my_Class3 *srcPtr = rawBuf.as<my_Class3>();
Util::construct(srcPtr, TA, V3);