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
#include "wx/frame.h"
#include "wx/menu.h"
#include "wx/frame.h"
#include "wx/menu.h"
+#include "wx/scopedptr.h"
#include "wx/scopeguard.h"
namespace
#include "wx/scopeguard.h"
namespace
CPPUNIT_ASSERT_EQUAL( "apA", g_str );
}
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.
//
// Helper for checking that the menu event processing resulted in the expected
// output from the handlers.
//
// 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.
// 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, "" );
}
CPPUNIT_NS::assertEquals( result, g_str, sourceLine, "" );
}
void EventPropagationTestCase::MenuEvent()
{
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<wxFrame*>(wxTheApp->GetTopWindow());
wxFrame* const frame = static_cast<wxFrame*>(wxTheApp->GetTopWindow());
+
+ // Create a minimal menu bar.
+ wxMenu* const menu = CreateTestMenu(frame);
+ wxMenuBar* const mb = menu->GetMenuBar();
+ wxScopedPtr<wxMenuBar> ensureMenuBarDestruction(mb);
wxON_BLOCK_EXIT_OBJ1( *frame, wxFrame::SetMenuBar, (wxMenuBar*)NULL );
// Check that wxApp gets the event exactly once.
wxON_BLOCK_EXIT_OBJ1( *frame, wxFrame::SetMenuBar, (wxMenuBar*)NULL );
// Check that wxApp gets the event exactly once.