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