]> git.saurik.com Git - wxWidgets.git/blob - tests/misc/metatest.cpp
Fix install_name_tool calls in OS X "make install".
[wxWidgets.git] / tests / misc / metatest.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/misc/metatest.cpp
3 // Purpose: Test template meta-programming constructs
4 // Author: Jaakko Salli
5 // Copyright: (c) the wxWidgets team
6 // Licence: wxWindows licence
7 ///////////////////////////////////////////////////////////////////////////////
8
9 #include "testprec.h"
10
11 #ifdef __BORLANDC__
12 # pragma hdrstop
13 #endif
14
15 #include "wx/object.h"
16 #include "wx/utils.h"
17 #include "wx/meta/pod.h"
18 #include "wx/meta/movable.h"
19
20 #ifndef wxNO_RTTI
21 #include <typeinfo>
22 #endif
23
24 // ----------------------------------------------------------------------------
25 // test class
26 // ----------------------------------------------------------------------------
27
28 class MetaProgrammingTestCase : public CppUnit::TestCase
29 {
30 public:
31 MetaProgrammingTestCase() { }
32
33 private:
34 CPPUNIT_TEST_SUITE( MetaProgrammingTestCase );
35 CPPUNIT_TEST( IsPod );
36 CPPUNIT_TEST( IsMovable );
37 CPPUNIT_TEST( ImplicitConversion );
38 CPPUNIT_TEST( MinMax );
39 CPPUNIT_TEST_SUITE_END();
40
41 void IsPod();
42 void IsMovable();
43 void ImplicitConversion();
44 void MinMax();
45
46 DECLARE_NO_COPY_CLASS(MetaProgrammingTestCase)
47 };
48
49 // register in the unnamed registry so that these tests are run by default
50 CPPUNIT_TEST_SUITE_REGISTRATION( MetaProgrammingTestCase );
51
52 // also include in its own registry so that these tests can be run alone
53 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( MetaProgrammingTestCase,
54 "MetaProgrammingTestCase" );
55
56
57 void MetaProgrammingTestCase::IsPod()
58 {
59 CPPUNIT_ASSERT(wxIsPod<bool>::value);
60 CPPUNIT_ASSERT(wxIsPod<signed int>::value);
61 CPPUNIT_ASSERT(wxIsPod<double>::value);
62 #if !defined(__VISUALC__) || wxCHECK_VISUALC_VERSION(7)
63 CPPUNIT_ASSERT(wxIsPod<wxObject*>::value);
64 #endif
65 CPPUNIT_ASSERT(!wxIsPod<wxObject>::value);
66 }
67
68 void MetaProgrammingTestCase::IsMovable()
69 {
70 CPPUNIT_ASSERT(wxIsMovable<bool>::value);
71 CPPUNIT_ASSERT(wxIsMovable<signed int>::value);
72 CPPUNIT_ASSERT(wxIsMovable<double>::value);
73 #if !defined(__VISUALC__) || wxCHECK_VISUALC_VERSION(7)
74 CPPUNIT_ASSERT(wxIsMovable<wxObject*>::value);
75 #endif
76 CPPUNIT_ASSERT(!wxIsMovable<wxObject>::value);
77 }
78
79 void MetaProgrammingTestCase::ImplicitConversion()
80 {
81 #ifndef wxNO_RTTI
82 CPPUNIT_ASSERT(typeid(wxImplicitConversionType<char,int>::value) == typeid(int));
83 CPPUNIT_ASSERT(typeid(wxImplicitConversionType<int,unsigned>::value) == typeid(unsigned));
84 #ifdef wxLongLong_t
85 CPPUNIT_ASSERT(typeid(wxImplicitConversionType<wxLongLong_t,float>::value) == typeid(float));
86 #endif
87 #endif // !wxNO_RTTI
88 }
89
90 void MetaProgrammingTestCase::MinMax()
91 {
92 // test that wxMax(1.1,1) returns float, not long int
93 float f = wxMax(1.1f, 1l);
94 CPPUNIT_ASSERT_EQUAL( 1.1f, f);
95
96 // test that comparing signed and unsigned correctly returns unsigned: this
97 // may seem counterintuitive in this case but this is consistent with the
98 // standard C conversions
99 CPPUNIT_ASSERT_EQUAL( 1, wxMin(-1, 1u) );
100
101 CPPUNIT_ASSERT_EQUAL( -1., wxClip(-1.5, -1, 1) );
102 CPPUNIT_ASSERT_EQUAL( 0, wxClip(0, -1, 1) );
103 CPPUNIT_ASSERT_EQUAL( 1, wxClip(2l, -1, 1) );
104 }