]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | |
2 | // (C) Copyright John Maddock 2000. | |
3 | // Use, modification and distribution are subject to the | |
4 | // Boost 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 | #ifndef TT_TEST_HPP | |
8 | #define TT_TEST_HPP | |
9 | ||
10 | #include <boost/config.hpp> | |
b32b8144 | 11 | #include <boost/detail/workaround.hpp> |
7c673cae FG |
12 | |
13 | #if defined(_WIN32_WCE) && defined(BOOST_MSVC) | |
14 | #pragma warning(disable:4201) | |
15 | #endif | |
16 | ||
17 | #include <boost/noncopyable.hpp> | |
18 | #include <iostream> | |
19 | #include <typeinfo> | |
20 | ||
1e59de90 TL |
21 | #ifdef TEST_CUDA_DEVICE |
22 | #define TEST_VIA_STATIC_ASSERT | |
23 | #endif | |
24 | ||
20effc67 | 25 | #ifdef BOOST_BORLANDC |
7c673cae FG |
26 | // we have to turn off these warnings otherwise we get swamped by the things: |
27 | #pragma option -w-8008 -w-8066 | |
28 | #endif | |
29 | ||
30 | #ifdef _MSC_VER | |
31 | // We have to turn off warnings that occur within the test suite: | |
32 | #pragma warning(disable:4127) | |
33 | #endif | |
34 | #ifdef BOOST_INTEL | |
35 | // remark #1418: external function definition with no prior declaration | |
36 | // remark #981: operands are evaluated in unspecified order | |
37 | #pragma warning(disable:1418 981) | |
38 | #endif | |
39 | ||
40 | #ifdef BOOST_INTEL | |
41 | // turn off warnings from this header: | |
42 | #pragma warning(push) | |
43 | #pragma warning(disable:444) | |
44 | #endif | |
45 | ||
46 | // | |
47 | // basic configuration: | |
48 | // | |
49 | #ifdef TEST_STD | |
50 | ||
51 | #define tt std::tr1 | |
52 | ||
53 | //#define TYPE_TRAITS(x) <type_traits> | |
54 | //#define TYPE_COMPARE(x) <type_compare> | |
55 | //#define TYPE_TRANSFORM(x) <type_transform> | |
56 | ||
57 | #else | |
58 | ||
59 | #define tt boost | |
60 | ||
61 | //#define TYPE_TRAITS(x) BOOST_STRINGIZE(boost/type_traits/x.hpp) | |
62 | //#define TYPE_COMPARE(x) BOOST_STRINGIZE(boost/type_traits/x.hpp) | |
63 | //#define TYPE_TRANSFORM(x) BOOST_STRINGIZE(boost/type_traits/x.hpp) | |
64 | ||
65 | #endif | |
66 | ||
67 | // | |
68 | // replacements for Unit test macros: | |
69 | // | |
70 | int error_count = 0; | |
71 | ||
72 | #define BOOST_CHECK_MESSAGE(pred, message)\ | |
73 | do{\ | |
74 | if(!(pred))\ | |
75 | {\ | |
76 | std::cerr << __FILE__ << ":" << __LINE__ << ": " << message << std::endl;\ | |
77 | ++error_count;\ | |
78 | }\ | |
79 | }while(0) | |
80 | ||
81 | #define BOOST_WARN_MESSAGE(pred, message)\ | |
82 | do{\ | |
83 | if(!(pred))\ | |
84 | {\ | |
85 | std::cerr << __FILE__ << ":" << __LINE__ << ": " << message << std::endl;\ | |
86 | }\ | |
87 | }while(0) | |
88 | ||
89 | #define BOOST_TEST_MESSAGE(message)\ | |
90 | do{ std::cout << __FILE__ << ":" << __LINE__ << ": " << message << std::endl; }while(0) | |
91 | ||
1e59de90 TL |
92 | #ifdef TEST_CUDA_DEVICE |
93 | #define BOOST_CHECK(pred) pred | |
94 | #else | |
7c673cae FG |
95 | #define BOOST_CHECK(pred)\ |
96 | do{ \ | |
97 | if(!(pred)){\ | |
98 | std::cout << __FILE__ << ":" << __LINE__ << ": Error in " << BOOST_STRINGIZE(pred) << std::endl;\ | |
99 | ++error_count;\ | |
100 | } \ | |
101 | }while(0) | |
1e59de90 | 102 | #endif |
7c673cae | 103 | |
1e59de90 TL |
104 | #ifdef TEST_CUDA_DEVICE |
105 | #define TT_TEST_BEGIN(trait_name)\ | |
106 | __global__ void test_proc(){ | |
107 | #define TT_TEST_END } | |
108 | #define BOOST_TT_PROC __device__ | |
109 | #else | |
7c673cae FG |
110 | #define TT_TEST_BEGIN(trait_name)\ |
111 | int main(){ | |
112 | #define TT_TEST_END return error_count; } | |
1e59de90 TL |
113 | #define BOOST_TT_PROC |
114 | #endif | |
7c673cae | 115 | |
b32b8144 FG |
116 | #if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES) && !BOOST_WORKAROUND(BOOST_GCC, < 40704) |
117 | ||
118 | #define TRANSFORM_CHECK_ALIASES(name, from_suffix, to_suffix)\ | |
119 | BOOST_CHECK_TYPE(bool to_suffix, name##_t<bool from_suffix>);\ | |
120 | BOOST_CHECK_TYPE(char to_suffix, name##_t<char from_suffix>);\ | |
121 | BOOST_CHECK_TYPE(wchar_t to_suffix, name##_t<wchar_t from_suffix>);\ | |
122 | BOOST_CHECK_TYPE(signed char to_suffix, name##_t<signed char from_suffix>);\ | |
123 | BOOST_CHECK_TYPE(unsigned char to_suffix, name##_t<unsigned char from_suffix>);\ | |
124 | BOOST_CHECK_TYPE(short to_suffix, name##_t<short from_suffix>);\ | |
125 | BOOST_CHECK_TYPE(unsigned short to_suffix, name##_t<unsigned short from_suffix>);\ | |
126 | BOOST_CHECK_TYPE(int to_suffix, name##_t<int from_suffix>);\ | |
127 | BOOST_CHECK_TYPE(unsigned int to_suffix, name##_t<unsigned int from_suffix>);\ | |
128 | BOOST_CHECK_TYPE(long to_suffix, name##_t<long from_suffix>);\ | |
129 | BOOST_CHECK_TYPE(unsigned long to_suffix, name##_t<unsigned long from_suffix>);\ | |
130 | BOOST_CHECK_TYPE(float to_suffix, name##_t<float from_suffix>);\ | |
131 | BOOST_CHECK_TYPE(long double to_suffix, name##_t<long double from_suffix>);\ | |
132 | BOOST_CHECK_TYPE(double to_suffix, name##_t<double from_suffix>);\ | |
133 | BOOST_CHECK_TYPE(UDT to_suffix, name##_t<UDT from_suffix>);\ | |
134 | BOOST_CHECK_TYPE(enum1 to_suffix, name##_t<enum1 from_suffix>); | |
135 | ||
136 | #else | |
137 | ||
138 | #define TRANSFORM_CHECK_ALIASES(name, from_suffix, to_suffix) /**/ | |
139 | ||
140 | #endif | |
7c673cae FG |
141 | |
142 | #define TRANSFORM_CHECK(name, from_suffix, to_suffix)\ | |
b32b8144 | 143 | TRANSFORM_CHECK_ALIASES(name, from_suffix, to_suffix)\ |
7c673cae FG |
144 | BOOST_CHECK_TYPE(bool to_suffix, name<bool from_suffix>::type);\ |
145 | BOOST_CHECK_TYPE(char to_suffix, name<char from_suffix>::type);\ | |
146 | BOOST_CHECK_TYPE(wchar_t to_suffix, name<wchar_t from_suffix>::type);\ | |
147 | BOOST_CHECK_TYPE(signed char to_suffix, name<signed char from_suffix>::type);\ | |
148 | BOOST_CHECK_TYPE(unsigned char to_suffix, name<unsigned char from_suffix>::type);\ | |
149 | BOOST_CHECK_TYPE(short to_suffix, name<short from_suffix>::type);\ | |
150 | BOOST_CHECK_TYPE(unsigned short to_suffix, name<unsigned short from_suffix>::type);\ | |
151 | BOOST_CHECK_TYPE(int to_suffix, name<int from_suffix>::type);\ | |
152 | BOOST_CHECK_TYPE(unsigned int to_suffix, name<unsigned int from_suffix>::type);\ | |
153 | BOOST_CHECK_TYPE(long to_suffix, name<long from_suffix>::type);\ | |
154 | BOOST_CHECK_TYPE(unsigned long to_suffix, name<unsigned long from_suffix>::type);\ | |
155 | BOOST_CHECK_TYPE(float to_suffix, name<float from_suffix>::type);\ | |
156 | BOOST_CHECK_TYPE(long double to_suffix, name<long double from_suffix>::type);\ | |
157 | BOOST_CHECK_TYPE(double to_suffix, name<double from_suffix>::type);\ | |
158 | BOOST_CHECK_TYPE(UDT to_suffix, name<UDT from_suffix>::type);\ | |
159 | BOOST_CHECK_TYPE(enum1 to_suffix, name<enum1 from_suffix>::type); | |
160 | ||
161 | #define BOOST_DUMMY_MACRO_PARAM /**/ | |
162 | ||
163 | #define BOOST_DECL_TRANSFORM_TEST(name, type, from, to)\ | |
1e59de90 | 164 | BOOST_TT_PROC void name(){ TRANSFORM_CHECK(type, from, to) } |
7c673cae | 165 | #define BOOST_DECL_TRANSFORM_TEST3(name, type, from)\ |
1e59de90 | 166 | BOOST_TT_PROC void name(){ TRANSFORM_CHECK(type, from, BOOST_DUMMY_MACRO_PARAM) } |
7c673cae | 167 | #define BOOST_DECL_TRANSFORM_TEST2(name, type, to)\ |
1e59de90 | 168 | BOOST_TT_PROC void name(){ TRANSFORM_CHECK(type, BOOST_DUMMY_MACRO_PARAM, to) } |
7c673cae | 169 | #define BOOST_DECL_TRANSFORM_TEST0(name, type)\ |
1e59de90 | 170 | BOOST_TT_PROC void name(){ TRANSFORM_CHECK(type, BOOST_DUMMY_MACRO_PARAM, BOOST_DUMMY_MACRO_PARAM) } |
7c673cae FG |
171 | |
172 | ||
173 | ||
174 | // | |
175 | // VC++ emits an awful lot of warnings unless we define these: | |
176 | #ifdef BOOST_MSVC | |
177 | # pragma warning(disable:4800) | |
178 | #endif | |
179 | ||
180 | // | |
181 | // define some test types: | |
182 | // | |
183 | enum enum_UDT{ one, two, three }; | |
184 | struct UDT | |
185 | { | |
186 | UDT(); | |
187 | ~UDT(); | |
188 | UDT(const UDT&); | |
189 | UDT& operator=(const UDT&); | |
190 | int i; | |
191 | ||
192 | void f1(); | |
193 | int f2(); | |
194 | int f3(int); | |
195 | int f4(int, float); | |
11fdf7f2 TL |
196 | #if __cpp_noexcept_function_type |
197 | void f5()noexcept; | |
198 | int f6(int)noexcept(true); | |
199 | double f7()noexcept(false); | |
200 | #endif | |
7c673cae FG |
201 | }; |
202 | ||
203 | typedef void(*f1)(); | |
204 | typedef int(*f2)(int); | |
205 | typedef int(*f3)(int, bool); | |
206 | typedef void (UDT::*mf1)(); | |
207 | typedef int (UDT::*mf2)(); | |
208 | typedef int (UDT::*mf3)(int); | |
209 | typedef int (UDT::*mf4)(int, float); | |
210 | typedef int (UDT::*mp); | |
211 | typedef int (UDT::*cmf)(int) const; | |
11fdf7f2 TL |
212 | #if __cpp_noexcept_function_type |
213 | typedef void (UDT::*mf5)()noexcept; | |
214 | typedef int (UDT::*mf6)(int)noexcept; | |
215 | typedef double (UDT::*mf7)()noexcept; | |
216 | #endif | |
217 | typedef int (UDT::*mf8)(...); | |
7c673cae FG |
218 | |
219 | // cv-qualifiers applied to reference types should have no effect | |
220 | // declare these here for later use with is_reference and remove_reference: | |
221 | # ifdef BOOST_MSVC | |
222 | # pragma warning(push) | |
223 | # pragma warning(disable: 4181) | |
224 | # elif defined(BOOST_INTEL) | |
225 | # pragma warning(push) | |
226 | # pragma warning(disable: 21) | |
92f5a8d4 TL |
227 | # elif defined(BOOST_CLANG) |
228 | # pragma clang diagnostic push | |
229 | # pragma clang diagnostic ignored "-Wignored-qualifiers" | |
7c673cae FG |
230 | # endif |
231 | // | |
232 | // This is intentional: | |
233 | // r_type and cr_type should be the same type | |
234 | // but some compilers wrongly apply cv-qualifiers | |
235 | // to reference types (this may generate a warning | |
236 | // on some compilers): | |
237 | // | |
238 | typedef int& r_type; | |
239 | #ifndef BOOST_INTEL | |
240 | typedef const r_type cr_type; | |
241 | #else | |
242 | // recent Intel compilers generate a hard error on the above: | |
243 | typedef r_type cr_type; | |
244 | #endif | |
245 | # ifdef BOOST_MSVC | |
246 | # pragma warning(pop) | |
247 | # elif defined(BOOST_INTEL) | |
248 | # pragma warning(pop) | |
249 | # pragma warning(disable: 985) // identifier truncated in debug information | |
92f5a8d4 TL |
250 | # elif defined(BOOST_CLANG) |
251 | # pragma clang diagnostic pop | |
7c673cae FG |
252 | # endif |
253 | ||
254 | struct POD_UDT { int x; }; | |
255 | struct empty_UDT | |
256 | { | |
257 | empty_UDT(); | |
258 | empty_UDT(const empty_UDT&); | |
259 | ~empty_UDT(); | |
260 | empty_UDT& operator=(const empty_UDT&); | |
261 | bool operator==(const empty_UDT&)const; | |
262 | }; | |
263 | struct empty_POD_UDT | |
264 | { | |
265 | bool operator==(const empty_POD_UDT&)const | |
266 | { return true; } | |
267 | }; | |
268 | union union_UDT | |
269 | { | |
270 | int x; | |
271 | double y; | |
272 | ~union_UDT(){} | |
273 | }; | |
274 | union POD_union_UDT | |
275 | { | |
276 | int x; | |
277 | double y; | |
278 | }; | |
279 | union empty_union_UDT | |
280 | { | |
281 | ~empty_union_UDT(){} | |
282 | }; | |
283 | union empty_POD_union_UDT{}; | |
284 | ||
285 | struct nothrow_copy_UDT | |
286 | { | |
287 | nothrow_copy_UDT(); | |
288 | nothrow_copy_UDT(const nothrow_copy_UDT&)throw(); | |
289 | ~nothrow_copy_UDT(){} | |
290 | nothrow_copy_UDT& operator=(const nothrow_copy_UDT&); | |
291 | bool operator==(const nothrow_copy_UDT&)const | |
292 | { return true; } | |
293 | }; | |
294 | ||
295 | struct nothrow_assign_UDT | |
296 | { | |
297 | nothrow_assign_UDT(); | |
298 | nothrow_assign_UDT(const nothrow_assign_UDT&); | |
299 | ~nothrow_assign_UDT(){}; | |
300 | nothrow_assign_UDT& operator=(const nothrow_assign_UDT&)throw(){ return *this; } | |
301 | bool operator==(const nothrow_assign_UDT&)const | |
302 | { return true; } | |
303 | }; | |
304 | ||
305 | #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES | |
306 | struct nothrow_move_UDT | |
307 | { | |
308 | nothrow_move_UDT(); | |
309 | nothrow_move_UDT(nothrow_move_UDT&&) throw(); | |
310 | nothrow_move_UDT& operator=(nothrow_move_UDT&&) throw(); | |
311 | bool operator==(const nothrow_move_UDT&)const | |
312 | { return true; } | |
313 | }; | |
314 | #endif | |
315 | ||
316 | ||
317 | struct nothrow_construct_UDT | |
318 | { | |
319 | nothrow_construct_UDT()throw(); | |
320 | nothrow_construct_UDT(const nothrow_construct_UDT&); | |
321 | ~nothrow_construct_UDT(){}; | |
322 | nothrow_construct_UDT& operator=(const nothrow_construct_UDT&){ return *this; } | |
323 | bool operator==(const nothrow_construct_UDT&)const | |
324 | { return true; } | |
325 | }; | |
326 | ||
327 | class Base { }; | |
328 | ||
329 | class Derived : public Base { }; | |
330 | class Derived2 : public Base { }; | |
331 | class MultiBase : public Derived, public Derived2 {}; | |
332 | class PrivateBase : private Base {}; | |
333 | ||
334 | class NonDerived { }; | |
335 | ||
336 | enum enum1 | |
337 | { | |
338 | one_,two_ | |
339 | }; | |
340 | ||
341 | enum enum2 | |
342 | { | |
343 | three_,four_ | |
344 | }; | |
345 | ||
92f5a8d4 TL |
346 | #ifndef BOOST_NO_CXX11_SCOPED_ENUMS |
347 | ||
348 | enum class scoped_enum { one, two, three }; | |
349 | ||
350 | #endif | |
351 | ||
7c673cae FG |
352 | struct VB |
353 | { | |
354 | virtual ~VB(){}; | |
355 | }; | |
356 | ||
357 | struct VD : public VB | |
358 | { | |
359 | ~VD(){}; | |
360 | }; | |
361 | // | |
362 | // struct non_pointer: | |
363 | // used to verify that is_pointer does not return | |
364 | // true for class types that implement operator void*() | |
365 | // | |
366 | struct non_pointer | |
367 | { | |
368 | operator void*(){return this;} | |
369 | }; | |
370 | struct non_int_pointer | |
371 | { | |
372 | int i; | |
373 | operator int*(){return &i;} | |
374 | }; | |
375 | struct int_constructible | |
376 | { | |
377 | int_constructible(int); | |
378 | }; | |
379 | struct int_convertible | |
380 | { | |
381 | operator int(); | |
382 | }; | |
383 | // | |
384 | // struct non_empty: | |
385 | // used to verify that is_empty does not emit | |
386 | // spurious warnings or errors. | |
387 | // | |
388 | struct non_empty : private boost::noncopyable | |
389 | { | |
390 | int i; | |
391 | }; | |
392 | // | |
393 | // abstract base classes: | |
394 | struct test_abc1 | |
395 | { | |
396 | test_abc1(); | |
397 | virtual ~test_abc1(); | |
398 | test_abc1(const test_abc1&); | |
399 | test_abc1& operator=(const test_abc1&); | |
400 | virtual void foo() = 0; | |
401 | virtual void foo2() = 0; | |
402 | }; | |
403 | ||
404 | struct test_abc2 | |
405 | { | |
406 | virtual ~test_abc2(); | |
407 | virtual void foo() = 0; | |
408 | virtual void foo2() = 0; | |
409 | }; | |
410 | ||
411 | struct test_abc3 : public test_abc1 | |
412 | { | |
413 | virtual void foo3() = 0; | |
414 | }; | |
415 | ||
416 | struct incomplete_type; | |
417 | ||
418 | struct polymorphic_base | |
419 | { | |
420 | virtual ~polymorphic_base(); | |
421 | virtual void method(); | |
422 | }; | |
423 | ||
424 | struct polymorphic_derived1 : public polymorphic_base | |
425 | { | |
426 | }; | |
427 | ||
428 | struct polymorphic_derived2 : public polymorphic_base | |
429 | { | |
430 | virtual void method(); | |
431 | }; | |
432 | ||
433 | #ifndef BOOST_NO_CXX11_FINAL | |
434 | struct final_UDT final | |
435 | {}; | |
436 | struct polymorphic_derived_final final : public polymorphic_derived2 | |
437 | {}; | |
438 | #endif | |
439 | ||
440 | ||
441 | struct virtual_inherit1 : public virtual Base { }; | |
442 | struct virtual_inherit2 : public virtual_inherit1 { }; | |
443 | struct virtual_inherit3 : private virtual Base {}; | |
444 | struct virtual_inherit4 : public virtual boost::noncopyable {}; | |
445 | struct virtual_inherit5 : public virtual int_convertible {}; | |
446 | struct virtual_inherit6 : public virtual Base { virtual ~virtual_inherit6()throw(); }; | |
447 | ||
448 | typedef void foo0_t(); | |
449 | typedef void foo1_t(int); | |
450 | typedef void foo2_t(int&, double); | |
451 | typedef void foo3_t(int&, bool, int, int); | |
452 | typedef void foo4_t(int, bool, int*, int[], int, int, int, int, int); | |
453 | ||
454 | struct trivial_except_construct | |
455 | { | |
456 | trivial_except_construct(); | |
457 | int i; | |
458 | }; | |
459 | ||
460 | struct trivial_except_destroy | |
461 | { | |
462 | ~trivial_except_destroy(); | |
463 | int i; | |
464 | }; | |
465 | ||
466 | struct trivial_except_copy | |
467 | { | |
468 | trivial_except_copy(trivial_except_copy const&); | |
469 | int i; | |
470 | }; | |
471 | ||
472 | struct trivial_except_assign | |
473 | { | |
474 | trivial_except_assign& operator=(trivial_except_assign const&); | |
475 | int i; | |
476 | }; | |
477 | ||
478 | template <class T> | |
479 | struct wrap | |
480 | { | |
481 | T t; | |
482 | int j; | |
483 | protected: | |
484 | wrap(); | |
485 | wrap(const wrap&); | |
486 | wrap& operator=(const wrap&); | |
487 | }; | |
488 | ||
489 | #ifdef BOOST_INTEL | |
490 | #pragma warning(pop) | |
491 | #endif | |
492 | ||
493 | #endif | |
494 |