]> git.saurik.com Git - wxWidgets.git/blob - tests/testprec.h
7724b1959180b6aa4572620702e40ee395c6c59d
[wxWidgets.git] / tests / testprec.h
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__) && !defined(__MINGW_FEATURES__) || !__USE_MINGW_ANSI_STDIO)
42 #define wxUSING_VC_CRT_IO
43 #endif
44
45 // thrown when assert fails in debug build
46 class TestAssertFailure
47 {
48 public:
49 TestAssertFailure(const wxString& file,
50 int line,
51 const wxString& func,
52 const wxString& cond,
53 const wxString& msg)
54 : m_file(file),
55 m_line(line),
56 m_func(func),
57 m_cond(cond),
58 m_msg(msg)
59 {
60 }
61
62 const wxString m_file;
63 const int m_line;
64 const wxString m_func;
65 const wxString m_cond;
66 const wxString m_msg;
67
68 wxDECLARE_NO_ASSIGN_CLASS(TestAssertFailure);
69 };
70
71 // macro to use for the functions which are supposed to fail an assertion
72 #if wxDEBUG_LEVEL
73 // some old cppunit versions don't define CPPUNIT_ASSERT_THROW so roll our
74 // own
75 #define WX_ASSERT_FAILS_WITH_ASSERT(cond) \
76 { \
77 bool throwsAssert = false; \
78 try { cond ; } \
79 catch ( const TestAssertFailure& ) { throwsAssert = true; } \
80 if ( !throwsAssert ) \
81 CPPUNIT_FAIL("expected assertion not generated"); \
82 }
83 #else
84 // there are no assertions in this build so just check that it fails
85 #define WX_ASSERT_FAILS_WITH_ASSERT(cond) CPPUNIT_ASSERT(!(cond))
86 #endif
87
88 // these functions can be used to hook into wxApp event processing and are
89 // currently used by the events propagation test
90 class WXDLLIMPEXP_FWD_BASE wxEvent;
91
92 typedef int (*FilterEventFunc)(wxEvent&);
93 typedef bool (*ProcessEventFunc)(wxEvent&);
94
95 extern void SetFilterEventFunc(FilterEventFunc func);
96 extern void SetProcessEventFunc(ProcessEventFunc func);
97
98 extern bool IsNetworkAvailable();
99
100 // Helper class setting the locale to the given one for its lifetime.
101 class LocaleSetter
102 {
103 public:
104 LocaleSetter(const char *loc) : m_locOld(setlocale(LC_ALL, loc)) { }
105 ~LocaleSetter() { setlocale(LC_ALL, m_locOld); }
106
107 private:
108 const char * const m_locOld;
109
110 wxDECLARE_NO_COPY_CLASS(LocaleSetter);
111 };
112
113 // An even simpler helper for setting the locale to "C" one during its lifetime.
114 class CLocaleSetter : private LocaleSetter
115 {
116 public:
117 CLocaleSetter() : LocaleSetter("C") { }
118
119 private:
120 wxDECLARE_NO_COPY_CLASS(CLocaleSetter);
121 };
122
123 // Macro that can be used to register the test with the given name in both the
124 // global unnamed registry so that it is ran by default and a registry with the
125 // same name as this test to allow running just this test individually.
126 //
127 // Notice that the name shouldn't include the "TestCase" suffix, it's added
128 // automatically by this macro.
129 //
130 // Implementation note: CPPUNIT_TEST_SUITE_[NAMED_]REGISTRATION macros can't be
131 // used here because they both declare the variable with the same name (as the
132 // "unique" name they generate is based on the line number which is the same
133 // for both calls inside the macro), so we need to do it manually.
134 #define wxREGISTER_UNIT_TEST(name) \
135 static CPPUNIT_NS::AutoRegisterSuite< name##TestCase > \
136 CPPUNIT_MAKE_UNIQUE_NAME( autoRegisterRegistry__ ); \
137 static CPPUNIT_NS::AutoRegisterSuite< name##TestCase > \
138 CPPUNIT_MAKE_UNIQUE_NAME( autoRegisterNamedRegistry__ )(#name "TestCase")