]>
Commit | Line | Data |
---|---|---|
031b101f VZ |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: tests/events/clone.cpp | |
3 | // Purpose: Test wxEvent::Clone() implementation by all event classes | |
4 | // Author: Vadim Zeitlin, based on the code by Francesco Montorsi | |
5 | // Created: 2009-03-22 | |
031b101f VZ |
6 | // Copyright: (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org> |
7 | /////////////////////////////////////////////////////////////////////////////// | |
8 | ||
9 | // ---------------------------------------------------------------------------- | |
10 | // headers | |
11 | // ---------------------------------------------------------------------------- | |
12 | ||
13 | #include "testprec.h" | |
14 | ||
15 | #ifdef __BORLANDC__ | |
16 | #pragma hdrstop | |
17 | #endif | |
18 | ||
19 | #ifndef WX_PRECOMP | |
20 | #include "wx/event.h" | |
21 | #endif // WX_PRECOMP | |
22 | ||
23 | // -------------------------------------------------------------------------- | |
24 | // test class | |
25 | // -------------------------------------------------------------------------- | |
26 | ||
27 | class EventCloneTestCase : public CppUnit::TestCase | |
28 | { | |
29 | public: | |
30 | EventCloneTestCase() {} | |
31 | ||
32 | private: | |
33 | CPPUNIT_TEST_SUITE( EventCloneTestCase ); | |
34 | CPPUNIT_TEST( CheckAll ); | |
35 | CPPUNIT_TEST_SUITE_END(); | |
36 | ||
37 | void CheckAll(); | |
38 | ||
39 | DECLARE_NO_COPY_CLASS(EventCloneTestCase) | |
40 | }; | |
41 | ||
42 | // register in the unnamed registry so that these tests are run by default | |
43 | CPPUNIT_TEST_SUITE_REGISTRATION( EventCloneTestCase ); | |
44 | ||
e3778b4d | 45 | // also include in its own registry so that these tests can be run alone |
031b101f VZ |
46 | CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( EventCloneTestCase, "EventCloneTestCase" ); |
47 | ||
48 | void EventCloneTestCase::CheckAll() | |
49 | { | |
50 | // check if event classes implement Clone() correctly | |
51 | // NOTE: the check is done against _all_ event classes which are linked to | |
52 | // the executable currently running, which are not necessarily all | |
53 | // wxWidgets event classes. | |
54 | const wxClassInfo *ci = wxClassInfo::GetFirst(); | |
55 | for (; ci; ci = ci->GetNext()) | |
56 | { | |
2026b433 FM |
57 | wxString cn = wxString(ci->GetClassName()); |
58 | ||
031b101f VZ |
59 | // is this class derived from wxEvent? |
60 | if ( !ci->IsKindOf(CLASSINFO(wxEvent)) || | |
2026b433 | 61 | cn == "wxEvent" ) |
031b101f VZ |
62 | continue; |
63 | ||
64 | const std::string | |
f70cea2b | 65 | msg = std::string("Event class \"") + |
2026b433 | 66 | std::string(cn.c_str()) + "\""; |
031b101f VZ |
67 | |
68 | CPPUNIT_ASSERT_MESSAGE( msg, ci->IsDynamic() ); | |
69 | ||
70 | wxEvent * const test = wxDynamicCast(ci->CreateObject(),wxEvent); | |
71 | CPPUNIT_ASSERT_MESSAGE( msg, test ); | |
72 | ||
73 | wxEvent * const cloned = test->Clone(); | |
74 | delete test; | |
75 | ||
76 | CPPUNIT_ASSERT_MESSAGE( msg, cloned ); | |
77 | CPPUNIT_ASSERT_MESSAGE( msg, cloned->GetClassInfo() == ci ); | |
78 | ||
79 | delete cloned; | |
80 | } | |
81 | } | |
82 |