]>
Commit | Line | Data |
---|---|---|
7c673cae | 1 | /* |
b32b8144 FG |
2 | Copyright 2014 Glen Joseph Fernandes |
3 | (glenjofe@gmail.com) | |
7c673cae | 4 | |
b32b8144 FG |
5 | Distributed under the Boost Software License, Version 1.0. |
6 | (http://www.boost.org/LICENSE_1_0.txt) | |
7c673cae FG |
7 | */ |
8 | #include <boost/align/aligned_allocator.hpp> | |
9 | #include <boost/align/is_aligned.hpp> | |
10 | #include <boost/core/lightweight_test.hpp> | |
11 | #include <cstring> | |
12 | ||
13 | template<std::size_t Alignment> | |
14 | void test_allocate() | |
15 | { | |
16 | { | |
17 | boost::alignment::aligned_allocator<int, Alignment> a; | |
18 | int* p = a.allocate(1); | |
19 | BOOST_TEST(p != 0); | |
20 | BOOST_TEST(boost::alignment::is_aligned(p, Alignment)); | |
21 | std::memset(p, 0, 1); | |
22 | a.deallocate(p, 1); | |
23 | } | |
24 | { | |
25 | boost::alignment::aligned_allocator<int, Alignment> a; | |
26 | int* p = a.allocate(0); | |
27 | a.deallocate(p, 0); | |
28 | } | |
29 | } | |
30 | ||
31 | template<std::size_t Alignment> | |
32 | void test_construct() | |
33 | { | |
34 | boost::alignment::aligned_allocator<int, Alignment> a; | |
35 | int* p = a.allocate(1); | |
36 | a.construct(p, 1); | |
37 | BOOST_TEST(*p == 1); | |
38 | a.destroy(p); | |
39 | a.deallocate(p, 1); | |
40 | } | |
41 | ||
42 | template<std::size_t Alignment> | |
43 | void test_constructor() | |
44 | { | |
45 | boost::alignment::aligned_allocator<char, Alignment> a1; | |
46 | boost::alignment::aligned_allocator<int, Alignment> a2(a1); | |
47 | BOOST_TEST(a2 == a1); | |
48 | } | |
49 | ||
50 | template<std::size_t Alignment> | |
51 | void test_rebind() | |
52 | { | |
53 | boost::alignment::aligned_allocator<char, Alignment> a1; | |
54 | typename boost::alignment::aligned_allocator<char, | |
55 | Alignment>::template rebind<int>::other a2(a1); | |
56 | BOOST_TEST(a2 == a1); | |
57 | } | |
58 | ||
59 | template<std::size_t Alignment> | |
60 | void test() | |
61 | { | |
62 | test_allocate<Alignment>(); | |
63 | test_construct<Alignment>(); | |
64 | test_constructor<Alignment>(); | |
65 | test_rebind<Alignment>(); | |
66 | } | |
67 | ||
68 | int main() | |
69 | { | |
70 | test<1>(); | |
71 | test<2>(); | |
72 | test<4>(); | |
73 | test<8>(); | |
74 | test<16>(); | |
75 | test<32>(); | |
76 | test<64>(); | |
77 | test<128>(); | |
78 | ||
79 | return boost::report_errors(); | |
80 | } |