]> git.saurik.com Git - wxWidgets.git/blame - tests/misc/metatest.cpp
Convert wxFSW_EVENT_{WARNING,ERROR} to string correctly.
[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
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"
fd7c5da6 17#include "wx/utils.h"
109e2ca4
JS
18#include "wx/meta/pod.h"
19#include "wx/meta/movable.h"
20
fd7c5da6
VS
21#ifndef wxNO_RTTI
22#include <typeinfo>
23#endif
24
109e2ca4
JS
25// ----------------------------------------------------------------------------
26// test class
27// ----------------------------------------------------------------------------
28
29class MetaProgrammingTestCase : public CppUnit::TestCase
30{
31public:
32 MetaProgrammingTestCase() { }
33
34private:
35 CPPUNIT_TEST_SUITE( MetaProgrammingTestCase );
36 CPPUNIT_TEST( IsPod );
37 CPPUNIT_TEST( IsMovable );
fd7c5da6 38 CPPUNIT_TEST( ImplicitConversion );
2a0ca9db 39 CPPUNIT_TEST( MinMax );
109e2ca4
JS
40 CPPUNIT_TEST_SUITE_END();
41
42 void IsPod();
43 void IsMovable();
fd7c5da6 44 void ImplicitConversion();
2a0ca9db 45 void MinMax();
109e2ca4
JS
46
47 DECLARE_NO_COPY_CLASS(MetaProgrammingTestCase)
48};
49
50// register in the unnamed registry so that these tests are run by default
51CPPUNIT_TEST_SUITE_REGISTRATION( MetaProgrammingTestCase );
52
e3778b4d 53// also include in its own registry so that these tests can be run alone
109e2ca4
JS
54CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( MetaProgrammingTestCase,
55 "MetaProgrammingTestCase" );
56
57
58void 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
69void 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}
fd7c5da6
VS
79
80void MetaProgrammingTestCase::ImplicitConversion()
81{
fd7c5da6
VS
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}
2a0ca9db
VZ
90
91void 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}