]> git.saurik.com Git - wxWidgets.git/blame - tests/misc/metatest.cpp
wxMessageBox off the main thread lost result code.
[wxWidgets.git] / tests / misc / metatest.cpp
CommitLineData
109e2ca4
JS
1///////////////////////////////////////////////////////////////////////////////
2// Name: tests/misc/metatest.cpp
3// Purpose: Test template meta-programming constructs
4// Author: Jaakko Salli
109e2ca4
JS
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"
fd7c5da6 16#include "wx/utils.h"
109e2ca4
JS
17#include "wx/meta/pod.h"
18#include "wx/meta/movable.h"
19
fd7c5da6
VS
20#ifndef wxNO_RTTI
21#include <typeinfo>
22#endif
23
109e2ca4
JS
24// ----------------------------------------------------------------------------
25// test class
26// ----------------------------------------------------------------------------
27
28class MetaProgrammingTestCase : public CppUnit::TestCase
29{
30public:
31 MetaProgrammingTestCase() { }
32
33private:
34 CPPUNIT_TEST_SUITE( MetaProgrammingTestCase );
35 CPPUNIT_TEST( IsPod );
36 CPPUNIT_TEST( IsMovable );
fd7c5da6 37 CPPUNIT_TEST( ImplicitConversion );
2a0ca9db 38 CPPUNIT_TEST( MinMax );
109e2ca4
JS
39 CPPUNIT_TEST_SUITE_END();
40
41 void IsPod();
42 void IsMovable();
fd7c5da6 43 void ImplicitConversion();
2a0ca9db 44 void MinMax();
109e2ca4
JS
45
46 DECLARE_NO_COPY_CLASS(MetaProgrammingTestCase)
47};
48
49// register in the unnamed registry so that these tests are run by default
50CPPUNIT_TEST_SUITE_REGISTRATION( MetaProgrammingTestCase );
51
e3778b4d 52// also include in its own registry so that these tests can be run alone
109e2ca4
JS
53CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( MetaProgrammingTestCase,
54 "MetaProgrammingTestCase" );
55
56
57void 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
68void 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}
fd7c5da6
VS
78
79void MetaProgrammingTestCase::ImplicitConversion()
80{
fd7c5da6
VS
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}
2a0ca9db
VZ
89
90void 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}