]> git.saurik.com Git - wxWidgets.git/commitdiff
add a unit test for new events (see #10000)
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 1 Feb 2009 22:12:12 +0000 (22:12 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 1 Feb 2009 22:12:12 +0000 (22:12 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@58611 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

tests/Makefile.in
tests/events/evthandler.cpp [new file with mode: 0644]
tests/makefile.bcc
tests/makefile.gcc
tests/makefile.vc
tests/makefile.wat
tests/test.bkl
tests/test_test_gui.dsp
tests/test_vc7_test_gui.vcproj
tests/test_vc8_test_gui.vcproj
tests/test_vc9_test_gui.vcproj

index bf0ba869ec73af01f181262f5e12868bc448c645..0f692c4cce9050b0e8c893cf5631861d1ddda438 100644 (file)
@@ -132,6 +132,7 @@ TEST_GUI_OBJECTS =  \
        test_gui_textentrytest.o \
        test_gui_treectrltest.o \
        test_gui_propagation.o \
+       test_gui_evthandler.o \
        test_gui_rawbmp.o \
        test_gui_htmlwindow.o \
        test_gui_guifuncs.o \
@@ -573,6 +574,9 @@ test_gui_treectrltest.o: $(srcdir)/controls/treectrltest.cpp $(TEST_GUI_ODEP)
 test_gui_propagation.o: $(srcdir)/events/propagation.cpp $(TEST_GUI_ODEP)
        $(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/events/propagation.cpp
 
+test_gui_evthandler.o: $(srcdir)/events/evthandler.cpp $(TEST_GUI_ODEP)
+       $(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/events/evthandler.cpp
+
 test_gui_rawbmp.o: $(srcdir)/image/rawbmp.cpp $(TEST_GUI_ODEP)
        $(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/image/rawbmp.cpp
 
diff --git a/tests/events/evthandler.cpp b/tests/events/evthandler.cpp
new file mode 100644 (file)
index 0000000..b6de473
--- /dev/null
@@ -0,0 +1,188 @@
+///////////////////////////////////////////////////////////////////////////////
+// Name:        tests/events/evthandler.cpp
+// Purpose:     Test the new event types and wxEvtHandler-methods
+// Author:      Peter Most
+// Created:     2009-01-24
+// RCS-ID:      $Id$
+// Copyright:   (c) 2009 Peter Most
+///////////////////////////////////////////////////////////////////////////////
+
+// ----------------------------------------------------------------------------
+// headers
+// ----------------------------------------------------------------------------
+
+#include "testprec.h"
+
+#ifdef __BORLANDC__
+    #pragma hdrstop
+#endif
+
+#ifndef WX_PRECOMP
+#endif // WX_PRECOMP
+
+#include "wx/event.h"
+
+
+// --------------------------------------------------------------------------
+// test class
+// --------------------------------------------------------------------------
+
+class EvtHandlerTestCase : public CppUnit::TestCase
+{
+public:
+    EvtHandlerTestCase() {}
+
+private:
+    CPPUNIT_TEST_SUITE( EvtHandlerTestCase );
+        CPPUNIT_TEST( TestConnectCompilation );
+        CPPUNIT_TEST( TestEventFunctorCompare );
+    CPPUNIT_TEST_SUITE_END();
+
+    void TestConnectCompilation();
+    void TestEventFunctorCompare();
+
+    DECLARE_NO_COPY_CLASS(EvtHandlerTestCase)
+};
+
+// 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
+CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( EvtHandlerTestCase, "EvtHandlerTestCase" );
+
+const wxEventType EVT_LEGACY = wxNewEventType();
+
+class MyEvent : public wxEvent
+{
+};
+
+wxDEFINE_EVENT( EVT_EVENT, MyEvent )
+
+// An arbitrary functor:
+
+class MyFunctor
+{
+    public:
+        void operator () ( MyEvent & )
+        { }
+
+        bool operator == ( const MyFunctor & ) const
+        { return ( true ); }
+};
+
+
+class MyHandler : public wxEvtHandler
+{
+    public:
+        void handleMethod( MyEvent & )
+        { }
+
+        static void handleFunction( MyEvent & )
+        { }
+
+        void handleEvent( wxEvent & )
+        { }
+
+};
+
+void EvtHandlerTestCase::TestConnectCompilation()
+{
+    // Test that connecting the 'legacy' events still compiles:
+
+    MyHandler handler;
+
+    handler.Connect( EVT_LEGACY, (wxObjectEventFunction)&MyHandler::handleEvent, NULL, &handler );
+    handler.Connect( 0, EVT_LEGACY, (wxObjectEventFunction)&MyHandler::handleEvent, NULL, &handler );
+    handler.Connect( 0, 0, EVT_LEGACY, (wxObjectEventFunction)&MyHandler::handleEvent, NULL, &handler );
+
+    handler.Disconnect( EVT_LEGACY, (wxObjectEventFunction)&MyHandler::handleEvent, NULL, &handler );
+    handler.Disconnect( 0, EVT_LEGACY, (wxObjectEventFunction)&MyHandler::handleEvent, NULL, &handler );
+    handler.Disconnect( 0, 0, EVT_LEGACY, (wxObjectEventFunction)&MyHandler::handleEvent, NULL, &handler );
+
+
+
+    handler.Connect( EVT_LEGACY, (wxObjectEventFunction)&MyHandler::handleEvent );
+    handler.Connect( 0, EVT_LEGACY, (wxObjectEventFunction)&MyHandler::handleEvent );
+    handler.Connect( 0, 0, EVT_LEGACY, (wxObjectEventFunction)&MyHandler::handleEvent );
+
+    handler.Disconnect( EVT_LEGACY, (wxObjectEventFunction)&MyHandler::handleEvent );
+    handler.Disconnect( 0, EVT_LEGACY, (wxObjectEventFunction)&MyHandler::handleEvent );
+    handler.Disconnect( 0, 0, EVT_LEGACY, (wxObjectEventFunction)&MyHandler::handleEvent );
+
+    // Call (and therefore instantiate) all Connect() variants to detect template
+    // errors:
+
+#if !wxEVENTS_COMPATIBILITY_2_8
+
+    handler.Connect( EVT_EVENT, &MyHandler::handleFunction );
+    handler.Connect( 0, EVT_EVENT, &MyHandler::handleFunction );
+    handler.Connect( 0, 0, EVT_EVENT, &MyHandler::handleFunction );
+
+    handler.Disconnect( EVT_EVENT, &MyHandler::handleFunction );
+    handler.Disconnect( 0, EVT_EVENT, &MyHandler::handleFunction );
+    handler.Disconnect( 0, 0, EVT_EVENT, &MyHandler::handleFunction );
+
+
+
+    handler.Connect( EVT_EVENT, &MyHandler::handleMethod );
+    handler.Connect( 0, EVT_EVENT, &MyHandler::handleMethod );
+    handler.Connect( 0, 0, EVT_EVENT, &MyHandler::handleMethod );
+
+    handler.Disconnect( EVT_EVENT, &MyHandler::handleMethod );
+    handler.Disconnect( 0, EVT_EVENT, &MyHandler::handleMethod );
+    handler.Disconnect( 0, 0, EVT_EVENT, &MyHandler::handleMethod );
+
+
+
+    handler.Connect( EVT_EVENT, &MyHandler::handleMethod, NULL, &handler );
+    handler.Connect( 0, EVT_EVENT, &MyHandler::handleMethod, NULL, &handler );
+    handler.Connect( 0, 0, EVT_EVENT, &MyHandler::handleMethod, NULL, &handler );
+
+    handler.Disconnect( EVT_EVENT, &MyHandler::handleMethod, NULL, &handler );
+    handler.Disconnect( 0, EVT_EVENT, &MyHandler::handleMethod, NULL, &handler );
+    handler.Disconnect( 0, 0, EVT_EVENT, &MyHandler::handleMethod, NULL, &handler );
+
+
+
+    wxEvtHandler::Connect( &handler, EVT_EVENT, &MyHandler::handleMethod, NULL, &handler );
+    wxEvtHandler::Connect( &handler, 0, EVT_EVENT, &MyHandler::handleMethod, NULL, &handler );
+    wxEvtHandler::Connect( &handler, 0, 0, EVT_EVENT, &MyHandler::handleMethod, NULL, &handler );
+
+    wxEvtHandler::Disconnect( &handler, EVT_EVENT, &MyHandler::handleMethod, NULL, &handler );
+    wxEvtHandler::Disconnect( &handler, 0, EVT_EVENT, &MyHandler::handleMethod, NULL, &handler );
+    wxEvtHandler::Disconnect( &handler, 0, 0, EVT_EVENT, &MyHandler::handleMethod, NULL, &handler );
+
+
+
+    MyFunctor functor;
+
+    handler.Connect( EVT_EVENT, functor );
+    handler.Connect( 0, EVT_EVENT, functor );
+    handler.Connect( 0, 0, EVT_EVENT, functor );
+
+    handler.Disconnect( EVT_EVENT, functor );
+    handler.Disconnect( 0, EVT_EVENT, functor );
+    handler.Disconnect( 0, 0, EVT_EVENT, functor );
+#endif
+}
+
+void EvtHandlerTestCase::TestEventFunctorCompare()
+{
+//#if !wxEVENTS_COMPATIBILITY_2_8
+//    MyHandler handler1;
+//    wxEventFunctor *connectFunctor = wxNewEventFunctor( EVT_EVENT, &MyHandler::handleMethod, &handler1 );
+//    wxEventFunctor *disconnectFunctor = wxNewEventFunctor( EVT_EVENT, &MyHandler::handleMethod, &handler1 );
+//    wxEventFunctor *nullFunctor = wxNewEventFunctor( EVT_EVENT, &MyHandler::handleMethod );
+//   
+//    CPPUNIT_ASSERT( connectFunctor->Matches( *disconnectFunctor ));
+//    CPPUNIT_ASSERT( disconnectFunctor->Matches( *connectFunctor ));
+//
+//    CPPUNIT_ASSERT( connectFunctor->Matches( *nullFunctor ));
+//    CPPUNIT_ASSERT( nullFunctor->Matches( *connectFunctor ));
+//
+//    CPPUNIT_ASSERT( disconnectFunctor->Matches( *nullFunctor ));
+//    CPPUNIT_ASSERT( nullFunctor->Matches( *disconnectFunctor ));
+//#endif
+}
+
+
index 9271298a018d5480f2ae5e0cefcb40632f6d101e..bf331edec977e18710f4ee5c1bd79ea8996ed5d6 100644 (file)
@@ -117,6 +117,7 @@ TEST_GUI_OBJECTS =  \
        $(OBJS)\test_gui_textentrytest.obj \
        $(OBJS)\test_gui_treectrltest.obj \
        $(OBJS)\test_gui_propagation.obj \
+       $(OBJS)\test_gui_evthandler.obj \
        $(OBJS)\test_gui_rawbmp.obj \
        $(OBJS)\test_gui_htmlwindow.obj \
        $(OBJS)\test_gui_guifuncs.obj \
@@ -613,6 +614,9 @@ $(OBJS)\test_gui_treectrltest.obj: .\controls\treectrltest.cpp
 $(OBJS)\test_gui_propagation.obj: .\events\propagation.cpp
        $(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\events\propagation.cpp
 
+$(OBJS)\test_gui_evthandler.obj: .\events\evthandler.cpp
+       $(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\events\evthandler.cpp
+
 $(OBJS)\test_gui_rawbmp.obj: .\image\rawbmp.cpp
        $(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\image\rawbmp.cpp
 
index db755e8a1ce0899abb537600a35b0e0426273a7c..d7095870ef401d07225b47d2aeccc4d245b22e0a 100644 (file)
@@ -110,6 +110,7 @@ TEST_GUI_OBJECTS =  \
        $(OBJS)\test_gui_textentrytest.o \
        $(OBJS)\test_gui_treectrltest.o \
        $(OBJS)\test_gui_propagation.o \
+       $(OBJS)\test_gui_evthandler.o \
        $(OBJS)\test_gui_rawbmp.o \
        $(OBJS)\test_gui_htmlwindow.o \
        $(OBJS)\test_gui_guifuncs.o \
@@ -593,6 +594,9 @@ $(OBJS)\test_gui_treectrltest.o: ./controls/treectrltest.cpp
 $(OBJS)\test_gui_propagation.o: ./events/propagation.cpp
        $(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $<
 
+$(OBJS)\test_gui_evthandler.o: ./events/evthandler.cpp
+       $(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $<
+
 $(OBJS)\test_gui_rawbmp.o: ./image/rawbmp.cpp
        $(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $<
 
index ae369520e3c8585e645466f6f39b767ede472aa1..8d529d7ee1b043f5851f75036754091463069dcf 100644 (file)
@@ -113,6 +113,7 @@ TEST_GUI_OBJECTS =  \
        $(OBJS)\test_gui_textentrytest.obj \
        $(OBJS)\test_gui_treectrltest.obj \
        $(OBJS)\test_gui_propagation.obj \
+       $(OBJS)\test_gui_evthandler.obj \
        $(OBJS)\test_gui_rawbmp.obj \
        $(OBJS)\test_gui_htmlwindow.obj \
        $(OBJS)\test_gui_guifuncs.obj \
@@ -698,6 +699,9 @@ $(OBJS)\test_gui_treectrltest.obj: .\controls\treectrltest.cpp
 $(OBJS)\test_gui_propagation.obj: .\events\propagation.cpp
        $(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\events\propagation.cpp
 
+$(OBJS)\test_gui_evthandler.obj: .\events\evthandler.cpp
+       $(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\events\evthandler.cpp
+
 $(OBJS)\test_gui_rawbmp.obj: .\image\rawbmp.cpp
        $(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\image\rawbmp.cpp
 
index 195a2072d97e2e24ac1c0d569c918d88540e410d..c5ca2d09ec695920ac58d4550ed0e7deca00dade 100644 (file)
@@ -344,6 +344,7 @@ TEST_GUI_OBJECTS =  &
        $(OBJS)\test_gui_textentrytest.obj &
        $(OBJS)\test_gui_treectrltest.obj &
        $(OBJS)\test_gui_propagation.obj &
+       $(OBJS)\test_gui_evthandler.obj &
        $(OBJS)\test_gui_rawbmp.obj &
        $(OBJS)\test_gui_htmlwindow.obj &
        $(OBJS)\test_gui_guifuncs.obj &
@@ -650,6 +651,9 @@ $(OBJS)\test_gui_treectrltest.obj :  .AUTODEPEND .\controls\treectrltest.cpp
 $(OBJS)\test_gui_propagation.obj :  .AUTODEPEND .\events\propagation.cpp
        $(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $<
 
+$(OBJS)\test_gui_evthandler.obj :  .AUTODEPEND .\events\evthandler.cpp
+       $(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $<
+
 $(OBJS)\test_gui_rawbmp.obj :  .AUTODEPEND .\image\rawbmp.cpp
        $(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $<
 
index 56ef3ef897822565f37b890345bfd98f2f808b0c..6c3f46c55c25bb81bf853641aeea5de3b4294d41 100644 (file)
             controls/textentrytest.cpp
             controls/treectrltest.cpp
             events/propagation.cpp
+            events/evthandler.cpp
             image/rawbmp.cpp
             html/htmlwindow.cpp
             misc/guifuncs.cpp
index 28eb179fe374318fefaa364b649d1329256630bc..00e7d760d0a79452974d5348bd5b6f905a5bc84b 100644 (file)
@@ -253,6 +253,10 @@ SOURCE=.\dummy.cpp
 # End Source File\r
 # Begin Source File\r
 \r
+SOURCE=.\events\evthandler.cpp\r
+# End Source File\r
+# Begin Source File\r
+\r
 SOURCE=.\misc\garbage.cpp\r
 # End Source File\r
 # Begin Source File\r
index ea1232cfab01ee1a313fa1ac3762fdde6acf77e7..6cb498beb86383867e20ba4afb65607fac134fef 100644 (file)
                                                UsePrecompiledHeader="1"/>\r
                                </FileConfiguration>\r
                        </File>\r
+                       <File\r
+                               RelativePath=".\events\evthandler.cpp">\r
+                       </File>\r
                        <File\r
                                RelativePath=".\misc\garbage.cpp">\r
                        </File>\r
index f5a15dd0f4a8b98fdee9980fc4ed33f8f3c059bf..913db73e774e435174964db3392701b65b4c4bb0 100644 (file)
                                        />\r
                                </FileConfiguration>\r
                        </File>\r
+                       <File\r
+                               RelativePath=".\events\evthandler.cpp"\r
+                               >\r
+                       </File>\r
                        <File\r
                                RelativePath=".\misc\garbage.cpp"\r
                                >\r
index 31c7de222e4b57385b00b293ced962bbc512a850..3a677d5af89e172801282326740c301e872584e1 100644 (file)
                                        />\r
                                </FileConfiguration>\r
                        </File>\r
+                       <File\r
+                               RelativePath=".\events\evthandler.cpp"\r
+                               >\r
+                       </File>\r
                        <File\r
                                RelativePath=".\misc\garbage.cpp"\r
                                >\r