1 /* ///////////////////////////////////////////////////////////////////////
2 * File: new_allocator_test.h
7 * Brief: new_allocator class unit testing
10 * Copyright (c) 2008-2020, Waruqi All rights reserved.
11 * //////////////////////////////////////////////////////////////////// */
13 #ifndef EXTL_MEMORY_NEW_ALLOCATOR_TEST_H
14 #define EXTL_MEMORY_NEW_ALLOCATOR_TEST_H
16 #ifndef EXTL_MEMORY_NEW_ALLOCATOR_H
17 # error This file must be included of new_allocator.h
20 /* ///////////////////////////////////////////////////////////////////////
21 * ::unit_test namespace
23 EXTL_TEST_BEGIN_NAMESPACE
25 /* ///////////////////////////////////////////////////////////////////////
28 #ifdef EXTL_TEMPLATE_CLASS_DEFAULT_ARGUMENT_SUPPORT
29 template < typename_param_k T
, typename_param_k A
= new_allocator
<T
> >
31 template < typename_param_k T
, typename_param_k A
>
33 struct new_allocator_test
37 new_allocator
< void > void_allocator
;
39 #ifdef EXTL_ASSERT_DISABLE
40 EXTL_SUPPRESS_UNUSED(void_allocator
);
45 T
*p
= allocator
.allocate(n
);
46 EXTL_ASSERT(p
!= NULL
);
48 allocator
.construct(p
, 1987);
49 EXTL_ASSERT(*p
== 1987);
51 T
*pnew
= allocator
.reallocate(p
, 1000, &n
);
52 EXTL_ASSERT(pnew
!= NULL
);
53 EXTL_ASSERT(*pnew
== 1987);
55 allocator
.destroy(pnew
);
56 //EXTL_ASSERT(*pnew != 1987);
58 EXTL_ASSERT((void_allocator
== void_allocator
));
59 EXTL_ASSERT(!(allocator
!= allocator
));
61 allocator
.deallocate(pnew
);
63 /* Rebind allocator */
64 #ifdef EXTL_MEMORY_ALLOCATOR_REBIND_SUPPORT
65 typedef typename_type_k
A::template_qual_k rebind
<e_char_t
>::other_type CA
;
67 e_char_t
*pc
= char_allocator
.allocate(n
);
68 char_allocator
.construct(pc
, 'C');
69 EXTL_ASSERT(*pc
== 'C');
70 char_allocator
.deallocate(pc
);
75 #if !defined(EXTL_COMPILER_IS_BORLAND) && !defined(EXTL_COMPILER_IS_DMC)
76 # ifdef EXTL_TEMPLATE_CLASS_DEFAULT_ARGUMENT_SUPPORT
77 new_allocator_test
< e_uint_t
> g_new_allocator_test
;
79 new_allocator_test
< e_uint_t
, new_allocator
< e_uint_t
> > g_new_allocator_test
;
83 /* ///////////////////////////////////////////////////////////////////////
84 * ::unit_test namespace
86 EXTL_TEST_END_NAMESPACE
88 /* //////////////////////////////////////////////////////////////////// */
89 #endif /* EXTL_MEMORY_NEW_ALLOCATOR_TEST_H */
90 /* //////////////////////////////////////////////////////////////////// */