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