+
+void MenuTestCase::RemoveAdd()
+{
+ wxMenuBar* bar = m_frame->GetMenuBar();
+
+ wxMenu* menu0 = bar->GetMenu(0);
+ wxMenu* menu1 = bar->GetMenu(1);
+ wxMenuItem* item = new wxMenuItem(menu0, MenuTestCase_Foo + 100, "t&ext\tCtrl-E");
+ menu0->Insert(0, item);
+ CPPUNIT_ASSERT( menu0->FindItemByPosition(0) == item );
+ menu0->Remove(item);
+ CPPUNIT_ASSERT( menu0->FindItemByPosition(0) != item );
+ menu1->Insert(0, item);
+ CPPUNIT_ASSERT( menu1->FindItemByPosition(0) == item );
+ menu1->Remove(item);
+ CPPUNIT_ASSERT( menu1->FindItemByPosition(0) != item );
+ menu0->Insert(0, item);
+ CPPUNIT_ASSERT( menu0->FindItemByPosition(0) == item );
+ menu0->Delete(item);
+}
+
+void MenuTestCase::Events()
+{
+#if wxUSE_UIACTIONSIMULATOR
+ class MenuEventHandler : public wxEvtHandler
+ {
+ public:
+ MenuEventHandler(wxWindow* win)
+ : m_win(win)
+ {
+ m_win->Connect(wxEVT_COMMAND_MENU_SELECTED,
+ wxCommandEventHandler(MenuEventHandler::OnMenu),
+ NULL,
+ this);
+
+ m_gotEvent = false;
+ m_event = NULL;
+ }
+
+ virtual ~MenuEventHandler()
+ {
+ m_win->Disconnect(wxEVT_COMMAND_MENU_SELECTED,
+ wxCommandEventHandler(MenuEventHandler::OnMenu),
+ NULL,
+ this);
+
+ delete m_event;
+ }
+
+ const wxCommandEvent& GetEvent()
+ {
+ CPPUNIT_ASSERT( m_gotEvent );
+
+ m_gotEvent = false;
+
+ return *m_event;
+ }
+
+ private:
+ void OnMenu(wxCommandEvent& event)
+ {
+ CPPUNIT_ASSERT( !m_gotEvent );
+
+ delete m_event;
+ m_event = static_cast<wxCommandEvent*>(event.Clone());
+ m_gotEvent = true;
+ }
+
+ wxWindow* const m_win;
+ wxCommandEvent* m_event;
+ bool m_gotEvent;
+ };
+
+ MenuEventHandler handler(m_frame);
+
+ // Invoke the accelerator.
+ m_frame->Show();
+ m_frame->SetFocus();
+ wxYield();
+
+ wxUIActionSimulator sim;
+ sim.KeyDown(WXK_F1);
+ sim.KeyUp(WXK_F1);
+ wxYield();
+
+ const wxCommandEvent& ev = handler.GetEvent();
+ CPPUNIT_ASSERT_EQUAL( static_cast<int>(MenuTestCase_Bar), ev.GetId() );
+
+ wxObject* const src = ev.GetEventObject();
+ CPPUNIT_ASSERT( src );
+
+ CPPUNIT_ASSERT_EQUAL( "wxMenu",
+ wxString(src->GetClassInfo()->GetClassName()) );
+ CPPUNIT_ASSERT_EQUAL( static_cast<wxObject*>(m_menuWithBar),
+ src );
+#endif // wxUSE_UIACTIONSIMULATOR
+}