Use wxUIActionSimulator to test event propagation order DocView test

Because using ASSERT_MENU_EVENT_RESULT, which uses wxMenuBase::SendEvent()
under the hood, fails with wxQt on Linux. While the former seems to work on
all platforms.
This commit is contained in:
AliKet
2025-04-22 15:33:20 +01:00
parent e2464cbff1
commit b4d80a7e23

View File

@@ -29,9 +29,7 @@
#include <memory>
#if defined(__WXGTK__) || defined(__WXQT__)
#include "waitfor.h"
#endif
#include "waitfor.h"
// FIXME: Currently under OS X testing paint event doesn't work because neither
// calling Refresh()+Update() nor even sending wxPaintEvent directly to
@@ -581,7 +579,6 @@ void EventPropagationTestCase::DocView()
// Ensure that the child that we've just created is the active one.
child->Activate();
#ifdef __WXGTK__
// There are a lot of hacks related to child frame menu bar handling in
// wxGTK and, in particular, the code in src/gtk/mdi.cpp relies on getting
// idle events to really put everything in place. Moreover, as wxGTK uses
@@ -593,8 +590,8 @@ void EventPropagationTestCase::DocView()
// make things work "as usual".
child->Show();
parent->Show();
wxYield();
#endif // __WXGTK__
child->SetFocus(); // Without this, the test would fail on wxGTK2
YieldForAWhile();
TestEvtSink sinkDoc('d');
doc->Connect(wxEVT_MENU,
@@ -610,7 +607,25 @@ void EventPropagationTestCase::DocView()
// Check that wxDocument, wxView, wxDocManager, child frame and the parent
// get the event in order.
#if wxUSE_UIACTIONSIMULATOR
// We use wxUIActionSimulator instead of ASSERT_MENU_EVENT_RESULT because
// using the latter fails with wxQt on Linux.
wxUnusedVar(menuChild);
g_str.clear();
wxUIActionSimulator sim;
sim.Char('m', wxMOD_ALT);
// N.B.: Don't call wxYield() here, as this will cause the menu to appear
// immediately (and enter its internal message loop) and the next line will
// never be executed under wxMSW. In other words, the execution would block
// indefinitely.
sim.Char('a');
wxYield();
CHECK( g_str == "advmcpA" );
#else // !wxUSE_UIACTIONSIMULATOR
ASSERT_MENU_EVENT_RESULT( menuChild, "advmcpA" );
#endif // wxUSE_UIACTIONSIMULATOR
#if wxUSE_TOOLBAR
// Also check that toolbar events get forwarded to the active child.