X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/52212bcb4a89cd0b784c93b5bc860308bd91c457..9c505a36e7cd4aa04a16c7ad4c68a57b5e266a82:/tests/events/propagation.cpp diff --git a/tests/events/propagation.cpp b/tests/events/propagation.cpp index 7ec1e50dd3..3392c778a6 100644 --- a/tests/events/propagation.cpp +++ b/tests/events/propagation.cpp @@ -178,6 +178,7 @@ private: CPPUNIT_TEST( TwoHandlers ); CPPUNIT_TEST( WindowWithoutHandler ); CPPUNIT_TEST( WindowWithHandler ); + CPPUNIT_TEST( ForwardEvent ); CPPUNIT_TEST( ScrollWindowWithoutHandler ); CPPUNIT_TEST( ScrollWindowWithHandler ); CPPUNIT_TEST_SUITE_END(); @@ -186,6 +187,7 @@ private: void TwoHandlers(); void WindowWithoutHandler(); void WindowWithHandler(); + void ForwardEvent(); void ScrollWindowWithoutHandler(); void ScrollWindowWithHandler(); @@ -195,7 +197,7 @@ private: // register in the unnamed registry so that these tests are run by default CPPUNIT_TEST_SUITE_REGISTRATION( EventPropagationTestCase ); -// 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( EventPropagationTestCase, "EventPropagationTestCase" ); void EventPropagationTestCase::setUp() @@ -262,6 +264,48 @@ void EventPropagationTestCase::WindowWithHandler() CPPUNIT_ASSERT_EQUAL( "oa2o1cpA", g_str ); } +void EventPropagationTestCase::ForwardEvent() +{ + // The idea of this test is to check that the events explicitly forwarded + // to another event handler still get pre/post-processed as usual as this + // used to be broken by the fixes trying to avoid duplicate processing. + TestWindow * const win = new TestWindow(wxTheApp->GetTopWindow(), 'w'); + wxON_BLOCK_EXIT_OBJ0( *win, wxWindow::Destroy ); + + TestEvtHandler h1('1'); + win->PushEventHandler(&h1); + wxON_BLOCK_EXIT_OBJ1( *win, wxWindow::PopEventHandler, false ); + + class ForwardEvtHandler : public wxEvtHandler + { + public: + ForwardEvtHandler(wxEvtHandler& h) : m_h(&h) { } + + virtual bool ProcessEvent(wxEvent& event) + { + g_str += 'f'; + + return m_h->ProcessEvent(event); + } + + private: + wxEvtHandler *m_h; + } f(h1); + + // First send the event directly to f. + wxCommandEvent event1(TEST_EVT); + f.ProcessEvent(event1); + CPPUNIT_ASSERT_EQUAL( "foa1wA", g_str ); + g_str.clear(); + + // And then also test sending it to f indirectly. + wxCommandEvent event2(TEST_EVT); + TestEvtHandler h2('2'); + h2.SetNextHandler(&f); + h2.ProcessEvent(event2); + CPPUNIT_ASSERT_EQUAL( "oa2fo1wAA", g_str ); +} + void EventPropagationTestCase::ScrollWindowWithoutHandler() { TestWindow * const parent = new TestWindow(wxTheApp->GetTopWindow(), 'p'); @@ -269,10 +313,11 @@ void EventPropagationTestCase::ScrollWindowWithoutHandler() TestScrollWindow * const win = new TestScrollWindow(parent); +#ifndef __WXOSX__ wxPaintEvent event(win->GetId()); win->ProcessWindowEvent(event); CPPUNIT_ASSERT_EQUAL( "PD", g_str ); - +#endif g_str.clear(); wxCommandEvent eventCmd(TEST_EVT); win->HandleWindowEvent(eventCmd); @@ -286,6 +331,7 @@ void EventPropagationTestCase::ScrollWindowWithHandler() TestScrollWindow * const win = new TestScrollWindow(parent); +#ifndef __WXOSX__ TestPaintEvtHandler h('h'); win->PushEventHandler(&h); wxON_BLOCK_EXIT_OBJ1( *win, wxWindow::PopEventHandler, false ); @@ -293,6 +339,7 @@ void EventPropagationTestCase::ScrollWindowWithHandler() wxPaintEvent event(win->GetId()); win->ProcessWindowEvent(event); CPPUNIT_ASSERT_EQUAL( "ohPD", g_str ); +#endif g_str.clear(); wxCommandEvent eventCmd(TEST_EVT);