]> git.saurik.com Git - wxWidgets.git/blob - tests/testprec.h
Correct handling of %hs and %ls in our wxPrintf() implementation.
[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 // thrown when assert fails in debug build
30 class TestAssertFailure
31 {
32 public:
33 TestAssertFailure(const wxString& file,
34 int line,
35 const wxString& func,
36 const wxString& cond,
37 const wxString& msg)
38 : m_file(file),
39 m_line(line),
40 m_func(func),
41 m_cond(cond),
42 m_msg(msg)
43 {
44 }
45
46 const wxString m_file;
47 const int m_line;
48 const wxString m_func;
49 const wxString m_cond;
50 const wxString m_msg;
51
52 wxDECLARE_NO_ASSIGN_CLASS(TestAssertFailure);
53 };
54
55 // macro to use for the functions which are supposed to fail an assertion
56 #if wxDEBUG_LEVEL
57 // some old cppunit versions don't define CPPUNIT_ASSERT_THROW so roll our
58 // own
59 #define WX_ASSERT_FAILS_WITH_ASSERT(cond) \
60 { \
61 bool throwsAssert = false; \
62 try { cond ; } \
63 catch ( const TestAssertFailure& ) { throwsAssert = true; } \
64 if ( !throwsAssert ) \
65 CPPUNIT_FAIL("expected assertion not generated"); \
66 }
67 #else
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))
70 #endif
71
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;
75
76 typedef int (*FilterEventFunc)(wxEvent&);
77 typedef bool (*ProcessEventFunc)(wxEvent&);
78
79 extern void SetFilterEventFunc(FilterEventFunc func);
80 extern void SetProcessEventFunc(ProcessEventFunc func);
81
82 extern bool IsNetworkAvailable();
83
84 // helper class setting the locale to "C" for its lifetime
85 class CLocaleSetter
86 {
87 public:
88 CLocaleSetter() : m_locOld(setlocale(LC_ALL, "C")) { }
89 ~CLocaleSetter() { setlocale(LC_ALL, m_locOld); }
90
91 private:
92 const char * const m_locOld;
93 wxDECLARE_NO_COPY_CLASS(CLocaleSetter);
94 };
95
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.
99 //
100 // Notice that the name shouldn't include the "TestCase" suffix, it's added
101 // automatically by this macro.
102 //
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")