]> git.saurik.com Git - wxWidgets.git/blob - tests/misc/metatest.cpp
Convert wxFSW_EVENT_{WARNING,ERROR} to string correctly.
[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 // 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"
17 #include "wx/utils.h"
18 #include "wx/meta/pod.h"
19 #include "wx/meta/movable.h"
20
21 #ifndef wxNO_RTTI
22 #include <typeinfo>
23 #endif
24
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 );
38 CPPUNIT_TEST( ImplicitConversion );
39 CPPUNIT_TEST( MinMax );
40 CPPUNIT_TEST_SUITE_END();
41
42 void IsPod();
43 void IsMovable();
44 void ImplicitConversion();
45 void MinMax();
46
47 DECLARE_NO_COPY_CLASS(MetaProgrammingTestCase)
48 };
49
50 // register in the unnamed registry so that these tests are run by default
51 CPPUNIT_TEST_SUITE_REGISTRATION( MetaProgrammingTestCase );
52
53 // also include in its own registry so that these tests can be run alone
54 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( MetaProgrammingTestCase,
55 "MetaProgrammingTestCase" );
56
57
58 void MetaProgrammingTestCase::IsPod()
59 {
60 CPPUNIT_ASSERT(wxIsPod<bool>::value);
61 CPPUNIT_ASSERT(wxIsPod<signed int>::value);
62 CPPUNIT_ASSERT(wxIsPod<double>::value);
63 #if !defined(__VISUALC__) || wxCHECK_VISUALC_VERSION(7)
64 CPPUNIT_ASSERT(wxIsPod<wxObject*>::value);
65 #endif
66 CPPUNIT_ASSERT(!wxIsPod<wxObject>::value);
67 }
68
69 void MetaProgrammingTestCase::IsMovable()
70 {
71 CPPUNIT_ASSERT(wxIsMovable<bool>::value);
72 CPPUNIT_ASSERT(wxIsMovable<signed int>::value);
73 CPPUNIT_ASSERT(wxIsMovable<double>::value);
74 #if !defined(__VISUALC__) || wxCHECK_VISUALC_VERSION(7)
75 CPPUNIT_ASSERT(wxIsMovable<wxObject*>::value);
76 #endif
77 CPPUNIT_ASSERT(!wxIsMovable<wxObject>::value);
78 }
79
80 void MetaProgrammingTestCase::ImplicitConversion()
81 {
82 #ifndef wxNO_RTTI
83 CPPUNIT_ASSERT(typeid(wxImplicitConversionType<char,int>::value) == typeid(int));
84 CPPUNIT_ASSERT(typeid(wxImplicitConversionType<int,unsigned>::value) == typeid(unsigned));
85 #ifdef wxLongLong_t
86 CPPUNIT_ASSERT(typeid(wxImplicitConversionType<wxLongLong_t,float>::value) == typeid(float));
87 #endif
88 #endif // !wxNO_RTTI
89 }
90
91 void MetaProgrammingTestCase::MinMax()
92 {
93 // test that wxMax(1.1,1) returns float, not long int
94 float f = wxMax(1.1f, 1l);
95 CPPUNIT_ASSERT_EQUAL( 1.1f, f);
96
97 // test that comparing signed and unsigned correctly returns unsigned: this
98 // may seem counterintuitive in this case but this is consistent with the
99 // standard C conversions
100 CPPUNIT_ASSERT_EQUAL( 1, wxMin(-1, 1u) );
101
102 CPPUNIT_ASSERT_EQUAL( -1., wxClip(-1.5, -1, 1) );
103 CPPUNIT_ASSERT_EQUAL( 0, wxClip(0, -1, 1) );
104 CPPUNIT_ASSERT_EQUAL( 1, wxClip(2l, -1, 1) );
105 }