1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/misc/misctests.cpp
3 // Purpose: test miscellaneous stuff
4 // Author: Peter Most, Vadim Zeitlin
7 // Copyright: (c) 2008 Peter Most
8 // (c) 2009 Vadim Zeitlin
9 ///////////////////////////////////////////////////////////////////////////////
11 // ----------------------------------------------------------------------------
13 // ----------------------------------------------------------------------------
23 // ----------------------------------------------------------------------------
25 // ----------------------------------------------------------------------------
27 class MiscTestCase
: public CppUnit::TestCase
33 CPPUNIT_TEST_SUITE( MiscTestCase
);
34 CPPUNIT_TEST( Assert
);
35 CPPUNIT_TEST( Delete
);
36 CPPUNIT_TEST_SUITE_END();
41 DECLARE_NO_COPY_CLASS(MiscTestCase
)
44 // register in the unnamed registry so that these tests are run by default
45 CPPUNIT_TEST_SUITE_REGISTRATION( MiscTestCase
);
47 // also include in it's own registry so that these tests can be run alone
48 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( MiscTestCase
, "MiscTestCase" );
53 void AssertIfOdd(int n
)
55 wxASSERT_MSG( !(n
% 2), "parameter must be even" );
58 } // anonymous namespace
60 void MiscTestCase::Assert()
63 WX_ASSERT_FAILS_WITH_ASSERT(AssertIfOdd(1));
65 // doesn't fail any more
66 wxAssertHandler_t oldHandler
= wxSetAssertHandler(NULL
);
68 wxSetAssertHandler(oldHandler
);
71 void MiscTestCase::Delete()
73 // Allocate some arbitrary memory to get a valid pointer:
74 long *pointer
= new long;
75 CPPUNIT_ASSERT( pointer
!= NULL
);
77 // Check that wxDELETE sets the pointer to NULL:
79 CPPUNIT_ASSERT( pointer
== NULL
);
81 // Allocate some arbitrary array to get a valid pointer:
82 long *array
= new long[ 3 ];
83 CPPUNIT_ASSERT( array
!= NULL
);
85 // Check that wxDELETEA sets the pointer to NULL:
87 CPPUNIT_ASSERT( array
== NULL
);
89 // this results in compilation error, as it should
91 struct SomeUnknownStruct
*p
= NULL
;