]>
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
6 // Copyright: (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org>
7 ///////////////////////////////////////////////////////////////////////////////
9 // ----------------------------------------------------------------------------
11 // ----------------------------------------------------------------------------
23 // --------------------------------------------------------------------------
25 // --------------------------------------------------------------------------
27 class EventCloneTestCase
: public CppUnit::TestCase
30 EventCloneTestCase() {}
33 CPPUNIT_TEST_SUITE( EventCloneTestCase
);
34 CPPUNIT_TEST( CheckAll
);
35 CPPUNIT_TEST_SUITE_END();
39 DECLARE_NO_COPY_CLASS(EventCloneTestCase
)
42 // register in the unnamed registry so that these tests are run by default
43 CPPUNIT_TEST_SUITE_REGISTRATION( EventCloneTestCase
);
45 // also include in its own registry so that these tests can be run alone
46 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( EventCloneTestCase
, "EventCloneTestCase" );
48 void EventCloneTestCase::CheckAll()
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())
57 wxString cn
= wxString(ci
->GetClassName());
59 // is this class derived from wxEvent?
60 if ( !ci
->IsKindOf(CLASSINFO(wxEvent
)) ||
65 msg
= std::string("Event class \"") +
66 std::string(cn
.c_str()) + "\"";
68 CPPUNIT_ASSERT_MESSAGE( msg
, ci
->IsDynamic() );
70 wxEvent
* const test
= wxDynamicCast(ci
->CreateObject(),wxEvent
);
71 CPPUNIT_ASSERT_MESSAGE( msg
, test
);
73 wxEvent
* const cloned
= test
->Clone();
76 CPPUNIT_ASSERT_MESSAGE( msg
, cloned
);
77 CPPUNIT_ASSERT_MESSAGE( msg
, cloned
->GetClassInfo() == ci
);