]> git.saurik.com Git - wxWidgets.git/blame_incremental - tests/testprec.h
Unload bogus XRC resources in "garbage" unit test.
[wxWidgets.git] / tests / testprec.h
... / ...
CommitLineData
1#include "wx/wxprec.h"
2#include "wx/cppunit.h"
3
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
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
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
27#endif
28
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__) || \
41 (defined(__MINGW32__) && \
42 (!defined(__MINGW_FEATURES__) || !__USE_MINGW_ANSI_STDIO))
43 #define wxUSING_VC_CRT_IO
44#endif
45
46// thrown when assert fails in debug build
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};
71
72// macro to use for the functions which are supposed to fail an assertion
73#if wxDEBUG_LEVEL
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
85 // there are no assertions in this build so just check that it fails
86 #define WX_ASSERT_FAILS_WITH_ASSERT(cond) CPPUNIT_ASSERT(!(cond))
87#endif
88
89// these functions can be used to hook into wxApp event processing and are
90// currently used by the events propagation test
91class WXDLLIMPEXP_FWD_BASE wxEvent;
92
93typedef int (*FilterEventFunc)(wxEvent&);
94typedef bool (*ProcessEventFunc)(wxEvent&);
95
96extern void SetFilterEventFunc(FilterEventFunc func);
97extern void SetProcessEventFunc(ProcessEventFunc func);
98
99extern bool IsNetworkAvailable();
100
101// Helper class setting the locale to the given one for its lifetime.
102class LocaleSetter
103{
104public:
105 LocaleSetter(const char *loc) : m_locOld(setlocale(LC_ALL, loc)) { }
106 ~LocaleSetter() { setlocale(LC_ALL, m_locOld); }
107
108private:
109 const char * const m_locOld;
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:
121 wxDECLARE_NO_COPY_CLASS(CLocaleSetter);
122};
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")