]>
Commit | Line | Data |
---|---|---|
109e2ca4 JS |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: tests/misc/metatest.cpp | |
3 | // Purpose: Test template meta-programming constructs | |
4 | // Author: Jaakko Salli | |
5 | // RCS-ID: $Id$ | |
6 | // Copyright: (c) the wxWidgets team | |
7 | // Licence: wxWindows licence | |
8 | /////////////////////////////////////////////////////////////////////////////// | |
9 | ||
10 | #include "testprec.h" | |
11 | ||
12 | #ifdef __BORLANDC__ | |
13 | # pragma hdrstop | |
14 | #endif | |
15 | ||
16 | #include "wx/object.h" | |
fd7c5da6 | 17 | #include "wx/utils.h" |
109e2ca4 JS |
18 | #include "wx/meta/pod.h" |
19 | #include "wx/meta/movable.h" | |
20 | ||
fd7c5da6 VS |
21 | #ifndef wxNO_RTTI |
22 | #include <typeinfo> | |
23 | #endif | |
24 | ||
109e2ca4 JS |
25 | // ---------------------------------------------------------------------------- |
26 | // test class | |
27 | // ---------------------------------------------------------------------------- | |
28 | ||
29 | class MetaProgrammingTestCase : public CppUnit::TestCase | |
30 | { | |
31 | public: | |
32 | MetaProgrammingTestCase() { } | |
33 | ||
34 | private: | |
35 | CPPUNIT_TEST_SUITE( MetaProgrammingTestCase ); | |
36 | CPPUNIT_TEST( IsPod ); | |
37 | CPPUNIT_TEST( IsMovable ); | |
fd7c5da6 | 38 | CPPUNIT_TEST( ImplicitConversion ); |
109e2ca4 JS |
39 | CPPUNIT_TEST_SUITE_END(); |
40 | ||
41 | void IsPod(); | |
42 | void IsMovable(); | |
fd7c5da6 | 43 | void ImplicitConversion(); |
109e2ca4 JS |
44 | |
45 | DECLARE_NO_COPY_CLASS(MetaProgrammingTestCase) | |
46 | }; | |
47 | ||
48 | // register in the unnamed registry so that these tests are run by default | |
49 | CPPUNIT_TEST_SUITE_REGISTRATION( MetaProgrammingTestCase ); | |
50 | ||
51 | // also include in it's own registry so that these tests can be run alone | |
52 | CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( MetaProgrammingTestCase, | |
53 | "MetaProgrammingTestCase" ); | |
54 | ||
55 | ||
56 | void MetaProgrammingTestCase::IsPod() | |
57 | { | |
58 | CPPUNIT_ASSERT(wxIsPod<bool>::value); | |
59 | CPPUNIT_ASSERT(wxIsPod<signed int>::value); | |
60 | CPPUNIT_ASSERT(wxIsPod<double>::value); | |
61 | #if !defined(__VISUALC__) || wxCHECK_VISUALC_VERSION(7) | |
62 | CPPUNIT_ASSERT(wxIsPod<wxObject*>::value); | |
63 | #endif | |
64 | CPPUNIT_ASSERT(!wxIsPod<wxObject>::value); | |
65 | } | |
66 | ||
67 | void MetaProgrammingTestCase::IsMovable() | |
68 | { | |
69 | CPPUNIT_ASSERT(wxIsMovable<bool>::value); | |
70 | CPPUNIT_ASSERT(wxIsMovable<signed int>::value); | |
71 | CPPUNIT_ASSERT(wxIsMovable<double>::value); | |
72 | #if !defined(__VISUALC__) || wxCHECK_VISUALC_VERSION(7) | |
73 | CPPUNIT_ASSERT(wxIsMovable<wxObject*>::value); | |
74 | #endif | |
75 | CPPUNIT_ASSERT(!wxIsMovable<wxObject>::value); | |
76 | } | |
fd7c5da6 VS |
77 | |
78 | void MetaProgrammingTestCase::ImplicitConversion() | |
79 | { | |
80 | // wxImplicitConversionType<> is used to implement wxMax(). We test it | |
81 | // indirectly through that here. | |
82 | ||
83 | // test that wxMax(1.1,1) returns float, not long int | |
84 | float f = wxMax(1.1f, 1l); | |
85 | CPPUNIT_ASSERT_EQUAL( 1.1f, f); | |
86 | ||
87 | #ifndef wxNO_RTTI | |
88 | CPPUNIT_ASSERT(typeid(wxImplicitConversionType<char,int>::value) == typeid(int)); | |
89 | CPPUNIT_ASSERT(typeid(wxImplicitConversionType<int,unsigned>::value) == typeid(unsigned)); | |
90 | #ifdef wxLongLong_t | |
91 | CPPUNIT_ASSERT(typeid(wxImplicitConversionType<wxLongLong_t,float>::value) == typeid(float)); | |
92 | #endif | |
93 | #endif // !wxNO_RTTI | |
94 | } |