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 // thrown when assert fails in debug build
30 class TestAssertFailure
33 TestAssertFailure(const wxString
& file
,
46 const wxString m_file
;
48 const wxString m_func
;
49 const wxString m_cond
;
52 wxDECLARE_NO_ASSIGN_CLASS(TestAssertFailure
);
55 // macro to use for the functions which are supposed to fail an assertion
57 // some old cppunit versions don't define CPPUNIT_ASSERT_THROW so roll our
59 #define WX_ASSERT_FAILS_WITH_ASSERT(cond) \
61 bool throwsAssert = false; \
63 catch ( const TestAssertFailure& ) { throwsAssert = true; } \
64 if ( !throwsAssert ) \
65 CPPUNIT_FAIL("expected assertion not generated"); \
68 // there are no assertions in this build so just check that it fails
69 #define WX_ASSERT_FAILS_WITH_ASSERT(cond) CPPUNIT_ASSERT(!(cond))
72 // these functions can be used to hook into wxApp event processing and are
73 // currently used by the events propagation test
74 class WXDLLIMPEXP_FWD_BASE wxEvent
;
76 typedef int (*FilterEventFunc
)(wxEvent
&);
77 typedef bool (*ProcessEventFunc
)(wxEvent
&);
79 extern void SetFilterEventFunc(FilterEventFunc func
);
80 extern void SetProcessEventFunc(ProcessEventFunc func
);
82 extern bool IsNetworkAvailable();
84 // helper class setting the locale to "C" for its lifetime
88 CLocaleSetter() : m_locOld(setlocale(LC_ALL
, "C")) { }
89 ~CLocaleSetter() { setlocale(LC_ALL
, m_locOld
); }
92 const char * const m_locOld
;
93 wxDECLARE_NO_COPY_CLASS(CLocaleSetter
);
96 // Macro that can be used to register the test with the given name in both the
97 // global unnamed registry so that it is ran by default and a registry with the
98 // same name as this test to allow running just this test individually.
100 // Notice that the name shouldn't include the "TestCase" suffix, it's added
101 // automatically by this macro.
103 // Implementation note: CPPUNIT_TEST_SUITE_[NAMED_]REGISTRATION macros can't be
104 // used here because they both declare the variable with the same name (as the
105 // "unique" name they generate is based on the line number which is the same
106 // for both calls inside the macro), so we need to do it manually.
107 #define wxREGISTER_UNIT_TEST(name) \
108 static CPPUNIT_NS::AutoRegisterSuite< name##TestCase > \
109 CPPUNIT_MAKE_UNIQUE_NAME( autoRegisterRegistry__ ); \
110 static CPPUNIT_NS::AutoRegisterSuite< name##TestCase > \
111 CPPUNIT_MAKE_UNIQUE_NAME( autoRegisterNamedRegistry__ )(#name "TestCase")