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