Simplify checking for menu events in the unit test
This should make the explicit casts such as added in 8db55e9653
(Explicitly cast enum to int inside CHECK(), 2019-09-30) and the
previous commit unnecessary, result in better messages if a test fails
and allow the other tests to still run after the failing tests, as we
use CHECK() instead of CPPUNIT_ASSERT(), which maps to REQUIRE(), now.
This commit is contained in:
@@ -562,7 +562,6 @@ public:
|
|||||||
{
|
{
|
||||||
m_win->Bind(wxEVT_MENU, &MenuEventHandler::OnMenu, this);
|
m_win->Bind(wxEVT_MENU, &MenuEventHandler::OnMenu, this);
|
||||||
|
|
||||||
m_gotEvent = false;
|
|
||||||
m_event = NULL;
|
m_event = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -573,33 +572,41 @@ public:
|
|||||||
delete m_event;
|
delete m_event;
|
||||||
}
|
}
|
||||||
|
|
||||||
const wxCommandEvent& GetEvent()
|
// Check that we received an event with the given ID and return the event
|
||||||
|
// object if we did (otherwise fail the test and return NULL).
|
||||||
|
const wxObject* CheckGot(int expectedId)
|
||||||
{
|
{
|
||||||
CPPUNIT_ASSERT( m_gotEvent );
|
if ( !m_event )
|
||||||
|
{
|
||||||
|
FAIL("Event not generated");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
m_gotEvent = false;
|
CHECK( m_event->GetId() == expectedId );
|
||||||
|
|
||||||
return *m_event;
|
const wxObject* const src = m_event->GetEventObject();
|
||||||
|
|
||||||
|
delete m_event;
|
||||||
|
m_event = NULL;
|
||||||
|
|
||||||
|
return src;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GotEvent() const
|
bool GotEvent() const
|
||||||
{
|
{
|
||||||
return m_gotEvent;
|
return m_event != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void OnMenu(wxCommandEvent& event)
|
void OnMenu(wxCommandEvent& event)
|
||||||
{
|
{
|
||||||
CPPUNIT_ASSERT( !m_gotEvent );
|
CHECK( !m_event );
|
||||||
|
|
||||||
delete m_event;
|
|
||||||
m_event = static_cast<wxCommandEvent*>(event.Clone());
|
m_event = static_cast<wxCommandEvent*>(event.Clone());
|
||||||
m_gotEvent = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wxWindow* const m_win;
|
wxWindow* const m_win;
|
||||||
wxCommandEvent* m_event;
|
wxCommandEvent* m_event;
|
||||||
bool m_gotEvent;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // wxUSE_UIACTIONSIMULATOR
|
#endif // wxUSE_UIACTIONSIMULATOR
|
||||||
@@ -619,59 +626,45 @@ void MenuTestCase::Events()
|
|||||||
sim.KeyUp(WXK_F1);
|
sim.KeyUp(WXK_F1);
|
||||||
wxYield();
|
wxYield();
|
||||||
|
|
||||||
const wxCommandEvent& ev = handler.GetEvent();
|
INFO("Expecting event for F1");
|
||||||
CPPUNIT_ASSERT_EQUAL( static_cast<int>(MenuTestCase_Bar), ev.GetId() );
|
if ( const wxObject* const src = handler.CheckGot(MenuTestCase_Bar) )
|
||||||
|
{
|
||||||
wxObject* const src = ev.GetEventObject();
|
CHECK( wxString(src->GetClassInfo()->GetClassName()) == "wxMenu" );
|
||||||
CPPUNIT_ASSERT( src );
|
CHECK( src == m_menuWithBar );
|
||||||
|
}
|
||||||
CPPUNIT_ASSERT_EQUAL( "wxMenu",
|
|
||||||
wxString(src->GetClassInfo()->GetClassName()) );
|
|
||||||
CPPUNIT_ASSERT_EQUAL( static_cast<wxObject*>(m_menuWithBar),
|
|
||||||
src );
|
|
||||||
|
|
||||||
// Invoke another accelerator, it should also work.
|
// Invoke another accelerator, it should also work.
|
||||||
sim.Char('A', wxMOD_CONTROL);
|
sim.Char('A', wxMOD_CONTROL);
|
||||||
wxYield();
|
wxYield();
|
||||||
|
|
||||||
const wxCommandEvent& ev2 = handler.GetEvent();
|
INFO("Expecting event for Ctrl-A");
|
||||||
CHECK( ev2.GetId() == static_cast<int>(MenuTestCase_SelectAll) );
|
handler.CheckGot(MenuTestCase_SelectAll);
|
||||||
|
|
||||||
// Invoke accelerator and extra accelerators, all of them should work.
|
// Invoke accelerator and extra accelerators, all of them should work.
|
||||||
sim.Char('U', wxMOD_CONTROL);
|
sim.Char('U', wxMOD_CONTROL);
|
||||||
wxYield();
|
wxYield();
|
||||||
if ( handler.GotEvent() )
|
INFO("Expecting event for Ctrl-U");
|
||||||
CHECK( handler.GetEvent().GetId() == static_cast<int>(MenuTestCase_ExtraAccel) );
|
handler.CheckGot(MenuTestCase_ExtraAccel);
|
||||||
else
|
|
||||||
FAIL("No expected event for Ctrl-U");
|
|
||||||
|
|
||||||
sim.Char('V', wxMOD_CONTROL);
|
sim.Char('V', wxMOD_CONTROL);
|
||||||
wxYield();
|
wxYield();
|
||||||
if ( handler.GotEvent() )
|
INFO("Expecting event for Ctrl-V");
|
||||||
CHECK( handler.GetEvent().GetId() == static_cast<int>(MenuTestCase_ExtraAccel) );
|
handler.CheckGot(MenuTestCase_ExtraAccel);
|
||||||
else
|
|
||||||
FAIL("No expected event for Ctrl-V");
|
|
||||||
|
|
||||||
sim.Char('W', wxMOD_CONTROL);
|
sim.Char('W', wxMOD_CONTROL);
|
||||||
wxYield();
|
wxYield();
|
||||||
if ( handler.GotEvent() )
|
INFO("Expecting event for Ctrl-W");
|
||||||
CHECK( handler.GetEvent().GetId() == static_cast<int>(MenuTestCase_ExtraAccels) );
|
handler.CheckGot(MenuTestCase_ExtraAccels);
|
||||||
else
|
|
||||||
FAIL("No expected event for Ctrl-W");
|
|
||||||
|
|
||||||
sim.Char('T', wxMOD_CONTROL);
|
sim.Char('T', wxMOD_CONTROL);
|
||||||
wxYield();
|
wxYield();
|
||||||
if ( handler.GotEvent() )
|
INFO("Expecting event for Ctrl-T");
|
||||||
CHECK( handler.GetEvent().GetId() == static_cast<int>(MenuTestCase_ExtraAccels) );
|
handler.CheckGot(MenuTestCase_ExtraAccels);
|
||||||
else
|
|
||||||
FAIL("No expected event for Ctrl-T");
|
|
||||||
|
|
||||||
sim.Char('W', wxMOD_CONTROL | wxMOD_SHIFT);
|
sim.Char('W', wxMOD_CONTROL | wxMOD_SHIFT);
|
||||||
wxYield();
|
wxYield();
|
||||||
if ( handler.GotEvent() )
|
INFO("Expecting event for Ctrl-Shift-W");
|
||||||
CHECK( handler.GetEvent().GetId() == static_cast<int>(MenuTestCase_ExtraAccels) );
|
handler.CheckGot(MenuTestCase_ExtraAccels);
|
||||||
else
|
|
||||||
FAIL("No expected event for Ctrl-Shift-W");
|
|
||||||
|
|
||||||
// Now create a text control which uses the same accelerator for itself and
|
// Now create a text control which uses the same accelerator for itself and
|
||||||
// check that when the text control has focus, the accelerator does _not_
|
// check that when the text control has focus, the accelerator does _not_
|
||||||
|
|||||||
Reference in New Issue
Block a user