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