]> git.saurik.com Git - wxWidgets.git/blob - tests/misc/misctests.cpp
Don't reset bullet number and outline number when applying style sheet.
[wxWidgets.git] / tests / misc / misctests.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/misc/misctests.cpp
3 // Purpose: test miscellaneous stuff
4 // Author: Peter Most, Vadim Zeitlin
5 // Created: 2008-07-10
6 // RCS-ID: $Id$
7 // Copyright: (c) 2008 Peter Most
8 // (c) 2009 Vadim Zeitlin
9 ///////////////////////////////////////////////////////////////////////////////
10
11 // ----------------------------------------------------------------------------
12 // headers
13 // ----------------------------------------------------------------------------
14
15 #include "testprec.h"
16
17 #ifdef __BORLANDC__
18 #pragma hdrstop
19 #endif
20
21 #include "wx/defs.h"
22
23 // just some classes using wxRTTI for wxStaticCast() test
24 #include "wx/tarstrm.h"
25 #include "wx/zipstrm.h"
26
27 // ----------------------------------------------------------------------------
28 // test class
29 // ----------------------------------------------------------------------------
30
31 class MiscTestCase : public CppUnit::TestCase
32 {
33 public:
34 MiscTestCase() { }
35
36 private:
37 CPPUNIT_TEST_SUITE( MiscTestCase );
38 CPPUNIT_TEST( Assert );
39 CPPUNIT_TEST( Delete );
40 CPPUNIT_TEST( StaticCast );
41 CPPUNIT_TEST_SUITE_END();
42
43 void Assert();
44 void Delete();
45 void StaticCast();
46
47 DECLARE_NO_COPY_CLASS(MiscTestCase)
48 };
49
50 // register in the unnamed registry so that these tests are run by default
51 CPPUNIT_TEST_SUITE_REGISTRATION( MiscTestCase );
52
53 // also include in it's own registry so that these tests can be run alone
54 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( MiscTestCase, "MiscTestCase" );
55
56 namespace
57 {
58
59 bool AssertIfOdd(int n)
60 {
61 wxCHECK_MSG( !(n % 2), false, "parameter must be even" );
62
63 return true;
64 }
65
66 } // anonymous namespace
67
68 void MiscTestCase::Assert()
69 {
70 AssertIfOdd(0);
71 WX_ASSERT_FAILS_WITH_ASSERT(AssertIfOdd(1));
72
73 // doesn't fail any more
74 wxAssertHandler_t oldHandler = wxSetAssertHandler(NULL);
75 AssertIfOdd(17);
76 wxSetAssertHandler(oldHandler);
77 }
78
79 void MiscTestCase::Delete()
80 {
81 // Allocate some arbitrary memory to get a valid pointer:
82 long *pointer = new long;
83 CPPUNIT_ASSERT( pointer != NULL );
84
85 // Check that wxDELETE sets the pointer to NULL:
86 wxDELETE( pointer );
87 CPPUNIT_ASSERT( pointer == NULL );
88
89 // Allocate some arbitrary array to get a valid pointer:
90 long *array = new long[ 3 ];
91 CPPUNIT_ASSERT( array != NULL );
92
93 // Check that wxDELETEA sets the pointer to NULL:
94 wxDELETE( array );
95 CPPUNIT_ASSERT( array == NULL );
96
97 // this results in compilation error, as it should
98 #if 0
99 struct SomeUnknownStruct *p = NULL;
100 wxDELETE(p);
101 #endif
102 }
103
104 namespace
105 {
106
107 // helper function used just to avoid warnings about value computed not being
108 // used in WX_ASSERT_FAILS_WITH_ASSERT() in StaticCast() below
109 bool IsNull(void *p)
110 {
111 return p == NULL;
112 }
113
114 } // anonymous namespace
115
116 void MiscTestCase::StaticCast()
117 {
118 wxTarEntry tarEntry;
119 CPPUNIT_ASSERT( wxStaticCast(&tarEntry, wxArchiveEntry) );
120
121 wxArchiveEntry *entry = &tarEntry;
122 CPPUNIT_ASSERT( wxStaticCast(entry, wxTarEntry) );
123
124 wxZipEntry zipEntry;
125 entry = &zipEntry;
126 CPPUNIT_ASSERT( wxStaticCast(entry, wxZipEntry) );
127
128 WX_ASSERT_FAILS_WITH_ASSERT( IsNull(wxStaticCast(entry, wxTarEntry)) );
129 WX_ASSERT_FAILS_WITH_ASSERT( IsNull(wxStaticCast(&zipEntry, wxTarEntry)) );
130 }
131