X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e3778b4d9c7eebc39f496a9dd055638e06fb9140..a75faeac6947b2e3913f53cea041a3e4941bdd93:/tests/events/evthandler.cpp diff --git a/tests/events/evthandler.cpp b/tests/events/evthandler.cpp index 2e5d478c7d..d8e24a3438 100644 --- a/tests/events/evthandler.cpp +++ b/tests/events/evthandler.cpp @@ -160,6 +160,8 @@ private: CPPUNIT_TEST_SUITE( EvtHandlerTestCase ); CPPUNIT_TEST( BuiltinConnect ); CPPUNIT_TEST( LegacyConnect ); + CPPUNIT_TEST( DisconnectWildcard ); + CPPUNIT_TEST( AutoDisconnect ); #ifdef wxHAS_EVENT_BIND CPPUNIT_TEST( BindFunction ); CPPUNIT_TEST( BindStaticMethod ); @@ -174,6 +176,8 @@ private: void BuiltinConnect(); void LegacyConnect(); + void DisconnectWildcard(); + void AutoDisconnect(); #ifdef wxHAS_EVENT_BIND void BindFunction(); void BindStaticMethod(); @@ -249,6 +253,31 @@ void EvtHandlerTestCase::LegacyConnect() handler.Disconnect( 0, 0, LegacyEventType, (wxObjectEventFunction)&MyHandler::OnEvent, NULL, &handler ); } +void EvtHandlerTestCase::DisconnectWildcard() +{ + // should be able to disconnect a different handler using "wildcard search" + MyHandler sink; + wxEvtHandler source; + source.Connect(wxEVT_IDLE, wxIdleEventHandler(MyHandler::OnIdle), NULL, &sink); + CPPUNIT_ASSERT(source.Disconnect(wxID_ANY, wxEVT_IDLE)); + // destruction of source and sink here should properly clean up the + // wxEventConnectionRef without crashing +} + +void EvtHandlerTestCase::AutoDisconnect() +{ + wxEvtHandler source; + { + MyHandler sink; + source.Connect(wxEVT_IDLE, wxIdleEventHandler(MyHandler::OnIdle), NULL, &sink); + // mismatched event type, so nothing should be disconnected + CPPUNIT_ASSERT(!source.Disconnect(wxEVT_THREAD, wxIdleEventHandler(MyHandler::OnIdle), NULL, &sink)); + } + // destruction of sink should have automatically disconnected it, so + // there should be nothing to disconnect anymore + CPPUNIT_ASSERT(!source.Disconnect(wxID_ANY, wxEVT_IDLE)); +} + #ifdef wxHAS_EVENT_BIND void EvtHandlerTestCase::BindFunction()