]> git.saurik.com Git - wxWidgets.git/blobdiff - tests/events/evthandler.cpp
Applied patch #15540: wxRichTextTable: crashes due to an invalid focus object (dghart)
[wxWidgets.git] / tests / events / evthandler.cpp
index 0f49b1a1791ba2ac8c8d7627e93622a350aee86c..1496f4c196d7e7e71fde16c836dd9b65330fb3a0 100644 (file)
@@ -3,7 +3,6 @@
 // Purpose:     Test the new event types and wxEvtHandler-methods
 // Author:      Peter Most
 // Created:     2009-01-24
-// RCS-ID:      $Id$
 // Copyright:   (c) 2009 Peter Most
 ///////////////////////////////////////////////////////////////////////////////
 
@@ -80,7 +79,9 @@ void GlobalOnEvent(wxEvent&)
     g_called.function = true;
 }
 
+#ifdef TEST_INVALID_BIND_GLOBAL
 void GlobalOnAnotherEvent(AnotherEvent&);
+#endif
 
 void GlobalOnIdle(wxIdleEvent&)
 {
@@ -160,6 +161,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 +177,8 @@ private:
 
     void BuiltinConnect();
     void LegacyConnect();
+    void DisconnectWildcard();
+    void AutoDisconnect();
 #ifdef wxHAS_EVENT_BIND
     void BindFunction();
     void BindStaticMethod();
@@ -197,7 +202,7 @@ private:
 // register in the unnamed registry so that these tests are run by default
 CPPUNIT_TEST_SUITE_REGISTRATION( EvtHandlerTestCase );
 
-// also include in it's own registry so that these tests can be run alone
+// also include in its own registry so that these tests can be run alone
 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( EvtHandlerTestCase, "EvtHandlerTestCase" );
 
 void EvtHandlerTestCase::BuiltinConnect()
@@ -249,6 +254,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()
@@ -309,6 +339,19 @@ void EvtHandlerTestCase::BindFunctor()
 
     handler.Bind( MyEventType, functor, 0, 0 );
     handler.Unbind( MyEventType, functor, 0, 0 );
+
+    // test that a temporary functor is working as well and also test that
+    // unbinding a different (though equal) instance of the same functor does
+    // not work
+    MyFunctor func;
+    handler.Bind( MyEventType, MyFunctor() );
+    CPPUNIT_ASSERT( !handler.Unbind( MyEventType, func ));
+
+    handler.Bind( MyEventType, MyFunctor(), 0 );
+    CPPUNIT_ASSERT( !handler.Unbind( MyEventType, func, 0 ));
+
+    handler.Bind( MyEventType, MyFunctor(), 0, 0 );
+    CPPUNIT_ASSERT( !handler.Unbind( MyEventType, func, 0, 0 ));
 }
 
 void EvtHandlerTestCase::BindMethod()