X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ce45133ee7de9002d7fa274cbce6fc5cfab2d4c2..fd5907ffd9b0785bb6eb6f2546101623b23827c5:/tests/events/propagation.cpp diff --git a/tests/events/propagation.cpp b/tests/events/propagation.cpp index f27395f1a5..bbc7428be6 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(); @@ -262,23 +264,74 @@ void EventPropagationTestCase::WindowWithHandler() CPPUNIT_ASSERT_EQUAL( "oa2o1cpA", g_str ); } -void EventPropagationTestCase::ScrollWindowWithoutHandler() +void EventPropagationTestCase::ForwardEvent() { - TestScrollWindow * const - win = new TestScrollWindow(wxTheApp->GetTopWindow()); + // 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'); + wxON_BLOCK_EXIT_OBJ0( *parent, wxWindow::Destroy ); + + 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); + CPPUNIT_ASSERT_EQUAL( "apA", g_str ); } void EventPropagationTestCase::ScrollWindowWithHandler() { - TestScrollWindow * const - win = new TestScrollWindow(wxTheApp->GetTopWindow()); - wxON_BLOCK_EXIT_OBJ0( *win, wxWindow::Destroy ); + TestWindow * const parent = new TestWindow(wxTheApp->GetTopWindow(), 'p'); + wxON_BLOCK_EXIT_OBJ0( *parent, wxWindow::Destroy ); + + TestScrollWindow * const win = new TestScrollWindow(parent); +#ifndef __WXOSX__ TestPaintEvtHandler h('h'); win->PushEventHandler(&h); wxON_BLOCK_EXIT_OBJ1( *win, wxWindow::PopEventHandler, false ); @@ -286,5 +339,11 @@ void EventPropagationTestCase::ScrollWindowWithHandler() wxPaintEvent event(win->GetId()); win->ProcessWindowEvent(event); CPPUNIT_ASSERT_EQUAL( "ohPD", g_str ); +#endif + + g_str.clear(); + wxCommandEvent eventCmd(TEST_EVT); + win->HandleWindowEvent(eventCmd); + CPPUNIT_ASSERT_EQUAL( "apA", g_str ); }