Merge branch 'timerevent-no-def-ctor'
Remove wxTimerEvent default constructor. See https://github.com/wxWidgets/wxWidgets/pull/1409
This commit is contained in:
@@ -159,26 +159,23 @@ private:
|
|||||||
class WXDLLIMPEXP_BASE wxTimerEvent : public wxEvent
|
class WXDLLIMPEXP_BASE wxTimerEvent : public wxEvent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
wxTimerEvent()
|
|
||||||
: wxEvent(wxID_ANY, wxEVT_TIMER) { m_timer=NULL; }
|
|
||||||
|
|
||||||
wxTimerEvent(wxTimer& timer)
|
wxTimerEvent(wxTimer& timer)
|
||||||
: wxEvent(timer.GetId(), wxEVT_TIMER),
|
: wxEvent(timer.GetId(), wxEVT_TIMER),
|
||||||
m_timer(&timer)
|
m_timer(timer)
|
||||||
{
|
{
|
||||||
SetEventObject(timer.GetOwner());
|
SetEventObject(timer.GetOwner());
|
||||||
}
|
}
|
||||||
|
|
||||||
// accessors
|
// accessors
|
||||||
int GetInterval() const { return m_timer->GetInterval(); }
|
int GetInterval() const { return m_timer.GetInterval(); }
|
||||||
wxTimer& GetTimer() const { return *m_timer; }
|
wxTimer& GetTimer() const { return m_timer; }
|
||||||
|
|
||||||
// implement the base class pure virtual
|
// implement the base class pure virtual
|
||||||
virtual wxEvent *Clone() const wxOVERRIDE { return new wxTimerEvent(*this); }
|
virtual wxEvent *Clone() const wxOVERRIDE { return new wxTimerEvent(*this); }
|
||||||
virtual wxEventCategory GetEventCategory() const wxOVERRIDE { return wxEVT_CATEGORY_TIMER; }
|
virtual wxEventCategory GetEventCategory() const wxOVERRIDE { return wxEVT_CATEGORY_TIMER; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
wxTimer* m_timer;
|
wxTimer& m_timer;
|
||||||
|
|
||||||
wxDECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxTimerEvent);
|
wxDECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxTimerEvent);
|
||||||
};
|
};
|
||||||
|
@@ -38,7 +38,9 @@
|
|||||||
// wxWin macros
|
// wxWin macros
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
wxIMPLEMENT_DYNAMIC_CLASS(wxTimerEvent, wxEvent);
|
// This class is not really abstract, but this macro has to be used because it
|
||||||
|
// doesn't have a default ctor.
|
||||||
|
wxIMPLEMENT_ABSTRACT_CLASS(wxTimerEvent, wxEvent);
|
||||||
|
|
||||||
wxDEFINE_EVENT(wxEVT_TIMER, wxTimerEvent);
|
wxDEFINE_EVENT(wxEVT_TIMER, wxTimerEvent);
|
||||||
|
|
||||||
|
@@ -18,35 +18,14 @@
|
|||||||
|
|
||||||
#ifndef WX_PRECOMP
|
#ifndef WX_PRECOMP
|
||||||
#include "wx/event.h"
|
#include "wx/event.h"
|
||||||
|
#include "wx/timer.h"
|
||||||
#endif // WX_PRECOMP
|
#endif // WX_PRECOMP
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
TEST_CASE("EventClone", "[wxEvent][clone]")
|
||||||
// test class
|
|
||||||
// --------------------------------------------------------------------------
|
|
||||||
|
|
||||||
class EventCloneTestCase : public CppUnit::TestCase
|
|
||||||
{
|
{
|
||||||
public:
|
// Dummy timer needed just to create a wxTimerEvent.
|
||||||
EventCloneTestCase() {}
|
wxTimer dummyTimer;
|
||||||
|
|
||||||
private:
|
|
||||||
CPPUNIT_TEST_SUITE( EventCloneTestCase );
|
|
||||||
CPPUNIT_TEST( CheckAll );
|
|
||||||
CPPUNIT_TEST_SUITE_END();
|
|
||||||
|
|
||||||
void CheckAll();
|
|
||||||
|
|
||||||
wxDECLARE_NO_COPY_CLASS(EventCloneTestCase);
|
|
||||||
};
|
|
||||||
|
|
||||||
// register in the unnamed registry so that these tests are run by default
|
|
||||||
CPPUNIT_TEST_SUITE_REGISTRATION( EventCloneTestCase );
|
|
||||||
|
|
||||||
// also include in its own registry so that these tests can be run alone
|
|
||||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( EventCloneTestCase, "EventCloneTestCase" );
|
|
||||||
|
|
||||||
void EventCloneTestCase::CheckAll()
|
|
||||||
{
|
|
||||||
// check if event classes implement Clone() correctly
|
// check if event classes implement Clone() correctly
|
||||||
// NOTE: the check is done against _all_ event classes which are linked to
|
// NOTE: the check is done against _all_ event classes which are linked to
|
||||||
// the executable currently running, which are not necessarily all
|
// the executable currently running, which are not necessarily all
|
||||||
@@ -61,20 +40,30 @@ void EventCloneTestCase::CheckAll()
|
|||||||
cn == "wxEvent" )
|
cn == "wxEvent" )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const std::string
|
INFO("Event class \"" << cn << "\"");
|
||||||
msg = std::string("Event class \"") +
|
|
||||||
std::string(cn.c_str()) + "\"";
|
|
||||||
|
|
||||||
CPPUNIT_ASSERT_MESSAGE( msg, ci->IsDynamic() );
|
wxEvent* test;
|
||||||
|
if ( ci->IsDynamic() )
|
||||||
|
{
|
||||||
|
test = wxDynamicCast(ci->CreateObject(),wxEvent);
|
||||||
|
}
|
||||||
|
else if ( cn == "wxTimerEvent" )
|
||||||
|
{
|
||||||
|
test = new wxTimerEvent(dummyTimer);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
FAIL("Can't create objects of type " + cn);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
wxEvent * const test = wxDynamicCast(ci->CreateObject(),wxEvent);
|
REQUIRE( test );
|
||||||
CPPUNIT_ASSERT_MESSAGE( msg, test );
|
|
||||||
|
|
||||||
wxEvent * const cloned = test->Clone();
|
wxEvent * const cloned = test->Clone();
|
||||||
delete test;
|
delete test;
|
||||||
|
|
||||||
CPPUNIT_ASSERT_MESSAGE( msg, cloned );
|
REQUIRE( cloned );
|
||||||
CPPUNIT_ASSERT_MESSAGE( msg, cloned->GetClassInfo() == ci );
|
CHECK( cloned->GetClassInfo() == ci );
|
||||||
|
|
||||||
delete cloned;
|
delete cloned;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user