]> git.saurik.com Git - wxWidgets.git/blob - tests/misc/misctests.cpp
3ead0b38ecbcf0ace7f63cbf4b69792fceef2ed1
[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 // ----------------------------------------------------------------------------
24 // test class
25 // ----------------------------------------------------------------------------
26
27 class MiscTestCase : public CppUnit::TestCase
28 {
29 public:
30 MiscTestCase() { }
31
32 private:
33 CPPUNIT_TEST_SUITE( MiscTestCase );
34 CPPUNIT_TEST( Assert );
35 CPPUNIT_TEST( Delete );
36 CPPUNIT_TEST_SUITE_END();
37
38 void Assert();
39 void Delete();
40
41 DECLARE_NO_COPY_CLASS(MiscTestCase)
42 };
43
44 // register in the unnamed registry so that these tests are run by default
45 CPPUNIT_TEST_SUITE_REGISTRATION( MiscTestCase );
46
47 // also include in it's own registry so that these tests can be run alone
48 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( MiscTestCase, "MiscTestCase" );
49
50 namespace
51 {
52
53 void AssertIfOdd(int n)
54 {
55 wxASSERT_MSG( !(n % 2), "parameter must be even" );
56 }
57
58 } // anonymous namespace
59
60 void MiscTestCase::Assert()
61 {
62 AssertIfOdd(0);
63 WX_ASSERT_FAILS_WITH_ASSERT(AssertIfOdd(1));
64
65 // doesn't fail any more
66 wxAssertHandler_t oldHandler = wxSetAssertHandler(NULL);
67 AssertIfOdd(17);
68 wxSetAssertHandler(oldHandler);
69 }
70
71 void MiscTestCase::Delete()
72 {
73 // Allocate some arbitrary memory to get a valid pointer:
74 long *pointer = new long;
75 CPPUNIT_ASSERT( pointer != NULL );
76
77 // Check that wxDELETE sets the pointer to NULL:
78 wxDELETE( pointer );
79 CPPUNIT_ASSERT( pointer == NULL );
80
81 // Allocate some arbitrary array to get a valid pointer:
82 long *array = new long[ 3 ];
83 CPPUNIT_ASSERT( array != NULL );
84
85 // Check that wxDELETEA sets the pointer to NULL:
86 wxDELETE( array );
87 CPPUNIT_ASSERT( array == NULL );
88
89 // this results in compilation error, as it should
90 #if 0
91 struct SomeUnknownStruct *p = NULL;
92 wxDELETE(p);
93 #endif
94 }
95