]>
git.saurik.com Git - wxWidgets.git/blob - 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 ///////////////////////////////////////////////////////////////////////////////
15 #include "wx/object.h"
17 #include "wx/meta/pod.h"
18 #include "wx/meta/movable.h"
24 // ----------------------------------------------------------------------------
26 // ----------------------------------------------------------------------------
28 class MetaProgrammingTestCase
: public CppUnit::TestCase
31 MetaProgrammingTestCase() { }
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();
43 void ImplicitConversion();
46 DECLARE_NO_COPY_CLASS(MetaProgrammingTestCase
)
49 // register in the unnamed registry so that these tests are run by default
50 CPPUNIT_TEST_SUITE_REGISTRATION( MetaProgrammingTestCase
);
52 // also include in its own registry so that these tests can be run alone
53 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( MetaProgrammingTestCase
,
54 "MetaProgrammingTestCase" );
57 void MetaProgrammingTestCase::IsPod()
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
);
65 CPPUNIT_ASSERT(!wxIsPod
<wxObject
>::value
);
68 void MetaProgrammingTestCase::IsMovable()
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
);
76 CPPUNIT_ASSERT(!wxIsMovable
<wxObject
>::value
);
79 void MetaProgrammingTestCase::ImplicitConversion()
82 CPPUNIT_ASSERT(typeid(wxImplicitConversionType
<char,int>::value
) == typeid(int));
83 CPPUNIT_ASSERT(typeid(wxImplicitConversionType
<int,unsigned>::value
) == typeid(unsigned));
85 CPPUNIT_ASSERT(typeid(wxImplicitConversionType
<wxLongLong_t
,float>::value
) == typeid(float));
90 void MetaProgrammingTestCase::MinMax()
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
);
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) );
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) );