1 #ifndef WX_TESTPREC_INCLUDED
2 #define WX_TESTPREC_INCLUDED 1
5 #include "wx/cppunit.h"
7 // Custom test macro that is only defined when wxUIActionSimulator is available
8 // this allows the tests that do not rely on it to run on platforms that don't
11 // FIXME: And while OS X does support it, more or less, too many tests
12 // currently fail under it so disable all interactive tests there. They
13 // should, of course, be reenabled a.s.a.p.
14 #if wxUSE_UIACTIONSIMULATOR && !defined(__WXOSX__)
15 #define WXUISIM_TEST(test) CPPUNIT_TEST(test)
17 #define WXUISIM_TEST(test) (void)0
20 // define wxHAVE_U_ESCAPE if the compiler supports \uxxxx character constants
21 #if (defined(__VISUALC__) && (__VISUALC__ >= 1300)) || \
22 (defined(__GNUC__) && (__GNUC__ >= 3))
23 #define wxHAVE_U_ESCAPE
25 // and disable warning that using them results in with MSVC 8+
26 #if wxCHECK_VISUALC_VERSION(8)
27 // universal-character-name encountered in source
28 #pragma warning(disable:4428)
32 // Define wxUSING_VC_CRT_IO when using MSVC CRT STDIO library as its standard
33 // functions give different results from glibc ones in several cases (of
34 // course, any code relying on this is not portable and probably won't work,
35 // i.e. will result in tests failures, with other platforms/compilers which
36 // should have checks for them added as well).
38 // Notice that MinGW uses VC CRT by default but may use its own printf()
39 // implementation if __USE_MINGW_ANSI_STDIO is defined. And finally also notice
40 // that testing for __USE_MINGW_ANSI_STDIO directly results in a warning with
41 // -Wundef if it involves an operation with undefined __MINGW_FEATURES__ so
42 // test for the latter too to avoid it.
43 #if defined(__VISUALC__) || \
44 (defined(__MINGW32__) && \
45 (!defined(__MINGW_FEATURES__) || !__USE_MINGW_ANSI_STDIO))
46 #define wxUSING_VC_CRT_IO
49 // thrown when assert fails in debug build
50 class TestAssertFailure
53 TestAssertFailure(const wxString
& file
,
66 const wxString m_file
;
68 const wxString m_func
;
69 const wxString m_cond
;
72 wxDECLARE_NO_ASSIGN_CLASS(TestAssertFailure
);
75 // macro to use for the functions which are supposed to fail an assertion
77 // some old cppunit versions don't define CPPUNIT_ASSERT_THROW so roll our
79 #define WX_ASSERT_FAILS_WITH_ASSERT(cond) \
81 bool throwsAssert = false; \
83 catch ( const TestAssertFailure& ) { throwsAssert = true; } \
84 if ( !throwsAssert ) \
85 CPPUNIT_FAIL("expected assertion not generated"); \
88 // there are no assertions in this build so just check that it fails
89 #define WX_ASSERT_FAILS_WITH_ASSERT(cond) CPPUNIT_ASSERT(!(cond))
92 // these functions can be used to hook into wxApp event processing and are
93 // currently used by the events propagation test
94 class WXDLLIMPEXP_FWD_BASE wxEvent
;
96 typedef int (*FilterEventFunc
)(wxEvent
&);
97 typedef bool (*ProcessEventFunc
)(wxEvent
&);
99 extern void SetFilterEventFunc(FilterEventFunc func
);
100 extern void SetProcessEventFunc(ProcessEventFunc func
);
102 extern bool IsNetworkAvailable();
104 // Helper class setting the locale to the given one for its lifetime.
108 LocaleSetter(const char *loc
) : m_locOld(setlocale(LC_ALL
, loc
)) { }
109 ~LocaleSetter() { setlocale(LC_ALL
, m_locOld
); }
112 const char * const m_locOld
;
114 wxDECLARE_NO_COPY_CLASS(LocaleSetter
);
117 // An even simpler helper for setting the locale to "C" one during its lifetime.
118 class CLocaleSetter
: private LocaleSetter
121 CLocaleSetter() : LocaleSetter("C") { }
124 wxDECLARE_NO_COPY_CLASS(CLocaleSetter
);
127 // Macro that can be used to register the test with the given name in both the
128 // global unnamed registry so that it is ran by default and a registry with the
129 // same name as this test to allow running just this test individually.
131 // Notice that the name shouldn't include the "TestCase" suffix, it's added
132 // automatically by this macro.
134 // Implementation note: CPPUNIT_TEST_SUITE_[NAMED_]REGISTRATION macros can't be
135 // used here because they both declare the variable with the same name (as the
136 // "unique" name they generate is based on the line number which is the same
137 // for both calls inside the macro), so we need to do it manually.
138 #define wxREGISTER_UNIT_TEST(name) \
139 static CPPUNIT_NS::AutoRegisterSuite< name##TestCase > \
140 CPPUNIT_MAKE_UNIQUE_NAME( autoRegisterRegistry__ ); \
141 static CPPUNIT_NS::AutoRegisterSuite< name##TestCase > \
142 CPPUNIT_MAKE_UNIQUE_NAME( autoRegisterNamedRegistry__ )(#name "TestCase")