1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/misc/misctests.cpp
3 // Purpose: test miscellaneous stuff
4 // Author: Peter Most, Vadim Zeitlin
6 // Copyright: (c) 2008 Peter Most
7 // (c) 2009 Vadim Zeitlin
8 ///////////////////////////////////////////////////////////////////////////////
10 // ----------------------------------------------------------------------------
12 // ----------------------------------------------------------------------------
22 // just some classes using wxRTTI for wxStaticCast() test
23 #include "wx/tarstrm.h"
24 #include "wx/zipstrm.h"
26 // ----------------------------------------------------------------------------
28 // ----------------------------------------------------------------------------
30 class MiscTestCase
: public CppUnit::TestCase
36 CPPUNIT_TEST_SUITE( MiscTestCase
);
37 CPPUNIT_TEST( Assert
);
38 CPPUNIT_TEST( Delete
);
39 CPPUNIT_TEST( StaticCast
);
40 CPPUNIT_TEST_SUITE_END();
46 DECLARE_NO_COPY_CLASS(MiscTestCase
)
49 // register in the unnamed registry so that these tests are run by default
50 CPPUNIT_TEST_SUITE_REGISTRATION( MiscTestCase
);
52 // also include in its own registry so that these tests can be run alone
53 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( MiscTestCase
, "MiscTestCase" );
58 bool AssertIfOdd(int n
)
60 wxCHECK_MSG( !(n
% 2), false, "parameter must be even" );
65 } // anonymous namespace
67 void MiscTestCase::Assert()
70 WX_ASSERT_FAILS_WITH_ASSERT(AssertIfOdd(1));
72 // doesn't fail any more
73 wxAssertHandler_t oldHandler
= wxSetAssertHandler(NULL
);
75 wxSetAssertHandler(oldHandler
);
78 void MiscTestCase::Delete()
80 // Allocate some arbitrary memory to get a valid pointer:
81 long *pointer
= new long;
82 CPPUNIT_ASSERT( pointer
!= NULL
);
84 // Check that wxDELETE sets the pointer to NULL:
86 CPPUNIT_ASSERT( pointer
== NULL
);
88 // Allocate some arbitrary array to get a valid pointer:
89 long *array
= new long[ 3 ];
90 CPPUNIT_ASSERT( array
!= NULL
);
92 // Check that wxDELETEA sets the pointer to NULL:
94 CPPUNIT_ASSERT( array
== NULL
);
96 // this results in compilation error, as it should
98 struct SomeUnknownStruct
*p
= NULL
;
106 // helper function used just to avoid warnings about value computed not being
107 // used in WX_ASSERT_FAILS_WITH_ASSERT() in StaticCast() below
113 } // anonymous namespace
115 void MiscTestCase::StaticCast()
119 CPPUNIT_ASSERT( wxStaticCast(&tarEntry
, wxArchiveEntry
) );
121 wxArchiveEntry
*entry
= &tarEntry
;
122 CPPUNIT_ASSERT( wxStaticCast(entry
, wxTarEntry
) );
127 CPPUNIT_ASSERT( wxStaticCast(entry
, wxZipEntry
) );
128 WX_ASSERT_FAILS_WITH_ASSERT( IsNull(wxStaticCast(&zipEntry
, wxTarEntry
)) );
129 #endif // wxUSE_ZIPSTREAM
131 WX_ASSERT_FAILS_WITH_ASSERT( IsNull(wxStaticCast(entry
, wxTarEntry
)) );
132 #endif // wxUSE_TARSTREAM