text
stringlengths 0
2.2M
|
---|
//: 4 Supplying a default-constructed allocator address has the same
|
//: effect as not supplying an allocator.
|
//:
|
//: 5 Supplying an allocator to the default constructor has no effect
|
//: on subsequent object values.
|
//:
|
//: 6 Any memory allocation is from the object allocator, which is
|
//: returned by the 'get_allocator' accessor method.
|
//:
|
//: 7 Every object releases any allocated memory at destruction.
|
//:
|
//: 8 'configureRootPath' is able to set the root path to any string
|
//: value.
|
//
|
// Plan:
|
//: 1 Default construct four objects, in turn, with different allocator
|
//: configurations:
|
//: 1 without passing an allocator,
|
//: 2 passing a default-constructed allocator explicitly,
|
//: 3 passing the address of a test allocator distinct from the
|
//: default, and
|
//: 4 passing in an allocator constructed from the address of a test
|
//: allocator distinct from the default.
|
//:
|
//: 2 Use the primary manipulators with boundary values and verify the
|
//: object's value.
|
//:
|
//: 3 Verify the correct memory allocator is used.
|
//
|
// Testing:
|
// baltzo::DataFileLoader();
|
// baltzo::DataFileLoader(const allocator_type& a);
|
// ~baltzo::DataFileLoader();
|
// void configureRootPath(const char *path);
|
// allocator_type get_allocator() const;
|
// --------------------------------------------------------------------
|
if (verbose) cout << endl
|
<< "DEFAULT CTOR & PRIMARY MANIPULATORS" << endl
|
<< "===================================" << endl;
|
const char *D1 = INVALID_PATH; // rootPath
|
const char *A1 = "";
|
const char *B1 = "a_" SUFFICIENTLY_LONG_STRING;
|
if (verbose) cout << "\nTesting with various allocator configurations."
|
<< endl;
|
for (char cfg = 'a'; cfg <= 'd'; ++cfg) {
|
bsls::AssertTestHandlerGuard hG;
|
const char CONFIG = cfg; // (how we specify the allocator)
|
bslma::TestAllocator fa("footprint", veryVeryVeryVerbose);
|
bslma::TestAllocator da("default", veryVeryVeryVerbose);
|
bslma::TestAllocator sa("supplied", veryVeryVeryVerbose);
|
bslma::DefaultAllocatorGuard dag(&da);
|
Obj *objPtr = 0;
|
bslma::TestAllocator *objAllocatorPtr = 0;
|
switch (CONFIG) {
|
case 'a': {
|
objPtr = new (fa) Obj();
|
objAllocatorPtr = &da;
|
} break;
|
case 'b': {
|
objPtr = new (fa) Obj(Obj::allocator_type());
|
objAllocatorPtr = &da;
|
} break;
|
case 'c': {
|
objPtr = new (fa) Obj(&sa);
|
objAllocatorPtr = &sa;
|
} break;
|
case 'd': {
|
objPtr = new (fa) Obj(Obj::allocator_type(&sa));
|
objAllocatorPtr = &sa;
|
} break;
|
default: {
|
LOOP_ASSERT(CONFIG, !"Bad allocator Config.");
|
} break;
|
}
|
Obj& mX = *objPtr; const Obj& X = mX;
|
bslma::TestAllocator& oa = *objAllocatorPtr;
|
bslma::TestAllocator& noa = &da == &oa ? sa : da;
|
// -------------------------------------
|
// Verify the object's attribute values.
|
// -------------------------------------
|
ASSERT_FAIL(X.rootPath());
|
ASSERT_FAIL(X.isRootPathPlausible());
|
LOOP3_ASSERT(CONFIG, &oa, ALLOC_OF(X), &oa == X.get_allocator());
|
// Verify that no memory is allocate by from the non-object
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.