]>
git.saurik.com Git - wxWidgets.git/blob - 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
7 // Copyright: (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org>
8 ///////////////////////////////////////////////////////////////////////////////
10 // ----------------------------------------------------------------------------
12 // ----------------------------------------------------------------------------
24 // --------------------------------------------------------------------------
26 // --------------------------------------------------------------------------
28 class EventCloneTestCase
: public CppUnit::TestCase
31 EventCloneTestCase() {}
34 CPPUNIT_TEST_SUITE( EventCloneTestCase
);
35 CPPUNIT_TEST( CheckAll
);
36 CPPUNIT_TEST_SUITE_END();
40 DECLARE_NO_COPY_CLASS(EventCloneTestCase
)
43 // register in the unnamed registry so that these tests are run by default
44 CPPUNIT_TEST_SUITE_REGISTRATION( EventCloneTestCase
);
46 // also include in it's own registry so that these tests can be run alone
47 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( EventCloneTestCase
, "EventCloneTestCase" );
49 void EventCloneTestCase::CheckAll()
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())
58 wxString cn
= wxString(ci
->GetClassName());
60 // is this class derived from wxEvent?
61 if ( !ci
->IsKindOf(CLASSINFO(wxEvent
)) ||
66 msg
= std::string("Event class \"") +
67 std::string(cn
.c_str()) + "\"";
69 CPPUNIT_ASSERT_MESSAGE( msg
, ci
->IsDynamic() );
71 wxEvent
* const test
= wxDynamicCast(ci
->CreateObject(),wxEvent
);
72 CPPUNIT_ASSERT_MESSAGE( msg
, test
);
74 wxEvent
* const cloned
= test
->Clone();
77 CPPUNIT_ASSERT_MESSAGE( msg
, cloned
);
78 CPPUNIT_ASSERT_MESSAGE( msg
, cloned
->GetClassInfo() == ci
);