remove \r
[extl.git] / extl / memory / unit_test / new_allocator_test.h
blob16e4e2ebadfb2dd303484758dc0cbe5714741a45
1 /* ///////////////////////////////////////////////////////////////////////
2 * File: new_allocator_test.h
4 * Created: 08.02.20
5 * Updated: 08.04.14
7 * Brief: new_allocator class unit testing
9 * [<Home>]
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
18 #endif
20 /* ///////////////////////////////////////////////////////////////////////
21 * ::unit_test namespace
23 EXTL_TEST_BEGIN_NAMESPACE
25 /* ///////////////////////////////////////////////////////////////////////
26 * Unit-testing
28 #ifdef EXTL_TEMPLATE_CLASS_DEFAULT_ARGUMENT_SUPPORT
29 template < typename_param_k T, typename_param_k A = new_allocator<T> >
30 #else
31 template < typename_param_k T, typename_param_k A >
32 #endif
33 struct new_allocator_test
35 new_allocator_test()
37 new_allocator< void > void_allocator;
39 #ifdef EXTL_ASSERT_DISABLE
40 EXTL_SUPPRESS_UNUSED(void_allocator);
41 #endif
43 A allocator;
44 e_uint_t n=100;
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;
66 CA char_allocator;
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);
71 #endif
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;
78 # else
79 new_allocator_test< e_uint_t, new_allocator< e_uint_t > > g_new_allocator_test;
80 # endif
81 #endif
83 /* ///////////////////////////////////////////////////////////////////////
84 * ::unit_test namespace
86 EXTL_TEST_END_NAMESPACE
88 /* //////////////////////////////////////////////////////////////////// */
89 #endif /* EXTL_MEMORY_NEW_ALLOCATOR_TEST_H */
90 /* //////////////////////////////////////////////////////////////////// */