]> git.saurik.com Git - wxWidgets.git/blame - tests/testprec.h
Fix for wxChm
[wxWidgets.git] / tests / testprec.h
CommitLineData
8899b155
RN
1#include "wx/wxprec.h"
2#include "wx/cppunit.h"
8da7a00a 3
232fdc63
VZ
4// Custom test macro that is only defined when wxUIActionSimulator is available
5// this allows the tests that do not rely on it to run on platforms that don't
6// support it.
7//
8// FIXME: And while OS X does support it, more or less, too many tests
9// currently fail under it so disable all interactive tests there. They
10// should, of course, be reenabled a.s.a.p.
11#if wxUSE_UIACTIONSIMULATOR && !defined(__WXOSX__)
12 #define WXUISIM_TEST(test) CPPUNIT_TEST(test)
13#else
14 #define WXUISIM_TEST(test) (void)0
15#endif
16
8da7a00a
VZ
17// define wxHAVE_U_ESCAPE if the compiler supports \uxxxx character constants
18#if (defined(__VISUALC__) && (__VISUALC__ >= 1300)) || \
19 (defined(__GNUC__) && (__GNUC__ >= 3))
20 #define wxHAVE_U_ESCAPE
a8f17758
VZ
21
22 // and disable warning that using them results in with MSVC 8+
23 #if wxCHECK_VISUALC_VERSION(8)
24 // universal-character-name encountered in source
25 #pragma warning(disable:4428)
26 #endif
8da7a00a 27#endif
0468a58a 28
43f8864b
VZ
29// Define wxUSING_VC_CRT_IO when using MSVC CRT STDIO library as its standard
30// functions give different results from glibc ones in several cases (of
31// course, any code relying on this is not portable and probably won't work,
32// i.e. will result in tests failures, with other platforms/compilers which
33// should have checks for them added as well).
34//
35// Notice that MinGW uses VC CRT by default but may use its own printf()
36// implementation if __USE_MINGW_ANSI_STDIO is defined. And finally also notice
37// that testing for __USE_MINGW_ANSI_STDIO directly results in a warning with
38// -Wundef if it involves an operation with undefined __MINGW_FEATURES__ so
39// test for the latter too to avoid it.
40#if defined(__VISUALC__) || \
c4cb46c1
VZ
41 (defined(__MINGW32__) && \
42 (!defined(__MINGW_FEATURES__) || !__USE_MINGW_ANSI_STDIO))
43f8864b
VZ
43 #define wxUSING_VC_CRT_IO
44#endif
45
0468a58a 46// thrown when assert fails in debug build
b33e98f0
VZ
47class TestAssertFailure
48{
49public:
50 TestAssertFailure(const wxString& file,
51 int line,
52 const wxString& func,
53 const wxString& cond,
54 const wxString& msg)
55 : m_file(file),
56 m_line(line),
57 m_func(func),
58 m_cond(cond),
59 m_msg(msg)
60 {
61 }
62
63 const wxString m_file;
64 const int m_line;
65 const wxString m_func;
66 const wxString m_cond;
67 const wxString m_msg;
68
69 wxDECLARE_NO_ASSIGN_CLASS(TestAssertFailure);
70};
0468a58a
VZ
71
72// macro to use for the functions which are supposed to fail an assertion
657a8a35 73#if wxDEBUG_LEVEL
0468a58a
VZ
74 // some old cppunit versions don't define CPPUNIT_ASSERT_THROW so roll our
75 // own
76 #define WX_ASSERT_FAILS_WITH_ASSERT(cond) \
77 { \
78 bool throwsAssert = false; \
79 try { cond ; } \
80 catch ( const TestAssertFailure& ) { throwsAssert = true; } \
81 if ( !throwsAssert ) \
82 CPPUNIT_FAIL("expected assertion not generated"); \
83 }
84#else
657a8a35 85 // there are no assertions in this build so just check that it fails
0468a58a
VZ
86 #define WX_ASSERT_FAILS_WITH_ASSERT(cond) CPPUNIT_ASSERT(!(cond))
87#endif
88
1649d288
VZ
89// these functions can be used to hook into wxApp event processing and are
90// currently used by the events propagation test
9eab6725
VZ
91class WXDLLIMPEXP_FWD_BASE wxEvent;
92
1649d288
VZ
93typedef int (*FilterEventFunc)(wxEvent&);
94typedef bool (*ProcessEventFunc)(wxEvent&);
95
96extern void SetFilterEventFunc(FilterEventFunc func);
97extern void SetProcessEventFunc(ProcessEventFunc func);
1f51673b
FM
98
99extern bool IsNetworkAvailable();
701aa4d8 100
12249b19
VZ
101// Helper class setting the locale to the given one for its lifetime.
102class LocaleSetter
701aa4d8
FM
103{
104public:
12249b19
VZ
105 LocaleSetter(const char *loc) : m_locOld(setlocale(LC_ALL, loc)) { }
106 ~LocaleSetter() { setlocale(LC_ALL, m_locOld); }
701aa4d8
FM
107
108private:
109 const char * const m_locOld;
12249b19
VZ
110
111 wxDECLARE_NO_COPY_CLASS(LocaleSetter);
112};
113
114// An even simpler helper for setting the locale to "C" one during its lifetime.
115class CLocaleSetter : private LocaleSetter
116{
117public:
118 CLocaleSetter() : LocaleSetter("C") { }
119
120private:
701aa4d8
FM
121 wxDECLARE_NO_COPY_CLASS(CLocaleSetter);
122};
8cdd00f2
VZ
123
124// Macro that can be used to register the test with the given name in both the
125// global unnamed registry so that it is ran by default and a registry with the
126// same name as this test to allow running just this test individually.
127//
128// Notice that the name shouldn't include the "TestCase" suffix, it's added
129// automatically by this macro.
130//
131// Implementation note: CPPUNIT_TEST_SUITE_[NAMED_]REGISTRATION macros can't be
132// used here because they both declare the variable with the same name (as the
133// "unique" name they generate is based on the line number which is the same
134// for both calls inside the macro), so we need to do it manually.
135#define wxREGISTER_UNIT_TEST(name) \
136 static CPPUNIT_NS::AutoRegisterSuite< name##TestCase > \
137 CPPUNIT_MAKE_UNIQUE_NAME( autoRegisterRegistry__ ); \
138 static CPPUNIT_NS::AutoRegisterSuite< name##TestCase > \
139 CPPUNIT_MAKE_UNIQUE_NAME( autoRegisterNamedRegistry__ )(#name "TestCase")