supernova: c++11 compile fixes
[supercollider.git] / external_libraries / boost_endian / libs / integer / test / endian_operations_test.cpp
blob2fd43291ff32dadeca1d99e54d0a4ab180c914cb
1 // endian_operations_test.cpp ----------------------------------------------//
3 // Copyright Beman Dawes 2008
5 // Distributed under the Boost Software License, Version 1.0. (See accompanying
6 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 // See library home page at http://www.boost.org/libs/endian
10 //----------------------------------------------------------------------------//
12 // This test probes operator overloading, including interaction between
13 // operand types.
15 // See endian_test for tests of endianess correctness, size, and value.
17 //----------------------------------------------------------------------------//
19 #define BOOST_ENDIAN_LOG
21 #include <boost/integer/endian.hpp>
22 #include <cassert>
23 #include <iostream>
25 namespace bi = boost::integer;
27 #ifdef _MSC_VER
28 # pragma warning( disable : 4244 ) // conversion ..., possible loss of data
29 # pragma warning( disable : 4018 ) // signed/unsigned mismatch
30 #endif
32 template <class T1, class T2>
33 struct default_construct
35 static void test()
37 T1 o1;
38 o1 = 1; // quiet warnings
42 template <class T1, class T2>
43 struct construct
45 static void test()
47 T2 o2(1);
48 T1 o1(o2);
49 ++o1; // quiet gcc unused variable warning
53 template <class T1, class T2>
54 struct initialize
56 static void test()
58 T1 o2(2);
59 T1 o1 = o2;
60 ++o1; // quiet gcc unused variable warning
64 template <class T1, class T2>
65 struct assign
67 static void test()
69 T2 o2;
70 o2 = 1;
71 T1 o1;
72 o1 = o2;
76 template <class T1, class T2>
77 struct relational
79 static void test()
81 T1 o1(1);
82 T2 o2(2);
83 if ( o1 == o2 ) return;
84 if ( o1 != o2 ) return;
85 if ( o1 < o2 ) return;
86 if ( o1 <= o2 ) return;
87 if ( o1 > o2 ) return;
88 if ( o1 >= o2 ) return;
92 template <class T1, class T2>
93 struct op_plus
95 static void test()
97 T1 o1(1);
98 T2 o2(2);
99 T1 o3;
101 o3 = +o1;
103 o3 = o1 + o2;
105 o1 += o2;
109 template <class T1, class T2>
110 struct op_star
112 static void test()
114 T1 o1(1);
115 T2 o2(2);
116 T1 o3;
118 o3 = o1 * o2;
120 o1 *= o2;
124 template <template<class, class> class Test, class T1>
125 void op_test_aux()
127 #ifdef BOOST_SHORT_ENDIAN_TEST
128 Test<T1, int>::test();
129 Test<T1, unsigned int>::test();
130 Test<T1, bi::big16_t>::test();
131 Test<T1, bi::ubig64_t>::test();
132 #else
133 Test<T1, char>::test();
134 Test<T1, unsigned char>::test();
135 Test<T1, signed char>::test();
136 Test<T1, short>::test();
137 Test<T1, unsigned short>::test();
138 Test<T1, int>::test();
139 Test<T1, unsigned int>::test();
140 Test<T1, long>::test();
141 Test<T1, unsigned long>::test();
142 Test<T1, long long>::test();
143 Test<T1, unsigned long long>::test();
144 Test<T1, bi::big8_t>::test();
145 Test<T1, bi::big16_t>::test();
146 Test<T1, bi::big24_t>::test();
147 Test<T1, bi::big32_t>::test();
148 Test<T1, bi::big40_t>::test();
149 Test<T1, bi::big48_t>::test();
150 Test<T1, bi::big56_t>::test();
151 Test<T1, bi::big64_t>::test();
152 Test<T1, bi::ubig8_t>::test();
153 Test<T1, bi::ubig16_t>::test();
154 Test<T1, bi::ubig24_t>::test();
155 Test<T1, bi::ubig32_t>::test();
156 Test<T1, bi::ubig40_t>::test();
157 Test<T1, bi::ubig48_t>::test();
158 Test<T1, bi::ubig56_t>::test();
159 Test<T1, bi::ubig64_t>::test();
160 Test<T1, bi::little8_t>::test();
161 Test<T1, bi::little16_t>::test();
162 Test<T1, bi::little24_t>::test();
163 Test<T1, bi::little32_t>::test();
164 Test<T1, bi::little40_t>::test();
165 Test<T1, bi::little48_t>::test();
166 Test<T1, bi::little56_t>::test();
167 Test<T1, bi::little64_t>::test();
168 Test<T1, bi::ulittle8_t>::test();
169 Test<T1, bi::ulittle16_t>::test();
170 Test<T1, bi::ulittle24_t>::test();
171 Test<T1, bi::ulittle32_t>::test();
172 Test<T1, bi::ulittle40_t>::test();
173 Test<T1, bi::ulittle48_t>::test();
174 Test<T1, bi::ulittle56_t>::test();
175 Test<T1, bi::ulittle64_t>::test();
176 Test<T1, bi::native8_t>::test();
177 Test<T1, bi::native16_t>::test();
178 Test<T1, bi::native24_t>::test();
179 Test<T1, bi::native32_t>::test();
180 Test<T1, bi::native40_t>::test();
181 Test<T1, bi::native48_t>::test();
182 Test<T1, bi::native56_t>::test();
183 Test<T1, bi::native64_t>::test();
184 Test<T1, bi::unative8_t>::test();
185 Test<T1, bi::unative16_t>::test();
186 Test<T1, bi::unative24_t>::test();
187 Test<T1, bi::unative32_t>::test();
188 Test<T1, bi::unative40_t>::test();
189 Test<T1, bi::unative48_t>::test();
190 Test<T1, bi::unative56_t>::test();
191 Test<T1, bi::unative64_t>::test();
192 #endif
195 template <template<class, class> class Test>
196 void op_test()
198 #ifdef BOOST_SHORT_ENDIAN_TEST
199 op_test_aux<Test, unsigned short>();
200 op_test_aux<Test, int>();
201 op_test_aux<Test, bi::big32_t>();
202 op_test_aux<Test, bi::ubig32_t>();
203 op_test_aux<Test, bi::little48_t>();
204 #else
205 op_test_aux<Test, char>();
206 op_test_aux<Test, unsigned char>();
207 op_test_aux<Test, signed char>();
208 op_test_aux<Test, short>();
209 op_test_aux<Test, unsigned short>();
210 op_test_aux<Test, int>();
211 op_test_aux<Test, unsigned int>();
212 op_test_aux<Test, long>();
213 op_test_aux<Test, unsigned long>();
214 op_test_aux<Test, long long>();
215 op_test_aux<Test, unsigned long long>();
216 op_test_aux<Test, bi::big8_t>();
217 op_test_aux<Test, bi::big16_t>();
218 op_test_aux<Test, bi::big24_t>();
219 op_test_aux<Test, bi::big32_t>();
220 op_test_aux<Test, bi::big40_t>();
221 op_test_aux<Test, bi::big48_t>();
222 op_test_aux<Test, bi::big56_t>();
223 op_test_aux<Test, bi::big64_t>();
224 op_test_aux<Test, bi::ubig8_t>();
225 op_test_aux<Test, bi::ubig16_t>();
226 op_test_aux<Test, bi::ubig24_t>();
227 op_test_aux<Test, bi::ubig32_t>();
228 op_test_aux<Test, bi::ubig40_t>();
229 op_test_aux<Test, bi::ubig48_t>();
230 op_test_aux<Test, bi::ubig56_t>();
231 op_test_aux<Test, bi::ubig64_t>();
232 op_test_aux<Test, bi::little8_t>();
233 op_test_aux<Test, bi::little16_t>();
234 op_test_aux<Test, bi::little24_t>();
235 op_test_aux<Test, bi::little32_t>();
236 op_test_aux<Test, bi::little40_t>();
237 op_test_aux<Test, bi::little48_t>();
238 op_test_aux<Test, bi::little56_t>();
239 op_test_aux<Test, bi::little64_t>();
240 op_test_aux<Test, bi::ulittle8_t>();
241 op_test_aux<Test, bi::ulittle16_t>();
242 op_test_aux<Test, bi::ulittle24_t>();
243 op_test_aux<Test, bi::ulittle32_t>();
244 op_test_aux<Test, bi::ulittle40_t>();
245 op_test_aux<Test, bi::ulittle48_t>();
246 op_test_aux<Test, bi::ulittle56_t>();
247 op_test_aux<Test, bi::ulittle64_t>();
248 op_test_aux<Test, bi::native8_t>();
249 op_test_aux<Test, bi::native16_t>();
250 op_test_aux<Test, bi::native24_t>();
251 op_test_aux<Test, bi::native32_t>();
252 op_test_aux<Test, bi::native40_t>();
253 op_test_aux<Test, bi::native48_t>();
254 op_test_aux<Test, bi::native56_t>();
255 op_test_aux<Test, bi::native64_t>();
256 op_test_aux<Test, bi::unative8_t>();
257 op_test_aux<Test, bi::unative16_t>();
258 op_test_aux<Test, bi::unative24_t>();
259 op_test_aux<Test, bi::unative32_t>();
260 op_test_aux<Test, bi::unative40_t>();
261 op_test_aux<Test, bi::unative48_t>();
262 op_test_aux<Test, bi::unative56_t>();
263 op_test_aux<Test, bi::unative64_t>();
264 #endif
267 int main()
269 bi::endian_log = false;
271 // make sure some simple things work
273 bi::big32_t o1(1);
274 bi::big32_t o2(2L);
275 bi::big32_t o3(3LL);
276 bi::big64_t o4(1);
278 // use cases; if BOOST_ENDIAN_LOG is defined, will output to clog info on
279 // what overloads and conversions are actually being performed.
281 bi::endian_log = true;
283 std::clog << "set up test values\n";
284 bi::big32_t big(12345);
285 bi::ulittle16_t ulittle(10);
286 bi::big64_t result;
289 std::clog << "\nresult = +big\n";
290 result = +big;
292 std::clog << "\nresult = -big\n";
293 result = -big;
295 std::clog << "\n++big\n";
296 ++big;
298 std::clog << "\nresult = big++\n";
299 result = big++;
301 std::clog << "\n--big\n";
302 --big;
304 std::clog << "\nbig--\n";
305 big--;
307 std::clog << "\nresult = big * big\n";
308 result = big * big;
310 std::clog << "\nresult = big * big\n";
311 result = big * big;
313 std::clog << "\nresult = big * ulittle\n";
314 result = big * ulittle;
316 std::clog << "\nbig *= ulittle\n";
317 big *= ulittle;
319 std::clog << "\nresult = ulittle * big\n";
320 result = ulittle * big;
322 std::clog << "\nresult = big * 5\n";
323 result = big * 5;
325 std::clog << "\nbig *= 5\n";
326 big *= 5;
328 std::clog << "\nresult = 5 * big\n";
329 result = 5 * big;
331 std::clog << "\nresult = ulittle * 5\n";
332 result = ulittle * 5;
334 std::clog << "\nresult = 5 * ulittle\n";
335 result = 5 * ulittle;
337 std::clog << "\nresult = 5 * 10\n";
338 result = 5 * 10;
339 std::clog << "\n";
341 bi::endian_log = false;
343 // perform the indicated test on ~60*60 operand types
345 op_test<default_construct>();
346 op_test<construct>(); // includes copy construction
347 op_test<initialize>();
348 op_test<assign>();
349 op_test<relational>();
350 op_test<op_plus>();
351 op_test<op_star>();
353 return 0;