]> git.saurik.com Git - wxWidgets.git/blob - include/wx/cppunit.h
fix gcc warnings about not calling the base class ctors (replaces patch 1962992)
[wxWidgets.git] / include / wx / cppunit.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/cppunit.h
3 // Purpose: wrapper header for CppUnit headers
4 // Author: Vadim Zeitlin
5 // Created: 15.02.04
6 // RCS-ID: $Id$
7 // Copyright: (c) 2004 Vadim Zeitlin
8 // Licence: wxWindows Licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _WX_CPPUNIT_H_
12 #define _WX_CPPUNIT_H_
13
14 ///////////////////////////////////////////////////////////////////////////////
15 // using CPPUNIT_TEST() macro results in this warning, disable it as there is
16 // no other way to get rid of it and it's not very useful anyhow
17 #ifdef __VISUALC__
18 // typedef-name 'foo' used as synonym for class-name 'bar'
19 #pragma warning(disable:4097)
20
21 // unreachable code: we don't care about warnings in CppUnit headers
22 #pragma warning(disable:4702)
23
24 // 'id': identifier was truncated to 'num' characters in the debug info
25 #pragma warning(disable:4786)
26 #endif // __VISUALC__
27
28 #ifdef __BORLANDC__
29 #pragma warn -8022
30 #endif
31
32 #ifndef CPPUNIT_STD_NEED_ALLOCATOR
33 #define CPPUNIT_STD_NEED_ALLOCATOR 0
34 #endif
35
36 ///////////////////////////////////////////////////////////////////////////////
37 // Set the default format for the errors, which can be used by an IDE to jump
38 // to the error location. This default gets overridden by the cppunit headers
39 // for some compilers (e.g. VC++).
40
41 #ifndef CPPUNIT_COMPILER_LOCATION_FORMAT
42 #define CPPUNIT_COMPILER_LOCATION_FORMAT "%p:%l:"
43 #endif
44
45
46 ///////////////////////////////////////////////////////////////////////////////
47 // Include all needed cppunit headers.
48 //
49
50 #include "wx/beforestd.h"
51 #include <cppunit/extensions/TestFactoryRegistry.h>
52 #include <cppunit/ui/text/TestRunner.h>
53 #include <cppunit/TestCase.h>
54 #include <cppunit/extensions/HelperMacros.h>
55 #include <cppunit/CompilerOutputter.h>
56 #include "wx/afterstd.h"
57
58
59 ///////////////////////////////////////////////////////////////////////////////
60 // Set of helpful test macros.
61 //
62
63 // Base macro for wrapping CPPUNIT_TEST macros and so making them conditional
64 // tests, meaning that the test only get registered and thus run when a given
65 // runtime condition is true.
66 // In case the condition is evaluated as false a skip message is logged
67 // (the message will only be shown in verbose mode).
68 #define WXTEST_ANY_WITH_CONDITION(suiteName, Condition, testMethod, anyTest) \
69 if (Condition) \
70 { anyTest; } \
71 else \
72 wxLogInfo(wxString::Format(_T("skipping: %s.%s\n reason: %s equals false\n"), \
73 wxString(suiteName, wxConvUTF8).c_str(), \
74 wxString(#testMethod, wxConvUTF8).c_str(), \
75 wxString(#Condition, wxConvUTF8).c_str()))
76
77 // Conditional CPPUNIT_TEST macro.
78 #define WXTEST_WITH_CONDITION(suiteName, Condition, testMethod) \
79 WXTEST_ANY_WITH_CONDITION(suiteName, Condition, testMethod, CPPUNIT_TEST(testMethod))
80 // Conditional CPPUNIT_TEST_FAIL macro.
81 #define WXTEST_FAIL_WITH_CONDITION(suiteName, Condition, testMethod) \
82 WXTEST_ANY_WITH_CONDITION(suiteName, Condition, testMethod, CPPUNIT_TEST_FAIL(testMethod))
83
84 // Use this macro to compare a wxString with a literal string.
85 #define WX_ASSERT_STR_EQUAL(p, s) CPPUNIT_ASSERT_EQUAL(wxString(p), s)
86
87 // Use this macro to compare a size_t with a literal integer
88 #define WX_ASSERT_SIZET_EQUAL(n, m) CPPUNIT_ASSERT_EQUAL(((size_t)n), m)
89
90 // Use this macro to compare a wxArrayString with the pipe-separated elements
91 // of the given string
92 //
93 // NB: it's a macro and not a function to have the correct line numbers in the
94 // test failure messages
95 #define WX_ASSERT_STRARRAY_EQUAL(s, a) \
96 { \
97 wxArrayString expected(wxSplit(s, '|', '\0')); \
98 \
99 CPPUNIT_ASSERT_EQUAL( expected.size(), a.size() ); \
100 \
101 for ( size_t n = 0; n < a.size(); n++ ) \
102 { \
103 CPPUNIT_ASSERT_EQUAL( expected[n], a[n] ); \
104 } \
105 }
106
107 // Use this macro to assert with the given formatted message (it should contain
108 // the format string and arguments in a separate pair of parentheses)
109 #define WX_ASSERT_MESSAGE(msg, cond) \
110 CPPUNIT_ASSERT_MESSAGE(std::string(wxString::Format msg .mb_str()), (cond))
111
112 ///////////////////////////////////////////////////////////////////////////////
113 // define stream inserter for wxString if it's not defined in the main library,
114 // we need it to output the test failures involving wxString
115 #if !wxUSE_STD_IOSTREAM
116
117 #include "wx/string.h"
118
119 #include <iostream>
120
121 inline std::ostream& operator<<(std::ostream& o, const wxString& s)
122 {
123 #if wxUSE_UNICODE
124 return o << (const char *)wxSafeConvertWX2MB(s.wc_str());
125 #else
126 return o << s.c_str();
127 #endif
128 }
129
130 // VC6 doesn't provide overloads for operator<<(__int64) in its stream classes
131 // so do it ourselves
132 #if defined(__VISUALC6__) && defined(wxLongLong_t)
133
134 #include "wx/longlong.h"
135
136 inline std::ostream& operator<<(std::ostream& ostr, wxLongLong_t ll)
137 {
138 ostr << wxLongLong(ll).ToString();
139
140 return ostr;
141 }
142
143 inline std::ostream& operator<<(std::ostream& ostr, unsigned wxLongLong_t llu)
144 {
145 ostr << wxULongLong(llu).ToString();
146
147 return ostr;
148 }
149
150 #endif // VC6 && wxLongLong_t
151
152 #endif // !wxUSE_STD_IOSTREAM
153
154 ///////////////////////////////////////////////////////////////////////////////
155 // Some more compiler warning tweaking and auto linking.
156 //
157
158 #ifdef __BORLANDC__
159 #pragma warn .8022
160 #endif
161
162 #ifdef _MSC_VER
163 #pragma warning(default:4702)
164 #endif // _MSC_VER
165
166 // for VC++ automatically link in cppunit library
167 #ifdef __VISUALC__
168 #ifdef NDEBUG
169 #pragma comment(lib, "cppunit.lib")
170 #else // Debug
171 #pragma comment(lib, "cppunitd.lib")
172 #endif // Release/Debug
173 #endif
174
175 #endif // _WX_CPPUNIT_H_
176