]>
git.saurik.com Git - wxWidgets.git/blob - tests/misc/metatest.cpp
ed1d4c388e927c84649aae44f95093282f9e0ebe
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_SUITE_END();
43 void ImplicitConversion();
45 DECLARE_NO_COPY_CLASS(MetaProgrammingTestCase
)
48 // register in the unnamed registry so that these tests are run by default
49 CPPUNIT_TEST_SUITE_REGISTRATION( MetaProgrammingTestCase
);
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" );
56 void MetaProgrammingTestCase::IsPod()
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
);
64 CPPUNIT_ASSERT(!wxIsPod
<wxObject
>::value
);
67 void MetaProgrammingTestCase::IsMovable()
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
);
75 CPPUNIT_ASSERT(!wxIsMovable
<wxObject
>::value
);
78 void MetaProgrammingTestCase::ImplicitConversion()
80 // wxImplicitConversionType<> is used to implement wxMax(). We test it
81 // indirectly through that here.
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
);
88 CPPUNIT_ASSERT(typeid(wxImplicitConversionType
<char,int>::value
) == typeid(int));
89 CPPUNIT_ASSERT(typeid(wxImplicitConversionType
<int,unsigned>::value
) == typeid(unsigned));
91 CPPUNIT_ASSERT(typeid(wxImplicitConversionType
<wxLongLong_t
,float>::value
) == typeid(float));