]> git.saurik.com Git - wxWidgets.git/blame - tests/testprec.h
Support for undoable application of custom properties, and customisation of propertie...
[wxWidgets.git] / tests / testprec.h
CommitLineData
38e54405
JJ
1#ifndef WX_TESTPREC_INCLUDED
2#define WX_TESTPREC_INCLUDED 1
3
8899b155
RN
4#include "wx/wxprec.h"
5#include "wx/cppunit.h"
8da7a00a 6
232fdc63
VZ
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
9// support it.
10//
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)
16#else
17 #define WXUISIM_TEST(test) (void)0
18#endif
19
8da7a00a
VZ
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
a8f17758
VZ
24
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)
29 #endif
8da7a00a 30#endif
0468a58a 31
43f8864b
VZ
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).
37//
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__) || \
c4cb46c1
VZ
44 (defined(__MINGW32__) && \
45 (!defined(__MINGW_FEATURES__) || !__USE_MINGW_ANSI_STDIO))
43f8864b
VZ
46 #define wxUSING_VC_CRT_IO
47#endif
48
0468a58a 49// thrown when assert fails in debug build
b33e98f0
VZ
50class TestAssertFailure
51{
52public:
53 TestAssertFailure(const wxString& file,
54 int line,
55 const wxString& func,
56 const wxString& cond,
57 const wxString& msg)
58 : m_file(file),
59 m_line(line),
60 m_func(func),
61 m_cond(cond),
62 m_msg(msg)
63 {
64 }
65
66 const wxString m_file;
67 const int m_line;
68 const wxString m_func;
69 const wxString m_cond;
70 const wxString m_msg;
71
72 wxDECLARE_NO_ASSIGN_CLASS(TestAssertFailure);
73};
0468a58a
VZ
74
75// macro to use for the functions which are supposed to fail an assertion
657a8a35 76#if wxDEBUG_LEVEL
0468a58a
VZ
77 // some old cppunit versions don't define CPPUNIT_ASSERT_THROW so roll our
78 // own
79 #define WX_ASSERT_FAILS_WITH_ASSERT(cond) \
80 { \
81 bool throwsAssert = false; \
82 try { cond ; } \
83 catch ( const TestAssertFailure& ) { throwsAssert = true; } \
84 if ( !throwsAssert ) \
85 CPPUNIT_FAIL("expected assertion not generated"); \
86 }
87#else
e042c3b5
VZ
88 // there are no assertions in this build so we can't do anything (we used
89 // to check that the condition failed but this didn't work well as in
90 // normal build with wxDEBUG_LEVEL != 0 we can pass something not
91 // evaluating to a bool at all but it then would fail to compile in
92 // wxDEBUG_LEVEL == 0 case, so just don't do anything at all now).
93 #define WX_ASSERT_FAILS_WITH_ASSERT(cond)
0468a58a
VZ
94#endif
95
1649d288
VZ
96// these functions can be used to hook into wxApp event processing and are
97// currently used by the events propagation test
9eab6725
VZ
98class WXDLLIMPEXP_FWD_BASE wxEvent;
99
1649d288
VZ
100typedef int (*FilterEventFunc)(wxEvent&);
101typedef bool (*ProcessEventFunc)(wxEvent&);
102
103extern void SetFilterEventFunc(FilterEventFunc func);
104extern void SetProcessEventFunc(ProcessEventFunc func);
1f51673b
FM
105
106extern bool IsNetworkAvailable();
701aa4d8 107
12249b19
VZ
108// Helper class setting the locale to the given one for its lifetime.
109class LocaleSetter
701aa4d8
FM
110{
111public:
12249b19
VZ
112 LocaleSetter(const char *loc) : m_locOld(setlocale(LC_ALL, loc)) { }
113 ~LocaleSetter() { setlocale(LC_ALL, m_locOld); }
701aa4d8
FM
114
115private:
116 const char * const m_locOld;
12249b19
VZ
117
118 wxDECLARE_NO_COPY_CLASS(LocaleSetter);
119};
120
121// An even simpler helper for setting the locale to "C" one during its lifetime.
122class CLocaleSetter : private LocaleSetter
123{
124public:
125 CLocaleSetter() : LocaleSetter("C") { }
126
127private:
701aa4d8
FM
128 wxDECLARE_NO_COPY_CLASS(CLocaleSetter);
129};
8cdd00f2
VZ
130
131// Macro that can be used to register the test with the given name in both the
132// global unnamed registry so that it is ran by default and a registry with the
133// same name as this test to allow running just this test individually.
134//
135// Notice that the name shouldn't include the "TestCase" suffix, it's added
136// automatically by this macro.
137//
138// Implementation note: CPPUNIT_TEST_SUITE_[NAMED_]REGISTRATION macros can't be
139// used here because they both declare the variable with the same name (as the
140// "unique" name they generate is based on the line number which is the same
141// for both calls inside the macro), so we need to do it manually.
142#define wxREGISTER_UNIT_TEST(name) \
143 static CPPUNIT_NS::AutoRegisterSuite< name##TestCase > \
144 CPPUNIT_MAKE_UNIQUE_NAME( autoRegisterRegistry__ ); \
145 static CPPUNIT_NS::AutoRegisterSuite< name##TestCase > \
146 CPPUNIT_MAKE_UNIQUE_NAME( autoRegisterNamedRegistry__ )(#name "TestCase")
38e54405
JJ
147
148#endif