]> git.saurik.com Git - wxWidgets.git/blame - tests/testprec.h
Implement hatched/stippled pens/brushes in wxGraphicsContext for Cairo.
[wxWidgets.git] / tests / testprec.h
CommitLineData
38e54405
JJ
1#ifndef WX_TESTPREC_INCLUDED
2#define WX_TESTPREC_INCLUDED 1
3
8899b155 4#include "wx/wxprec.h"
1e0b0d7c
SL
5#include "wx/stopwatch.h"
6#include "wx/evtloop.h"
8899b155 7#include "wx/cppunit.h"
8da7a00a 8
232fdc63
VZ
9// Custom test macro that is only defined when wxUIActionSimulator is available
10// this allows the tests that do not rely on it to run on platforms that don't
11// support it.
12//
13// FIXME: And while OS X does support it, more or less, too many tests
14// currently fail under it so disable all interactive tests there. They
15// should, of course, be reenabled a.s.a.p.
16#if wxUSE_UIACTIONSIMULATOR && !defined(__WXOSX__)
17 #define WXUISIM_TEST(test) CPPUNIT_TEST(test)
18#else
19 #define WXUISIM_TEST(test) (void)0
20#endif
21
8da7a00a
VZ
22// define wxHAVE_U_ESCAPE if the compiler supports \uxxxx character constants
23#if (defined(__VISUALC__) && (__VISUALC__ >= 1300)) || \
24 (defined(__GNUC__) && (__GNUC__ >= 3))
25 #define wxHAVE_U_ESCAPE
a8f17758
VZ
26
27 // and disable warning that using them results in with MSVC 8+
28 #if wxCHECK_VISUALC_VERSION(8)
29 // universal-character-name encountered in source
30 #pragma warning(disable:4428)
31 #endif
8da7a00a 32#endif
0468a58a 33
43f8864b
VZ
34// Define wxUSING_VC_CRT_IO when using MSVC CRT STDIO library as its standard
35// functions give different results from glibc ones in several cases (of
36// course, any code relying on this is not portable and probably won't work,
37// i.e. will result in tests failures, with other platforms/compilers which
38// should have checks for them added as well).
39//
40// Notice that MinGW uses VC CRT by default but may use its own printf()
41// implementation if __USE_MINGW_ANSI_STDIO is defined. And finally also notice
42// that testing for __USE_MINGW_ANSI_STDIO directly results in a warning with
43// -Wundef if it involves an operation with undefined __MINGW_FEATURES__ so
44// test for the latter too to avoid it.
45#if defined(__VISUALC__) || \
c4cb46c1
VZ
46 (defined(__MINGW32__) && \
47 (!defined(__MINGW_FEATURES__) || !__USE_MINGW_ANSI_STDIO))
43f8864b
VZ
48 #define wxUSING_VC_CRT_IO
49#endif
50
0468a58a 51// thrown when assert fails in debug build
b33e98f0
VZ
52class TestAssertFailure
53{
54public:
55 TestAssertFailure(const wxString& file,
56 int line,
57 const wxString& func,
58 const wxString& cond,
59 const wxString& msg)
60 : m_file(file),
61 m_line(line),
62 m_func(func),
63 m_cond(cond),
64 m_msg(msg)
65 {
66 }
67
68 const wxString m_file;
69 const int m_line;
70 const wxString m_func;
71 const wxString m_cond;
72 const wxString m_msg;
73
74 wxDECLARE_NO_ASSIGN_CLASS(TestAssertFailure);
75};
0468a58a
VZ
76
77// macro to use for the functions which are supposed to fail an assertion
657a8a35 78#if wxDEBUG_LEVEL
0468a58a
VZ
79 // some old cppunit versions don't define CPPUNIT_ASSERT_THROW so roll our
80 // own
81 #define WX_ASSERT_FAILS_WITH_ASSERT(cond) \
82 { \
83 bool throwsAssert = false; \
84 try { cond ; } \
85 catch ( const TestAssertFailure& ) { throwsAssert = true; } \
86 if ( !throwsAssert ) \
87 CPPUNIT_FAIL("expected assertion not generated"); \
88 }
89#else
e042c3b5
VZ
90 // there are no assertions in this build so we can't do anything (we used
91 // to check that the condition failed but this didn't work well as in
92 // normal build with wxDEBUG_LEVEL != 0 we can pass something not
93 // evaluating to a bool at all but it then would fail to compile in
94 // wxDEBUG_LEVEL == 0 case, so just don't do anything at all now).
95 #define WX_ASSERT_FAILS_WITH_ASSERT(cond)
0468a58a
VZ
96#endif
97
1e0b0d7c
SL
98#define WX_ASSERT_EVENT_OCCURS(eventcounter, count) \
99{\
100 wxStopWatch sw; \
101 wxEventLoopBase* loop = wxEventLoopBase::GetActive(); \
102 while(eventcounter.GetCount() < count) \
103 { \
104 if(sw.Time() < 100) \
105 loop->Dispatch(); \
106 else \
107 { \
108 CPPUNIT_FAIL(wxString::Format("timeout reached with %d " \
109 "events received, %d expected", \
110 eventcounter.GetCount(), count).ToStdString()); \
111 break; \
112 } \
113 } \
114 eventcounter.Clear(); \
115}
116
1649d288
VZ
117// these functions can be used to hook into wxApp event processing and are
118// currently used by the events propagation test
9eab6725
VZ
119class WXDLLIMPEXP_FWD_BASE wxEvent;
120
1649d288
VZ
121typedef int (*FilterEventFunc)(wxEvent&);
122typedef bool (*ProcessEventFunc)(wxEvent&);
123
124extern void SetFilterEventFunc(FilterEventFunc func);
125extern void SetProcessEventFunc(ProcessEventFunc func);
1f51673b
FM
126
127extern bool IsNetworkAvailable();
701aa4d8 128
f1287154
VZ
129extern bool IsAutomaticTest();
130
12249b19
VZ
131// Helper class setting the locale to the given one for its lifetime.
132class LocaleSetter
701aa4d8
FM
133{
134public:
12249b19
VZ
135 LocaleSetter(const char *loc) : m_locOld(setlocale(LC_ALL, loc)) { }
136 ~LocaleSetter() { setlocale(LC_ALL, m_locOld); }
701aa4d8
FM
137
138private:
139 const char * const m_locOld;
12249b19
VZ
140
141 wxDECLARE_NO_COPY_CLASS(LocaleSetter);
142};
143
144// An even simpler helper for setting the locale to "C" one during its lifetime.
145class CLocaleSetter : private LocaleSetter
146{
147public:
148 CLocaleSetter() : LocaleSetter("C") { }
149
150private:
701aa4d8
FM
151 wxDECLARE_NO_COPY_CLASS(CLocaleSetter);
152};
8cdd00f2
VZ
153
154// Macro that can be used to register the test with the given name in both the
155// global unnamed registry so that it is ran by default and a registry with the
156// same name as this test to allow running just this test individually.
157//
158// Notice that the name shouldn't include the "TestCase" suffix, it's added
159// automatically by this macro.
160//
161// Implementation note: CPPUNIT_TEST_SUITE_[NAMED_]REGISTRATION macros can't be
162// used here because they both declare the variable with the same name (as the
163// "unique" name they generate is based on the line number which is the same
164// for both calls inside the macro), so we need to do it manually.
165#define wxREGISTER_UNIT_TEST(name) \
166 static CPPUNIT_NS::AutoRegisterSuite< name##TestCase > \
167 CPPUNIT_MAKE_UNIQUE_NAME( autoRegisterRegistry__ ); \
168 static CPPUNIT_NS::AutoRegisterSuite< name##TestCase > \
169 CPPUNIT_MAKE_UNIQUE_NAME( autoRegisterNamedRegistry__ )(#name "TestCase")
38e54405
JJ
170
171#endif