]> git.saurik.com Git - wxWidgets.git/blame - include/wx/cppunit.h
corrected inverted test in IsEmpty() (patch 1936052)
[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
044a69a4
VS
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
68379eaf 65// runtime condition is true.
044a69a4
VS
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
a9dce709
VZ
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
d2001a56
VZ
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)
044a69a4 89
b7c746d0
VZ
90
91// Use this macro to assert with the given formatted message (it should contain
92// the format string and arguments in a separate pair of parentheses)
93#define WX_ASSERT_MESSAGE(msg, cond) \
94 CPPUNIT_ASSERT_MESSAGE(std::string(wxString::Format msg .mb_str()), (cond))
95
2c940453 96///////////////////////////////////////////////////////////////////////////////
6919e3bb
VZ
97// define stream inserter for wxString if it's not defined in the main library,
98// we need it to output the test failures involving wxString
99#if !wxUSE_STD_IOSTREAM
2c940453 100
ef0aeb72
MW
101#include "wx/string.h"
102
5098c258
VZ
103#include <iostream>
104
2c940453
MW
105inline std::ostream& operator<<(std::ostream& o, const wxString& s)
106{
dad49cc7
VZ
107#if wxUSE_UNICODE
108 return o << (const char *)wxSafeConvertWX2MB(s.wc_str());
109#else
110 return o << s.c_str();
111#endif
2c940453
MW
112}
113
aa709c26
VZ
114// VC6 doesn't provide overloads for operator<<(__int64) in its stream classes
115// so do it ourselves
116#if defined(__VISUALC6__) && defined(wxLongLong_t)
5098c258
VZ
117
118#include "wx/longlong.h"
119
120inline std::ostream& operator<<(std::ostream& ostr, wxLongLong_t ll)
121{
122 ostr << wxLongLong(ll).ToString();
123
124 return ostr;
125}
126
127inline std::ostream& operator<<(std::ostream& ostr, unsigned wxLongLong_t llu)
128{
129 ostr << wxULongLong(llu).ToString();
130
131 return ostr;
132}
133
aa709c26 134#endif // VC6 && wxLongLong_t
5098c258 135
6919e3bb 136#endif // !wxUSE_STD_IOSTREAM
2c940453 137
044a69a4
VS
138///////////////////////////////////////////////////////////////////////////////
139// Some more compiler warning tweaking and auto linking.
140//
141
20f46e8d
VS
142#ifdef __BORLANDC__
143 #pragma warn .8022
144#endif
145
86132a69
VZ
146#ifdef _MSC_VER
147 #pragma warning(default:4702)
148#endif // _MSC_VER
149
150// for VC++ automatically link in cppunit library
151#ifdef __VISUALC__
152 #ifdef NDEBUG
153 #pragma comment(lib, "cppunit.lib")
154 #else // Debug
155 #pragma comment(lib, "cppunitd.lib")
156 #endif // Release/Debug
157#endif
158
159#endif // _WX_CPPUNIT_H_
160