add a unit test for new events (see #10000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@58611 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -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
|
||||
|
||||
|
188
tests/events/evthandler.cpp
Normal file
188
tests/events/evthandler.cpp
Normal file
@@ -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
|
||||
}
|
||||
|
||||
|
@@ -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
|
||||
|
||||
|
@@ -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) $<
|
||||
|
||||
|
@@ -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
|
||||
|
||||
|
@@ -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) $<
|
||||
|
||||
|
@@ -114,6 +114,7 @@
|
||||
controls/textentrytest.cpp
|
||||
controls/treectrltest.cpp
|
||||
events/propagation.cpp
|
||||
events/evthandler.cpp
|
||||
image/rawbmp.cpp
|
||||
html/htmlwindow.cpp
|
||||
misc/guifuncs.cpp
|
||||
|
@@ -253,6 +253,10 @@ SOURCE=.\dummy.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\events\evthandler.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\misc\garbage.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
@@ -609,6 +609,9 @@
|
||||
UsePrecompiledHeader="1"/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\events\evthandler.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\misc\garbage.cpp">
|
||||
</File>
|
||||
|
@@ -891,6 +891,10 @@
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\events\evthandler.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\misc\garbage.cpp"
|
||||
>
|
||||
|
@@ -863,6 +863,10 @@
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\events\evthandler.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\misc\garbage.cpp"
|
||||
>
|
||||
|
Reference in New Issue
Block a user