File: metatest.cpp

package info (click to toggle)
wxwidgets3.0 3.0.5.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 120,464 kB
  • sloc: cpp: 896,633; makefile: 52,303; ansic: 21,971; sh: 5,713; python: 2,940; xml: 1,534; perl: 264; javascript: 33
file content (104 lines) | stat: -rw-r--r-- 3,226 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
///////////////////////////////////////////////////////////////////////////////
// Name:        tests/misc/metatest.cpp
// Purpose:     Test template meta-programming constructs
// Author:      Jaakko Salli
// Copyright:   (c) the wxWidgets team
// Licence:     wxWindows licence
///////////////////////////////////////////////////////////////////////////////

#include "testprec.h"

#ifdef __BORLANDC__
#   pragma hdrstop
#endif

#include "wx/object.h"
#include "wx/utils.h"
#include "wx/meta/pod.h"
#include "wx/meta/movable.h"

#ifndef wxNO_RTTI
#include <typeinfo>
#endif

// ----------------------------------------------------------------------------
// test class
// ----------------------------------------------------------------------------

class MetaProgrammingTestCase : public CppUnit::TestCase
{
public:
    MetaProgrammingTestCase() { }

private:
    CPPUNIT_TEST_SUITE( MetaProgrammingTestCase );
        CPPUNIT_TEST( IsPod );
        CPPUNIT_TEST( IsMovable );
        CPPUNIT_TEST( ImplicitConversion );
        CPPUNIT_TEST( MinMax );
    CPPUNIT_TEST_SUITE_END();

    void IsPod();
    void IsMovable();
    void ImplicitConversion();
    void MinMax();

    DECLARE_NO_COPY_CLASS(MetaProgrammingTestCase)
};

// register in the unnamed registry so that these tests are run by default
CPPUNIT_TEST_SUITE_REGISTRATION( MetaProgrammingTestCase );

// also include in its own registry so that these tests can be run alone
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( MetaProgrammingTestCase,
                                       "MetaProgrammingTestCase" );


void MetaProgrammingTestCase::IsPod()
{
    CPPUNIT_ASSERT(wxIsPod<bool>::value);
    CPPUNIT_ASSERT(wxIsPod<signed int>::value);
    CPPUNIT_ASSERT(wxIsPod<double>::value);
#if !defined(__VISUALC__) || wxCHECK_VISUALC_VERSION(7)
    CPPUNIT_ASSERT(wxIsPod<wxObject*>::value);
#endif
    CPPUNIT_ASSERT(!wxIsPod<wxObject>::value);
}

void MetaProgrammingTestCase::IsMovable()
{
    CPPUNIT_ASSERT(wxIsMovable<bool>::value);
    CPPUNIT_ASSERT(wxIsMovable<signed int>::value);
    CPPUNIT_ASSERT(wxIsMovable<double>::value);
#if !defined(__VISUALC__) || wxCHECK_VISUALC_VERSION(7)
    CPPUNIT_ASSERT(wxIsMovable<wxObject*>::value);
#endif
    CPPUNIT_ASSERT(!wxIsMovable<wxObject>::value);
}

void MetaProgrammingTestCase::ImplicitConversion()
{
#ifndef wxNO_RTTI
    CPPUNIT_ASSERT(typeid(wxImplicitConversionType<char,int>::value) == typeid(int));
    CPPUNIT_ASSERT(typeid(wxImplicitConversionType<int,unsigned>::value) == typeid(unsigned));
#ifdef wxLongLong_t
    CPPUNIT_ASSERT(typeid(wxImplicitConversionType<wxLongLong_t,float>::value) == typeid(float));
#endif
#endif // !wxNO_RTTI
}

void MetaProgrammingTestCase::MinMax()
{
    // test that wxMax(1.1,1) returns float, not long int
    float f = wxMax(1.1f, 1l);
    CPPUNIT_ASSERT_EQUAL( 1.1f, f);

    // test that comparing signed and unsigned correctly returns unsigned: this
    // may seem counterintuitive in this case but this is consistent with the
    // standard C conversions
    CPPUNIT_ASSERT_EQUAL( 1, wxMin(-1, 1u) );

    CPPUNIT_ASSERT_EQUAL( -1., wxClip(-1.5, -1, 1) );
    CPPUNIT_ASSERT_EQUAL( 0, wxClip(0, -1, 1) );
    CPPUNIT_ASSERT_EQUAL( 1, wxClip(2l, -1, 1) );
}