From bbde2164ac9c79a5f268942c8e2b771e8c5f5e82 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 4 May 2013 23:59:48 +0000 Subject: [PATCH] Factor out functions dealing with menus in the event propagation test. No real changes, just refactor the code to allow testing for menu events in other frames too. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@73926 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- tests/events/propagation.cpp | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/tests/events/propagation.cpp b/tests/events/propagation.cpp index d13e8eb532..0a9222f7e0 100644 --- a/tests/events/propagation.cpp +++ b/tests/events/propagation.cpp @@ -26,7 +26,7 @@ #include "wx/frame.h" #include "wx/menu.h" - +#include "wx/scopedptr.h" #include "wx/scopeguard.h" namespace @@ -362,6 +362,19 @@ void EventPropagationTestCase::ScrollWindowWithHandler() CPPUNIT_ASSERT_EQUAL( "apA", g_str ); } +// Create a menu bar with a single menu containing wxID_APPLY menu item and +// attach it to the specified frame. +wxMenu* CreateTestMenu(wxFrame* frame) +{ + wxMenu* const menu = new wxMenu; + menu->Append(wxID_APPLY); + wxMenuBar* const mb = new wxMenuBar; + mb->Append(menu, "&Menu"); + frame->SetMenuBar(mb); + + return menu; +} + // Helper for checking that the menu event processing resulted in the expected // output from the handlers. // @@ -376,7 +389,7 @@ CheckMenuEvent(wxMenu* menu, const char* result, CppUnit::SourceLine sourceLine) // Trigger the menu event: this is more reliable than using // wxUIActionSimulator and currently works in all ports as they all call // wxMenuBase::SendEvent() from their respective menu event handlers. - menu->SendEvent(wxID_NEW); + menu->SendEvent(wxID_APPLY); CPPUNIT_NS::assertEquals( result, g_str, sourceLine, "" ); } @@ -386,14 +399,12 @@ CheckMenuEvent(wxMenu* menu, const char* result, CppUnit::SourceLine sourceLine) void EventPropagationTestCase::MenuEvent() { - // Create a minimal menu bar. - wxMenu* const menu = new wxMenu; - menu->Append(wxID_NEW); - wxMenuBar* const mb = new wxMenuBar; - mb->Append(menu, "&Menu"); - wxFrame* const frame = static_cast(wxTheApp->GetTopWindow()); - frame->SetMenuBar(mb); + + // Create a minimal menu bar. + wxMenu* const menu = CreateTestMenu(frame); + wxMenuBar* const mb = menu->GetMenuBar(); + wxScopedPtr ensureMenuBarDestruction(mb); wxON_BLOCK_EXIT_OBJ1( *frame, wxFrame::SetMenuBar, (wxMenuBar*)NULL ); // Check that wxApp gets the event exactly once. -- 2.45.2