]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/cppunit.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wrapper header for CppUnit headers
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 2004 Vadim Zeitlin
8 // Licence: wxWindows Licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_CPPUNIT_H_
12 #define _WX_CPPUNIT_H_
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
18 // typedef-name 'foo' used as synonym for class-name 'bar'
19 #pragma warning(disable:4097)
21 // unreachable code: we don't care about warnings in CppUnit headers
22 #pragma warning(disable:4702)
24 // 'id': identifier was truncated to 'num' characters in the debug info
25 #pragma warning(disable:4786)
32 #ifndef CPPUNIT_STD_NEED_ALLOCATOR
33 #define CPPUNIT_STD_NEED_ALLOCATOR 0
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++).
41 #ifndef CPPUNIT_COMPILER_LOCATION_FORMAT
42 #define CPPUNIT_COMPILER_LOCATION_FORMAT "%p:%l:"
46 ///////////////////////////////////////////////////////////////////////////////
47 // Include all needed cppunit headers.
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"
59 ///////////////////////////////////////////////////////////////////////////////
60 // Set of helpful test macros.
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) \
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()))
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))
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)
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)
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))
96 ///////////////////////////////////////////////////////////////////////////////
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
101 #include "wx/string.h"
105 inline std::ostream
& operator<<(std::ostream
& o
, const wxString
& s
)
108 return o
<< (const char *)wxSafeConvertWX2MB(s
.wc_str());
110 return o
<< s
.c_str();
116 #include "wx/longlong.h"
118 inline std::ostream
& operator<<(std::ostream
& ostr
, wxLongLong_t ll
)
120 ostr
<< wxLongLong(ll
).ToString();
125 inline std::ostream
& operator<<(std::ostream
& ostr
, unsigned wxLongLong_t llu
)
127 ostr
<< wxULongLong(llu
).ToString();
132 #endif // wxLongLong_t
134 #endif // !wxUSE_STD_IOSTREAM
136 ///////////////////////////////////////////////////////////////////////////////
137 // Some more compiler warning tweaking and auto linking.
145 #pragma warning(default:4702)
148 // for VC++ automatically link in cppunit library
151 #pragma comment(lib, "cppunit.lib")
153 #pragma comment(lib, "cppunitd.lib")
154 #endif // Release/Debug
157 #endif // _WX_CPPUNIT_H_