2 #include "wx/cppunit.h"
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
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)
14 #define WXUISIM_TEST(test) (void)0
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
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)
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).
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
46 // thrown when assert fails in debug build
47 class TestAssertFailure
50 TestAssertFailure(const wxString
& file
,
63 const wxString m_file
;
65 const wxString m_func
;
66 const wxString m_cond
;
69 wxDECLARE_NO_ASSIGN_CLASS(TestAssertFailure
);
72 // macro to use for the functions which are supposed to fail an assertion
74 // some old cppunit versions don't define CPPUNIT_ASSERT_THROW so roll our
76 #define WX_ASSERT_FAILS_WITH_ASSERT(cond) \
78 bool throwsAssert = false; \
80 catch ( const TestAssertFailure& ) { throwsAssert = true; } \
81 if ( !throwsAssert ) \
82 CPPUNIT_FAIL("expected assertion not generated"); \
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))
89 // these functions can be used to hook into wxApp event processing and are
90 // currently used by the events propagation test
91 class WXDLLIMPEXP_FWD_BASE wxEvent
;
93 typedef int (*FilterEventFunc
)(wxEvent
&);
94 typedef bool (*ProcessEventFunc
)(wxEvent
&);
96 extern void SetFilterEventFunc(FilterEventFunc func
);
97 extern void SetProcessEventFunc(ProcessEventFunc func
);
99 extern bool IsNetworkAvailable();
101 // Helper class setting the locale to the given one for its lifetime.
105 LocaleSetter(const char *loc
) : m_locOld(setlocale(LC_ALL
, loc
)) { }
106 ~LocaleSetter() { setlocale(LC_ALL
, m_locOld
); }
109 const char * const m_locOld
;
111 wxDECLARE_NO_COPY_CLASS(LocaleSetter
);
114 // An even simpler helper for setting the locale to "C" one during its lifetime.
115 class CLocaleSetter
: private LocaleSetter
118 CLocaleSetter() : LocaleSetter("C") { }
121 wxDECLARE_NO_COPY_CLASS(CLocaleSetter
);
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.
128 // Notice that the name shouldn't include the "TestCase" suffix, it's added
129 // automatically by this macro.
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")