]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/container/test/slist_test.cpp
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / boost / libs / container / test / slist_test.cpp
CommitLineData
7c673cae
FG
1//////////////////////////////////////////////////////////////////////////////
2//
3// (C) Copyright Ion Gaztanaga 2004-2013. Distributed under the Boost
4// Software License, Version 1.0. (See accompanying file
5// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6//
7// See http://www.boost.org/libs/container for documentation.
8//
9//////////////////////////////////////////////////////////////////////////////
10#include <boost/container/detail/config_begin.hpp>
11#include <boost/container/slist.hpp>
12#include <boost/container/node_allocator.hpp>
13
14#include <memory>
15#include "dummy_test_allocator.hpp"
16#include "movable_int.hpp"
17#include "list_test.hpp"
18#include "propagate_allocator_test.hpp"
19#include "emplace_test.hpp"
20#include "../../intrusive/test/iterator_test.hpp"
21
22using namespace boost::container;
23
24namespace boost {
25namespace container {
26
27//Explicit instantiation to detect compilation errors
28template class boost::container::slist
29 < test::movable_and_copyable_int
30 , test::simple_allocator<test::movable_and_copyable_int> >;
31
32template class boost::container::slist
33 < test::movable_and_copyable_int
34 , node_allocator<test::movable_and_copyable_int> >;
35
36}}
37
38class recursive_slist
39{
40public:
41 int id_;
42 slist<recursive_slist> slist_;
43 slist<recursive_slist>::iterator it_;
44 slist<recursive_slist>::const_iterator cit_;
45
46 recursive_slist &operator=(const recursive_slist &o)
47 { slist_ = o.slist_; return *this; }
48};
49
50void recursive_slist_test()//Test for recursive types
51{
52 slist<recursive_slist> recursive_list_list;
53}
54
55template<class VoidAllocator>
56struct GetAllocatorCont
57{
58 template<class ValueType>
59 struct apply
60 {
61 typedef slist< ValueType
62 , typename allocator_traits<VoidAllocator>
63 ::template portable_rebind_alloc<ValueType>::type
64 > type;
65 };
66};
67
68template<class VoidAllocator>
69int test_cont_variants()
70{
71 typedef typename GetAllocatorCont<VoidAllocator>::template apply<int>::type MyCont;
72 typedef typename GetAllocatorCont<VoidAllocator>::template apply<test::movable_int>::type MyMoveCont;
73 typedef typename GetAllocatorCont<VoidAllocator>::template apply<test::movable_and_copyable_int>::type MyCopyMoveCont;
74 typedef typename GetAllocatorCont<VoidAllocator>::template apply<test::copyable_int>::type MyCopyCont;
75
76 if(test::list_test<MyCont, false>())
77 return 1;
78 if(test::list_test<MyMoveCont, false>())
79 return 1;
80 if(test::list_test<MyCopyMoveCont, false>())
81 return 1;
82 if(test::list_test<MyCopyMoveCont, false>())
83 return 1;
84 if(test::list_test<MyCopyCont, false>())
85 return 1;
86
87 return 0;
88}
89
90bool test_support_for_initializer_list()
91{
92#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
93 const std::initializer_list<int> il = {5, 10, 15};
94 const slist<int> expected_list(il.begin(), il.end());
95 {
96 slist<int> sl = il;
97 if(sl != expected_list)
98 return false;
99 }
100
101 {
102 slist<int> sl = {1, 2};
103 sl = il;
104 if(sl != expected_list)
105 return false;
106 }
107 {
108 slist<int> sl({ 1, 2 }, slist<int>::allocator_type());
109 sl = il;
110 if (sl != expected_list)
111 return false;
112 }
113 {
114 slist<int> sl = {4, 5};
115 sl.assign(il);
116 if(sl != expected_list)
117 return false;
118 }
119
120 {
121 slist<int> sl = {15};
122 sl.insert(sl.cbegin(), {5, 10});
123 if(sl != expected_list)
124 return false;
125 }
126
127 {
128 slist<int> sl = {5};
129 sl.insert_after(sl.cbegin(), {10, 15});
130 if(sl != expected_list)
131 return false;
132 }
133 return true;
134#endif
135 return true;
136}
137
11fdf7f2
TL
138bool test_for_splice()
139{
140 {
141 slist<int> list1; list1.push_front(3); list1.push_front(2); list1.push_front(1); list1.push_front(0);
142 slist<int> list2;
143 slist<int> expected1; expected1.push_front(3); expected1.push_front(2); expected1.push_front(0);
144 slist<int> expected2; expected2.push_front(1);
145
146 list2.splice(list2.begin(), list1, ++list1.begin());
147
148 if (!(expected1 == list1 && expected2 == list2))
149 return false;
150 }
151 {
152 slist<int> list1; list1.push_front(3); list1.push_front(2); list1.push_front(1); list1.push_front(0);
153 slist<int> list2;
154 slist<int> expected1;
155 slist<int> expected2; expected2.push_front(3); expected2.push_front(2); expected2.push_front(1); expected2.push_front(0);
156
157 list2.splice(list2.begin(), list1, list1.begin(), list1.end());
158
159 if (!(expected1 == list1 && expected2 == list2))
160 return false;
161 }
162 return true;
163}
164
7c673cae
FG
165struct boost_container_slist;
166
167namespace boost {
168namespace container {
169namespace test {
170
171template<>
172struct alloc_propagate_base<boost_container_slist>
173{
174 template <class T, class Allocator>
175 struct apply
176 {
177 typedef boost::container::slist<T, Allocator> type;
178 };
179};
180
181}}}
182
183int main ()
184{
185 recursive_slist_test();
186 {
187 //Now test move semantics
188 slist<recursive_slist> original;
189 slist<recursive_slist> move_ctor(boost::move(original));
190 slist<recursive_slist> move_assign;
191 move_assign = boost::move(move_ctor);
192 move_assign.swap(original);
193 {
194 slist<recursive_slist> recursive, copy;
195 //Test to test both move emulations
196 if(!copy.size()){
197 copy = recursive;
198 }
199 }
200 }
201 ////////////////////////////////////
202 // Testing allocator implementations
203 ////////////////////////////////////
204 // std:allocator
205 if(test_cont_variants< std::allocator<void> >()){
206 std::cerr << "test_cont_variants< std::allocator<void> > failed" << std::endl;
207 return 1;
208 }
209 // boost::container::node_allocator
210 if(test_cont_variants< node_allocator<void> >()){
211 std::cerr << "test_cont_variants< node_allocator<void> > failed" << std::endl;
212 return 1;
213 }
214
215 ////////////////////////////////////
216 // Emplace testing
217 ////////////////////////////////////
218 const test::EmplaceOptions Options = (test::EmplaceOptions)
219 (test::EMPLACE_FRONT | test::EMPLACE_AFTER | test::EMPLACE_BEFORE | test::EMPLACE_AFTER);
220
221 if(!boost::container::test::test_emplace
222 < slist<test::EmplaceInt>, Options>())
223 return 1;
224
225 ////////////////////////////////////
226 // Allocator propagation testing
227 ////////////////////////////////////
228 if(!boost::container::test::test_propagate_allocator<boost_container_slist>())
229 return 1;
230
231 ////////////////////////////////////
232 // Initializer lists
233 ////////////////////////////////////
234 if(!test_support_for_initializer_list())
235 return 1;
236
11fdf7f2
TL
237 ////////////////////////////////////
238 // Splice testing
239 ////////////////////////////////////
240 if(!test_for_splice())
241 return 1;
242
7c673cae
FG
243 ////////////////////////////////////
244 // Iterator testing
245 ////////////////////////////////////
246 {
247 typedef boost::container::slist<int> vector_int;
248 vector_int a; a.push_front(2); a.push_front(1); a.push_front(0);
249 boost::intrusive::test::test_iterator_forward< boost::container::slist<int> >(a);
250 if(boost::report_errors() != 0) {
251 return 1;
252 }
253 }
254}
255
256#include <boost/container/detail/config_end.hpp>
257