]> git.saurik.com Git - wxWidgets.git/blame_incremental - tests/events/clone.cpp
using ordinary Show for popup windows as on MSW which activates it as well, I'll...
[wxWidgets.git] / tests / events / clone.cpp
... / ...
CommitLineData
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
28class EventCloneTestCase : public CppUnit::TestCase
29{
30public:
31 EventCloneTestCase() {}
32
33private:
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
44CPPUNIT_TEST_SUITE_REGISTRATION( EventCloneTestCase );
45
46// also include in its own registry so that these tests can be run alone
47CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( EventCloneTestCase, "EventCloneTestCase" );
48
49void 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 wxString cn = wxString(ci->GetClassName());
59
60 // is this class derived from wxEvent?
61 if ( !ci->IsKindOf(CLASSINFO(wxEvent)) ||
62 cn == "wxEvent" )
63 continue;
64
65 const std::string
66 msg = std::string("Event class \"") +
67 std::string(cn.c_str()) + "\"";
68
69 CPPUNIT_ASSERT_MESSAGE( msg, ci->IsDynamic() );
70
71 wxEvent * const test = wxDynamicCast(ci->CreateObject(),wxEvent);
72 CPPUNIT_ASSERT_MESSAGE( msg, test );
73
74 wxEvent * const cloned = test->Clone();
75 delete test;
76
77 CPPUNIT_ASSERT_MESSAGE( msg, cloned );
78 CPPUNIT_ASSERT_MESSAGE( msg, cloned->GetClassInfo() == ci );
79
80 delete cloned;
81 }
82}
83