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