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
15 // See endian_test for tests of endianess correctness, size, and value.
17 //----------------------------------------------------------------------------//
19 #define BOOST_ENDIAN_LOG
21 #include <boost/integer/endian.hpp>
25 namespace bi
= boost::integer
;
28 # pragma warning( disable : 4244 ) // conversion ..., possible loss of data
29 # pragma warning( disable : 4018 ) // signed/unsigned mismatch
32 template <class T1
, class T2
>
33 struct default_construct
38 o1
= 1; // quiet warnings
42 template <class T1
, class T2
>
49 ++o1
; // quiet gcc unused variable warning
53 template <class T1
, class T2
>
60 ++o1
; // quiet gcc unused variable warning
64 template <class T1
, class T2
>
76 template <class T1
, class T2
>
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
>
109 template <class T1
, class T2
>
124 template <template<class, class> class Test
, class T1
>
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();
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();
195 template <template<class, class> class 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
>();
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
>();
269 bi::endian_log
= false;
271 // make sure some simple things work
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);
289 std::clog
<< "\nresult = +big\n";
292 std::clog
<< "\nresult = -big\n";
295 std::clog
<< "\n++big\n";
298 std::clog
<< "\nresult = big++\n";
301 std::clog
<< "\n--big\n";
304 std::clog
<< "\nbig--\n";
307 std::clog
<< "\nresult = big * big\n";
310 std::clog
<< "\nresult = big * big\n";
313 std::clog
<< "\nresult = big * ulittle\n";
314 result
= big
* ulittle
;
316 std::clog
<< "\nbig *= ulittle\n";
319 std::clog
<< "\nresult = ulittle * big\n";
320 result
= ulittle
* big
;
322 std::clog
<< "\nresult = big * 5\n";
325 std::clog
<< "\nbig *= 5\n";
328 std::clog
<< "\nresult = 5 * big\n";
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";
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
>();
349 op_test
<relational
>();