]> git.saurik.com Git - wxWidgets.git/blame - include/wx/cppunit.h
remove dll export declaration from wxCStrData now that all its methods are inline...
[wxWidgets.git] / include / wx / cppunit.h
CommitLineData
86132a69
VZ
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
99d80019 8// Licence: wxWindows Licence
86132a69
VZ
9/////////////////////////////////////////////////////////////////////////////
10
11#ifndef _WX_CPPUNIT_H_
12#define _WX_CPPUNIT_H_
13
044a69a4 14///////////////////////////////////////////////////////////////////////////////
86132a69
VZ
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
20f46e8d
VS
28#ifdef __BORLANDC__
29 #pragma warn -8022
30#endif
d2001a56 31
53e372c2
MW
32#ifndef CPPUNIT_STD_NEED_ALLOCATOR
33 #define CPPUNIT_STD_NEED_ALLOCATOR 0
34#endif
35
14dc53b2
MW
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
d2001a56 41#ifndef CPPUNIT_COMPILER_LOCATION_FORMAT
14dc53b2
MW
42 #define CPPUNIT_COMPILER_LOCATION_FORMAT "%p:%l:"
43#endif
20f46e8d 44
044a69a4
VS
45
46///////////////////////////////////////////////////////////////////////////////
47// Include all needed cppunit headers.
48//
49
86132a69
VZ
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>
14dc53b2 55#include <cppunit/CompilerOutputter.h>
86132a69
VZ
56#include "wx/afterstd.h"
57
3d9b0b53
VZ
58#include "wx/string.h"
59
044a69a4
VS
60
61///////////////////////////////////////////////////////////////////////////////
62// Set of helpful test macros.
63//
64
65// Base macro for wrapping CPPUNIT_TEST macros and so making them conditional
66// tests, meaning that the test only get registered and thus run when a given
68379eaf 67// runtime condition is true.
044a69a4
VS
68// In case the condition is evaluated as false a skip message is logged
69// (the message will only be shown in verbose mode).
70#define WXTEST_ANY_WITH_CONDITION(suiteName, Condition, testMethod, anyTest) \
71 if (Condition) \
72 { anyTest; } \
73 else \
74 wxLogInfo(wxString::Format(_T("skipping: %s.%s\n reason: %s equals false\n"), \
75 wxString(suiteName, wxConvUTF8).c_str(), \
76 wxString(#testMethod, wxConvUTF8).c_str(), \
77 wxString(#Condition, wxConvUTF8).c_str()))
78
79// Conditional CPPUNIT_TEST macro.
80#define WXTEST_WITH_CONDITION(suiteName, Condition, testMethod) \
81 WXTEST_ANY_WITH_CONDITION(suiteName, Condition, testMethod, CPPUNIT_TEST(testMethod))
82// Conditional CPPUNIT_TEST_FAIL macro.
83#define WXTEST_FAIL_WITH_CONDITION(suiteName, Condition, testMethod) \
84 WXTEST_ANY_WITH_CONDITION(suiteName, Condition, testMethod, CPPUNIT_TEST_FAIL(testMethod))
85
1de532f5
VZ
86CPPUNIT_NS_BEGIN
87
88// provide an overload of cppunit assertEquals(T, T) which can be used to
89// compare wxStrings directly with C strings
390b8241
VZ
90inline void
91assertEquals(const char *expected,
92 const char *actual,
93 CppUnit::SourceLine sourceLine,
94 const std::string& message)
95{
96 assertEquals(wxString(expected), wxString(actual), sourceLine, message);
97}
98
1de532f5
VZ
99inline void
100assertEquals(const char *expected,
101 const wxString& actual,
102 CppUnit::SourceLine sourceLine,
103 const std::string& message)
104{
105 assertEquals(wxString(expected), actual, sourceLine, message);
106}
107
599d1291
VZ
108inline void
109assertEquals(const wxString& expected,
110 const char *actual,
111 CppUnit::SourceLine sourceLine,
112 const std::string& message)
113{
114 assertEquals(expected, wxString(actual), sourceLine, message);
115}
116
1de532f5
VZ
117inline void
118assertEquals(const wchar_t *expected,
119 const wxString& actual,
120 CppUnit::SourceLine sourceLine,
121 const std::string& message)
122{
123 assertEquals(wxString(expected), actual, sourceLine, message);
124}
125
599d1291
VZ
126inline void
127assertEquals(const wxString& expected,
128 const wchar_t *actual,
129 CppUnit::SourceLine sourceLine,
130 const std::string& message)
131{
132 assertEquals(expected, wxString(actual), sourceLine, message);
133}
134
b2eabfe8
VZ
135CPPUNIT_NS_END
136
137// define an assertEquals() overload for the given types, this is a helper and
138// shouldn't be used directly because of VC6 complications, see below
527587d3
VZ
139#define WX_CPPUNIT_ASSERT_EQUALS(T1, T2) \
140 inline void \
141 assertEquals(T1 expected, \
142 T2 actual, \
143 CppUnit::SourceLine sourceLine, \
144 const std::string& message) \
145 { \
146 if ( !assertion_traits<T1>::equal(expected,actual) ) \
147 { \
148 Asserter::failNotEqual( assertion_traits<T1>::toString(expected), \
149 assertion_traits<T2>::toString(actual), \
150 sourceLine, \
151 message ); \
152 } \
153 }
154
b2eabfe8
VZ
155// this macro allows us to specify (usually literal) ints as expected values
156// for functions returning integral types different from "int"
157//
158// FIXME-VC6: due to incorrect resolution of overloaded/template functions in
159// this compiler (it basically doesn't use the template version at
160// all if any overloaded function matches partially even if none of
161// them matches fully) we also need to provide extra overloads
6fc905e0 162
b2eabfe8
VZ
163#ifdef __VISUALC6__
164 #define WX_CPPUNIT_ALLOW_EQUALS_TO_INT(T) \
165 CPPUNIT_NS_BEGIN \
166 WX_CPPUNIT_ASSERT_EQUALS(int, T) \
599d1291 167 WX_CPPUNIT_ASSERT_EQUALS(T, int) \
b2eabfe8
VZ
168 WX_CPPUNIT_ASSERT_EQUALS(T, T) \
169 CPPUNIT_NS_END
170
171 CPPUNIT_NS_BEGIN
172 WX_CPPUNIT_ASSERT_EQUALS(int, int)
173 CPPUNIT_NS_END
174#else // !VC6
175 #define WX_CPPUNIT_ALLOW_EQUALS_TO_INT(T) \
176 CPPUNIT_NS_BEGIN \
177 WX_CPPUNIT_ASSERT_EQUALS(int, T) \
599d1291 178 WX_CPPUNIT_ASSERT_EQUALS(T, int) \
b2eabfe8
VZ
179 CPPUNIT_NS_END
180#endif // VC6/!VC6
181
182WX_CPPUNIT_ALLOW_EQUALS_TO_INT(long)
183WX_CPPUNIT_ALLOW_EQUALS_TO_INT(short)
306f34a3
VZ
184WX_CPPUNIT_ALLOW_EQUALS_TO_INT(unsigned)
185WX_CPPUNIT_ALLOW_EQUALS_TO_INT(unsigned long)
044a69a4 186
5769cf0f
VZ
187// Use this macro to compare a wxArrayString with the pipe-separated elements
188// of the given string
189//
190// NB: it's a macro and not a function to have the correct line numbers in the
191// test failure messages
192#define WX_ASSERT_STRARRAY_EQUAL(s, a) \
193 { \
194 wxArrayString expected(wxSplit(s, '|', '\0')); \
195 \
196 CPPUNIT_ASSERT_EQUAL( expected.size(), a.size() ); \
197 \
198 for ( size_t n = 0; n < a.size(); n++ ) \
199 { \
200 CPPUNIT_ASSERT_EQUAL( expected[n], a[n] ); \
201 } \
202 }
b7c746d0
VZ
203
204// Use this macro to assert with the given formatted message (it should contain
205// the format string and arguments in a separate pair of parentheses)
206#define WX_ASSERT_MESSAGE(msg, cond) \
207 CPPUNIT_ASSERT_MESSAGE(std::string(wxString::Format msg .mb_str()), (cond))
208
e18865ec
VZ
209#define WX_ASSERT_EQUAL_MESSAGE(msg, expected, actual) \
210 CPPUNIT_ASSERT_EQUAL_MESSAGE(std::string(wxString::Format msg .mb_str()), \
211 (expected), (actual))
212
2c940453 213///////////////////////////////////////////////////////////////////////////////
6919e3bb
VZ
214// define stream inserter for wxString if it's not defined in the main library,
215// we need it to output the test failures involving wxString
216#if !wxUSE_STD_IOSTREAM
2c940453 217
ef0aeb72
MW
218#include "wx/string.h"
219
5098c258
VZ
220#include <iostream>
221
2c940453
MW
222inline std::ostream& operator<<(std::ostream& o, const wxString& s)
223{
dad49cc7
VZ
224#if wxUSE_UNICODE
225 return o << (const char *)wxSafeConvertWX2MB(s.wc_str());
226#else
227 return o << s.c_str();
228#endif
2c940453
MW
229}
230
55d9f029
VZ
231#endif // !wxUSE_STD_IOSTREAM
232
aa709c26
VZ
233// VC6 doesn't provide overloads for operator<<(__int64) in its stream classes
234// so do it ourselves
235#if defined(__VISUALC6__) && defined(wxLongLong_t)
5098c258
VZ
236
237#include "wx/longlong.h"
238
239inline std::ostream& operator<<(std::ostream& ostr, wxLongLong_t ll)
240{
241 ostr << wxLongLong(ll).ToString();
242
243 return ostr;
244}
245
246inline std::ostream& operator<<(std::ostream& ostr, unsigned wxLongLong_t llu)
247{
248 ostr << wxULongLong(llu).ToString();
249
250 return ostr;
251}
252
aa709c26 253#endif // VC6 && wxLongLong_t
5098c258 254
044a69a4
VS
255///////////////////////////////////////////////////////////////////////////////
256// Some more compiler warning tweaking and auto linking.
257//
258
20f46e8d
VS
259#ifdef __BORLANDC__
260 #pragma warn .8022
261#endif
262
86132a69
VZ
263#ifdef _MSC_VER
264 #pragma warning(default:4702)
265#endif // _MSC_VER
266
267// for VC++ automatically link in cppunit library
268#ifdef __VISUALC__
269 #ifdef NDEBUG
270 #pragma comment(lib, "cppunit.lib")
271 #else // Debug
272 #pragma comment(lib, "cppunitd.lib")
273 #endif // Release/Debug
274#endif
275
276#endif // _WX_CPPUNIT_H_
277