]>
git.saurik.com Git - wxWidgets.git/blob - tests/events/clone.cpp
23998fb587e443a745b24bc87fab200a7a872688
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 // is this class derived from wxEvent?
59 if ( !ci
->IsKindOf(CLASSINFO(wxEvent
)) ||
60 wxString(ci
->GetClassName()) == "wxEvent" )
64 msg
= std::string("Event class \"") +
65 std::string(ci
->GetClassName().c_str()) + "\"";
67 CPPUNIT_ASSERT_MESSAGE( msg
, ci
->IsDynamic() );
69 wxEvent
* const test
= wxDynamicCast(ci
->CreateObject(),wxEvent
);
70 CPPUNIT_ASSERT_MESSAGE( msg
, test
);
72 wxEvent
* const cloned
= test
->Clone();
75 CPPUNIT_ASSERT_MESSAGE( msg
, cloned
);
76 CPPUNIT_ASSERT_MESSAGE( msg
, cloned
->GetClassInfo() == ci
);