]>
git.saurik.com Git - wxWidgets.git/blob - tests/misc/metatest.cpp
6d5261a55a1df1b4d54e11d6f59cf5c488901089
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/misc/metatest.cpp
3 // Purpose: Test template meta-programming constructs
4 // Author: Jaakko Salli
6 // Copyright: (c) the wxWidgets team
7 // Licence: wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
16 #include "wx/object.h"
18 #include "wx/meta/pod.h"
19 #include "wx/meta/movable.h"
25 // ----------------------------------------------------------------------------
27 // ----------------------------------------------------------------------------
29 class MetaProgrammingTestCase
: public CppUnit::TestCase
32 MetaProgrammingTestCase() { }
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();
44 void ImplicitConversion();
47 DECLARE_NO_COPY_CLASS(MetaProgrammingTestCase
)
50 // register in the unnamed registry so that these tests are run by default
51 CPPUNIT_TEST_SUITE_REGISTRATION( MetaProgrammingTestCase
);
53 // also include in its own registry so that these tests can be run alone
54 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( MetaProgrammingTestCase
,
55 "MetaProgrammingTestCase" );
58 void MetaProgrammingTestCase::IsPod()
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
);
66 CPPUNIT_ASSERT(!wxIsPod
<wxObject
>::value
);
69 void MetaProgrammingTestCase::IsMovable()
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
);
77 CPPUNIT_ASSERT(!wxIsMovable
<wxObject
>::value
);
80 void MetaProgrammingTestCase::ImplicitConversion()
83 CPPUNIT_ASSERT(typeid(wxImplicitConversionType
<char,int>::value
) == typeid(int));
84 CPPUNIT_ASSERT(typeid(wxImplicitConversionType
<int,unsigned>::value
) == typeid(unsigned));
86 CPPUNIT_ASSERT(typeid(wxImplicitConversionType
<wxLongLong_t
,float>::value
) == typeid(float));
91 void MetaProgrammingTestCase::MinMax()
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
);
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) );
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) );