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 BOOST_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 #if __cpp_noexcept_function_type
181    void f5()noexcept;
182    int f6(int)noexcept(true);
183    double f7()noexcept(false);
184 #endif
185 };
186 
187 typedef void(*f1)();
188 typedef int(*f2)(int);
189 typedef int(*f3)(int, bool);
190 typedef void (UDT::*mf1)();
191 typedef int (UDT::*mf2)();
192 typedef int (UDT::*mf3)(int);
193 typedef int (UDT::*mf4)(int, float);
194 typedef int (UDT::*mp);
195 typedef int (UDT::*cmf)(int) const;
196 #if __cpp_noexcept_function_type
197 typedef void (UDT::*mf5)()noexcept;
198 typedef int (UDT::*mf6)(int)noexcept;
199 typedef double (UDT::*mf7)()noexcept;
200 #endif
201 typedef int (UDT::*mf8)(...);
202 
203 // cv-qualifiers applied to reference types should have no effect
204 // declare these here for later use with is_reference and remove_reference:
205 # ifdef BOOST_MSVC
206 #  pragma warning(push)
207 #  pragma warning(disable: 4181)
208 # elif defined(BOOST_INTEL)
209 #  pragma warning(push)
210 #  pragma warning(disable: 21)
211 # elif defined(BOOST_CLANG)
212 #  pragma clang diagnostic push
213 #  pragma clang diagnostic ignored "-Wignored-qualifiers"
214 # endif
215 //
216 // This is intentional:
217 // r_type and cr_type should be the same type
218 // but some compilers wrongly apply cv-qualifiers
219 // to reference types (this may generate a warning
220 // on some compilers):
221 //
222 typedef int& r_type;
223 #ifndef BOOST_INTEL
224 typedef const r_type cr_type;
225 #else
226 // recent Intel compilers generate a hard error on the above:
227 typedef r_type cr_type;
228 #endif
229 # ifdef BOOST_MSVC
230 #  pragma warning(pop)
231 # elif defined(BOOST_INTEL)
232 #  pragma warning(pop)
233 #  pragma warning(disable: 985) // identifier truncated in debug information
234 # elif defined(BOOST_CLANG)
235 #  pragma clang diagnostic pop
236 # endif
237 
238 struct POD_UDT { int x; };
239 struct empty_UDT
240 {
241    empty_UDT();
242    empty_UDT(const empty_UDT&);
243    ~empty_UDT();
244    empty_UDT& operator=(const empty_UDT&);
245    bool operator==(const empty_UDT&)const;
246 };
247 struct empty_POD_UDT
248 {
operator ==empty_POD_UDT249    bool operator==(const empty_POD_UDT&)const
250    { return true; }
251 };
252 union union_UDT
253 {
254   int x;
255   double y;
~union_UDT()256   ~union_UDT(){}
257 };
258 union POD_union_UDT
259 {
260   int x;
261   double y;
262 };
263 union empty_union_UDT
264 {
~empty_union_UDT()265    ~empty_union_UDT(){}
266 };
267 union empty_POD_union_UDT{};
268 
269 struct nothrow_copy_UDT
270 {
271    nothrow_copy_UDT();
272    nothrow_copy_UDT(const nothrow_copy_UDT&)throw();
~nothrow_copy_UDTnothrow_copy_UDT273    ~nothrow_copy_UDT(){}
274    nothrow_copy_UDT& operator=(const nothrow_copy_UDT&);
operator ==nothrow_copy_UDT275    bool operator==(const nothrow_copy_UDT&)const
276    { return true; }
277 };
278 
279 struct nothrow_assign_UDT
280 {
281    nothrow_assign_UDT();
282    nothrow_assign_UDT(const nothrow_assign_UDT&);
~nothrow_assign_UDTnothrow_assign_UDT283    ~nothrow_assign_UDT(){};
operator =nothrow_assign_UDT284    nothrow_assign_UDT& operator=(const nothrow_assign_UDT&)throw(){ return *this; }
operator ==nothrow_assign_UDT285    bool operator==(const nothrow_assign_UDT&)const
286    { return true; }
287 };
288 
289 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
290 struct nothrow_move_UDT
291 {
292    nothrow_move_UDT();
293    nothrow_move_UDT(nothrow_move_UDT&&) throw();
294    nothrow_move_UDT& operator=(nothrow_move_UDT&&) throw();
operator ==nothrow_move_UDT295    bool operator==(const nothrow_move_UDT&)const
296    { return true; }
297 };
298 #endif
299 
300 
301 struct nothrow_construct_UDT
302 {
303    nothrow_construct_UDT()throw();
304    nothrow_construct_UDT(const nothrow_construct_UDT&);
~nothrow_construct_UDTnothrow_construct_UDT305    ~nothrow_construct_UDT(){};
operator =nothrow_construct_UDT306    nothrow_construct_UDT& operator=(const nothrow_construct_UDT&){ return *this; }
operator ==nothrow_construct_UDT307    bool operator==(const nothrow_construct_UDT&)const
308    { return true; }
309 };
310 
311 class Base { };
312 
313 class Derived : public Base { };
314 class Derived2 : public Base { };
315 class MultiBase : public Derived, public Derived2 {};
316 class PrivateBase : private Base {};
317 
318 class NonDerived { };
319 
320 enum enum1
321 {
322    one_,two_
323 };
324 
325 enum enum2
326 {
327    three_,four_
328 };
329 
330 #ifndef BOOST_NO_CXX11_SCOPED_ENUMS
331 
332 enum class scoped_enum { one, two, three };
333 
334 #endif
335 
336 struct VB
337 {
~VBVB338    virtual ~VB(){};
339 };
340 
341 struct VD : public VB
342 {
~VDVD343    ~VD(){};
344 };
345 //
346 // struct non_pointer:
347 // used to verify that is_pointer does not return
348 // true for class types that implement operator void*()
349 //
350 struct non_pointer
351 {
operator void*non_pointer352    operator void*(){return this;}
353 };
354 struct non_int_pointer
355 {
356    int i;
operator int*non_int_pointer357    operator int*(){return &i;}
358 };
359 struct int_constructible
360 {
361    int_constructible(int);
362 };
363 struct int_convertible
364 {
365    operator int();
366 };
367 //
368 // struct non_empty:
369 // used to verify that is_empty does not emit
370 // spurious warnings or errors.
371 //
372 struct non_empty : private boost::noncopyable
373 {
374    int i;
375 };
376 //
377 // abstract base classes:
378 struct test_abc1
379 {
380    test_abc1();
381    virtual ~test_abc1();
382    test_abc1(const test_abc1&);
383    test_abc1& operator=(const test_abc1&);
384    virtual void foo() = 0;
385    virtual void foo2() = 0;
386 };
387 
388 struct test_abc2
389 {
390    virtual ~test_abc2();
391    virtual void foo() = 0;
392    virtual void foo2() = 0;
393 };
394 
395 struct test_abc3 : public test_abc1
396 {
397    virtual void foo3() = 0;
398 };
399 
400 struct incomplete_type;
401 
402 struct polymorphic_base
403 {
404    virtual ~polymorphic_base();
405    virtual void method();
406 };
407 
408 struct polymorphic_derived1 : public polymorphic_base
409 {
410 };
411 
412 struct polymorphic_derived2 : public polymorphic_base
413 {
414    virtual void method();
415 };
416 
417 #ifndef BOOST_NO_CXX11_FINAL
418 struct final_UDT final
419 {};
420 struct polymorphic_derived_final final : public polymorphic_derived2
421 {};
422 #endif
423 
424 
425 struct virtual_inherit1 : public virtual Base { };
426 struct virtual_inherit2 : public virtual_inherit1 { };
427 struct virtual_inherit3 : private virtual Base {};
428 struct virtual_inherit4 : public virtual boost::noncopyable {};
429 struct virtual_inherit5 : public virtual int_convertible {};
430 struct virtual_inherit6 : public virtual Base { virtual ~virtual_inherit6()throw(); };
431 
432 typedef void foo0_t();
433 typedef void foo1_t(int);
434 typedef void foo2_t(int&, double);
435 typedef void foo3_t(int&, bool, int, int);
436 typedef void foo4_t(int, bool, int*, int[], int, int, int, int, int);
437 
438 struct trivial_except_construct
439 {
440    trivial_except_construct();
441    int i;
442 };
443 
444 struct trivial_except_destroy
445 {
446    ~trivial_except_destroy();
447    int i;
448 };
449 
450 struct trivial_except_copy
451 {
452    trivial_except_copy(trivial_except_copy const&);
453    int i;
454 };
455 
456 struct trivial_except_assign
457 {
458    trivial_except_assign& operator=(trivial_except_assign const&);
459    int i;
460 };
461 
462 template <class T>
463 struct wrap
464 {
465    T t;
466    int j;
467 protected:
468    wrap();
469    wrap(const wrap&);
470    wrap& operator=(const wrap&);
471 };
472 
473 #ifdef BOOST_INTEL
474 #pragma warning(pop)
475 #endif
476 
477 #endif
478 
479