]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/align/test/aligned_allocator_test.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / align / test / aligned_allocator_test.cpp
CommitLineData
7c673cae 1/*
b32b8144
FG
2Copyright 2014 Glen Joseph Fernandes
3(glenjofe@gmail.com)
7c673cae 4
b32b8144
FG
5Distributed 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
13template<std::size_t Alignment>
14void 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
31template<std::size_t Alignment>
32void 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
42template<std::size_t Alignment>
43void 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
50template<std::size_t Alignment>
51void 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
59template<std::size_t Alignment>
60void test()
61{
62 test_allocate<Alignment>();
63 test_construct<Alignment>();
64 test_constructor<Alignment>();
65 test_rebind<Alignment>();
66}
67
68int 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}