Make wxUIActionSimulator works more reliably on GTK/X11
Add wxXSync class which adds delays between the synthesized events sufficient for them to be processed by the higher layers (X, GTK). This makes it possible to run the UI tests by default with wxGTK. Closes https://github.com/wxWidgets/wxWidgets/pull/1845
This commit is contained in:
committed by
Vadim Zeitlin
parent
fb5c13ed00
commit
59ad9f46e6
@@ -88,7 +88,10 @@ void BitmapToggleButtonTestCase::Click()
|
||||
CPPUNIT_ASSERT(m_button->GetValue());
|
||||
|
||||
clicked.Clear();
|
||||
|
||||
#ifdef __WXMSW__
|
||||
wxMilliSleep(1000);
|
||||
#endif
|
||||
|
||||
sim.MouseClick();
|
||||
wxYield();
|
||||
|
@@ -145,38 +145,12 @@ TEST_CASE_METHOD(GridTestCase, "Grid::CellEdit", "[grid]")
|
||||
|
||||
sim.Text("abab");
|
||||
|
||||
// We need to wait until the editor is really shown under GTK, consider
|
||||
// that it happens once it gets focus.
|
||||
#ifdef __WXGTK__
|
||||
for ( wxStopWatch sw; wxWindow::FindFocus() == m_grid; )
|
||||
{
|
||||
if ( sw.Time() > 250 )
|
||||
{
|
||||
WARN("Editor control not shown until timeout expiration");
|
||||
break;
|
||||
}
|
||||
|
||||
wxYield();
|
||||
}
|
||||
#endif // __WXGTK__
|
||||
wxYield();
|
||||
|
||||
sim.Char(WXK_RETURN);
|
||||
|
||||
wxYield();
|
||||
|
||||
#ifdef __WXGTK__
|
||||
for ( wxStopWatch sw; wxWindow::FindFocus() != m_grid; )
|
||||
{
|
||||
if ( sw.Time() > 250 )
|
||||
{
|
||||
WARN("Editor control not hidden until timeout expiration");
|
||||
break;
|
||||
}
|
||||
|
||||
wxYield();
|
||||
}
|
||||
#endif // __WXGTK__
|
||||
|
||||
CHECK(m_grid->GetCellValue(1, 1) == "abab");
|
||||
|
||||
CHECK(created.GetCount() == 1);
|
||||
@@ -388,11 +362,16 @@ TEST_CASE_METHOD(GridTestCase, "Grid::Size", "[grid]")
|
||||
// TODO on OSX resizing interactively works, but not automated
|
||||
// Grid could not pass the test under GTK, OSX, and Universal.
|
||||
// So there may has bug in Grid implementation
|
||||
#if wxUSE_UIACTIONSIMULATOR && !defined(__WXGTK__) && !defined(__WXOSX__) \
|
||||
&& !defined(__WXUNIVERSAL__)
|
||||
#if wxUSE_UIACTIONSIMULATOR && !defined(__WXOSX__) && !defined(__WXUNIVERSAL__)
|
||||
if ( !EnableUITests() )
|
||||
return;
|
||||
|
||||
#ifdef __WXGTK20__
|
||||
// Works locally, but not when run on Travis CI.
|
||||
if ( IsAutomaticTest() )
|
||||
return;
|
||||
#endif
|
||||
|
||||
EventCounter colsize(m_grid, wxEVT_GRID_COL_SIZE);
|
||||
EventCounter rowsize(m_grid, wxEVT_GRID_ROW_SIZE);
|
||||
|
||||
@@ -400,7 +379,6 @@ TEST_CASE_METHOD(GridTestCase, "Grid::Size", "[grid]")
|
||||
|
||||
wxPoint pt = m_grid->ClientToScreen(wxPoint(m_grid->GetRowLabelSize() +
|
||||
m_grid->GetColSize(0), 5));
|
||||
|
||||
sim.MouseMove(pt);
|
||||
wxYield();
|
||||
|
||||
@@ -419,6 +397,7 @@ TEST_CASE_METHOD(GridTestCase, "Grid::Size", "[grid]")
|
||||
m_grid->GetRowSize(0)));
|
||||
|
||||
sim.MouseDragDrop(pt.x, pt.y, pt.x, pt.y + 50);
|
||||
|
||||
wxYield();
|
||||
|
||||
CHECK(rowsize.GetCount() == 1);
|
||||
@@ -1072,15 +1051,6 @@ TEST_CASE_METHOD(GridTestCase, "Grid::ReadOnly", "[grid]")
|
||||
|
||||
m_grid->SetFocus();
|
||||
|
||||
#ifdef __WXGTK__
|
||||
// This is a mystery, but we somehow get WXK_RETURN generated by the
|
||||
// previous test (Editable) in this one. In spite of wxYield() in that
|
||||
// test, the key doesn't get dispatched there and we have to consume it
|
||||
// here before setting the current grid cell, as getting WXK_RETURN later
|
||||
// would move the selection down, to a non read-only cell.
|
||||
wxYield();
|
||||
#endif // __WXGTK__
|
||||
|
||||
m_grid->SetGridCursor(1, 1);
|
||||
|
||||
CHECK(m_grid->IsCurrentCellReadOnly());
|
||||
@@ -1161,10 +1131,16 @@ TEST_CASE_METHOD(GridTestCase, "Grid::WindowAsEditorControl", "[grid]")
|
||||
TEST_CASE_METHOD(GridTestCase, "Grid::ResizeScrolledHeader", "[grid]")
|
||||
{
|
||||
// TODO this test currently works only under Windows unfortunately
|
||||
#if wxUSE_UIACTIONSIMULATOR && defined(__WXMSW__)
|
||||
#if wxUSE_UIACTIONSIMULATOR && (defined(__WXMSW__) || defined(__WXGTK__))
|
||||
if ( !EnableUITests() )
|
||||
return;
|
||||
|
||||
#ifdef __WXGTK20__
|
||||
// Works locally, but not when run on Travis CI.
|
||||
if ( IsAutomaticTest() )
|
||||
return;
|
||||
#endif
|
||||
|
||||
SECTION("Default") {}
|
||||
SECTION("Native header") { m_grid->UseNativeColHeader(); }
|
||||
|
||||
@@ -1206,10 +1182,16 @@ TEST_CASE_METHOD(GridTestCase, "Grid::ResizeScrolledHeader", "[grid]")
|
||||
TEST_CASE_METHOD(GridTestCase, "Grid::ColumnMinWidth", "[grid]")
|
||||
{
|
||||
// TODO this test currently works only under Windows unfortunately
|
||||
#if wxUSE_UIACTIONSIMULATOR && defined(__WXMSW__)
|
||||
#if wxUSE_UIACTIONSIMULATOR && (defined(__WXMSW__) || defined(__WXGTK__))
|
||||
if ( !EnableUITests() )
|
||||
return;
|
||||
|
||||
#ifdef __WXGTK20__
|
||||
// Works locally, but not when run on Travis CI.
|
||||
if ( IsAutomaticTest() )
|
||||
return;
|
||||
#endif
|
||||
|
||||
SECTION("Default") {}
|
||||
SECTION("Native header")
|
||||
{
|
||||
|
@@ -92,7 +92,7 @@ void HyperlinkCtrlTestCase::Url()
|
||||
|
||||
void HyperlinkCtrlTestCase::Click()
|
||||
{
|
||||
#if wxUSE_UIACTIONSIMULATOR && !defined(__WXGTK__)
|
||||
#if wxUSE_UIACTIONSIMULATOR
|
||||
EventCounter hyperlink(m_hyperlink, wxEVT_HYPERLINK);
|
||||
|
||||
wxUIActionSimulator sim;
|
||||
|
@@ -251,7 +251,7 @@ void ListBaseTestCase::KeyDown()
|
||||
|
||||
list->SetFocus();
|
||||
wxYield();
|
||||
sim.Text("aAbB");
|
||||
sim.Text("aAbB"); // 4 letters + 2 shift mods.
|
||||
wxYield();
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(6, keydown.GetCount());
|
||||
|
@@ -75,8 +75,8 @@ void RadioButtonTestCase::tearDown()
|
||||
|
||||
void RadioButtonTestCase::Click()
|
||||
{
|
||||
// GTK and OS X do not support selecting a single radio button
|
||||
#if wxUSE_UIACTIONSIMULATOR && !defined(__WXGTK__) && !defined(__WXOSX__)
|
||||
// OS X doesn't support selecting a single radio button
|
||||
#if wxUSE_UIACTIONSIMULATOR && !defined(__WXOSX__)
|
||||
EventCounter selected(m_radio, wxEVT_RADIOBUTTON);
|
||||
|
||||
wxUIActionSimulator sim;
|
||||
|
@@ -128,9 +128,6 @@ void RichTextCtrlTestCase::CharacterEvent()
|
||||
{
|
||||
#if wxUSE_UIACTIONSIMULATOR
|
||||
|
||||
// There seems to be an event sequence problem on GTK+ that causes the events
|
||||
// to be disconnected before they're processed, generating spurious errors.
|
||||
#if !defined(__WXGTK__)
|
||||
EventCounter character(m_rich, wxEVT_RICHTEXT_CHARACTER);
|
||||
EventCounter content(m_rich, wxEVT_RICHTEXT_CONTENT_INSERTED);
|
||||
|
||||
@@ -154,15 +151,12 @@ void RichTextCtrlTestCase::CharacterEvent()
|
||||
CPPUNIT_ASSERT_EQUAL(0, character.GetCount());
|
||||
CPPUNIT_ASSERT_EQUAL(1, content.GetCount());
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void RichTextCtrlTestCase::DeleteEvent()
|
||||
{
|
||||
#if wxUSE_UIACTIONSIMULATOR
|
||||
// There seems to be an event sequence problem on GTK+ that causes the events
|
||||
// to be disconnected before they're processed, generating spurious errors.
|
||||
#if !defined(__WXGTK__)
|
||||
|
||||
EventCounter deleteevent(m_rich, wxEVT_RICHTEXT_DELETE);
|
||||
EventCounter contentdelete(m_rich, wxEVT_RICHTEXT_CONTENT_DELETED);
|
||||
|
||||
@@ -178,15 +172,12 @@ void RichTextCtrlTestCase::DeleteEvent()
|
||||
//Only one as the delete doesn't delete anthing
|
||||
CPPUNIT_ASSERT_EQUAL(1, contentdelete.GetCount());
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void RichTextCtrlTestCase::ReturnEvent()
|
||||
{
|
||||
#if wxUSE_UIACTIONSIMULATOR
|
||||
// There seems to be an event sequence problem on GTK+ that causes the events
|
||||
// to be disconnected before they're processed, generating spurious errors.
|
||||
#if !defined(__WXGTK__)
|
||||
|
||||
EventCounter returnevent(m_rich, wxEVT_RICHTEXT_RETURN);
|
||||
|
||||
m_rich->SetFocus();
|
||||
@@ -197,7 +188,6 @@ void RichTextCtrlTestCase::ReturnEvent()
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(1, returnevent.GetCount());
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void RichTextCtrlTestCase::StyleEvent()
|
||||
@@ -235,8 +225,7 @@ void RichTextCtrlTestCase::BufferResetEvent()
|
||||
void RichTextCtrlTestCase::UrlEvent()
|
||||
{
|
||||
#if wxUSE_UIACTIONSIMULATOR
|
||||
// Mouse up event not being caught on GTK+
|
||||
#if !defined(__WXGTK__)
|
||||
|
||||
EventCounter url(m_rich, wxEVT_TEXT_URL);
|
||||
|
||||
m_rich->BeginURL("http://www.wxwidgets.org");
|
||||
@@ -252,13 +241,11 @@ void RichTextCtrlTestCase::UrlEvent()
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(1, url.GetCount());
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void RichTextCtrlTestCase::TextEvent()
|
||||
{
|
||||
#if wxUSE_UIACTIONSIMULATOR
|
||||
#if !defined(__WXGTK__)
|
||||
EventCounter updated(m_rich, wxEVT_TEXT);
|
||||
|
||||
m_rich->SetFocus();
|
||||
@@ -270,7 +257,6 @@ void RichTextCtrlTestCase::TextEvent()
|
||||
CPPUNIT_ASSERT_EQUAL("abcdef", m_rich->GetValue());
|
||||
CPPUNIT_ASSERT_EQUAL(6, updated.GetCount());
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void RichTextCtrlTestCase::CutCopyPaste()
|
||||
@@ -418,7 +404,6 @@ void RichTextCtrlTestCase::Selection()
|
||||
void RichTextCtrlTestCase::Editable()
|
||||
{
|
||||
#if wxUSE_UIACTIONSIMULATOR
|
||||
#if !defined(__WXGTK__)
|
||||
EventCounter updated(m_rich, wxEVT_TEXT);
|
||||
|
||||
m_rich->SetFocus();
|
||||
@@ -438,7 +423,6 @@ void RichTextCtrlTestCase::Editable()
|
||||
CPPUNIT_ASSERT_EQUAL("abcdef", m_rich->GetValue());
|
||||
CPPUNIT_ASSERT_EQUAL(0, updated.GetCount());
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void RichTextCtrlTestCase::Range()
|
||||
|
@@ -91,7 +91,7 @@ void SpinCtrlDoubleTestCase::NoEventsInCtor()
|
||||
|
||||
void SpinCtrlDoubleTestCase::Arrows()
|
||||
{
|
||||
#if wxUSE_UIACTIONSIMULATOR && !defined(__WXGTK__)
|
||||
#if wxUSE_UIACTIONSIMULATOR
|
||||
EventCounter updated(m_spin, wxEVT_SPINCTRLDOUBLE);
|
||||
|
||||
wxUIActionSimulator sim;
|
||||
@@ -196,9 +196,10 @@ void SpinCtrlDoubleTestCase::Value()
|
||||
|
||||
void SpinCtrlDoubleTestCase::Increment()
|
||||
{
|
||||
#if wxUSE_UIACTIONSIMULATOR && !defined(__WXGTK__)
|
||||
#if wxUSE_UIACTIONSIMULATOR
|
||||
CPPUNIT_ASSERT_EQUAL(1.0, m_spin->GetIncrement());
|
||||
|
||||
m_spin->SetDigits(1); // GTK would fail without this.
|
||||
m_spin->SetIncrement(0.1);
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(0.1, m_spin->GetIncrement());
|
||||
|
@@ -21,6 +21,7 @@
|
||||
#include "testableframe.h"
|
||||
#include "wx/uiaction.h"
|
||||
#include "wx/spinctrl.h"
|
||||
#include "wx/textctrl.h"
|
||||
|
||||
class SpinCtrlTestCase : public CppUnit::TestCase
|
||||
{
|
||||
@@ -245,6 +246,10 @@ void SpinCtrlTestCase::SetValueInsideEventHandler()
|
||||
#if wxUSE_UIACTIONSIMULATOR
|
||||
m_spin->Bind(wxEVT_SPINCTRL, &SpinCtrlTestCase::OnSpinSetValue, this);
|
||||
|
||||
// A dummy control with which we change the focus.
|
||||
wxTextCtrl* text = new wxTextCtrl(wxTheApp->GetTopWindow(), wxID_ANY);
|
||||
text->Move(m_spin->GetSize().x, m_spin->GetSize().y * 3);
|
||||
|
||||
wxUIActionSimulator sim;
|
||||
|
||||
// run multiple times to make sure there are no issues with keeping old value
|
||||
@@ -258,7 +263,7 @@ void SpinCtrlTestCase::SetValueInsideEventHandler()
|
||||
sim.Text("20");
|
||||
wxYield();
|
||||
|
||||
wxTheApp->GetTopWindow()->SetFocus();
|
||||
text->SetFocus();
|
||||
wxYield();
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(32, m_spin->GetValue());
|
||||
|
@@ -359,6 +359,10 @@ void TextCtrlTestCase::HitTestSingleLine()
|
||||
|
||||
long pos = -1;
|
||||
|
||||
#ifdef __WXGTK__
|
||||
wxYield();
|
||||
#endif
|
||||
|
||||
// Hitting a point near the left side of the control should find one of the
|
||||
// first few characters under it.
|
||||
SECTION("Normal")
|
||||
@@ -384,24 +388,14 @@ void TextCtrlTestCase::HitTestSingleLine()
|
||||
m_text->ChangeValue(wxString(200, 'X'));
|
||||
m_text->SetInsertionPointEnd();
|
||||
|
||||
#ifdef __WXGTK__
|
||||
// wxGTK must be given an opportunity to lay the text out.
|
||||
wxYield();
|
||||
for ( wxStopWatch sw; sw.Time() < 50; )
|
||||
wxYield();
|
||||
#endif
|
||||
|
||||
// For some reason, this test consistently fails when running under
|
||||
// Xvfb. Debugging shows that the text gets scrolled too far, instead
|
||||
// of scrolling by ~156 characters, leaving the remaining 44 shown, in
|
||||
// normal runs, it gets scrolled by all 200 characters, leaving nothing
|
||||
// shown. It's not clear why does it happen, and there doesn't seem
|
||||
// anything we can do about it.
|
||||
if ( IsRunningUnderXVFB() )
|
||||
{
|
||||
WARN("Skipping test known to fail under Xvfb");
|
||||
}
|
||||
else
|
||||
{
|
||||
REQUIRE( m_text->HitTest(wxPoint(2*sizeChar.x, yMid), &pos) == wxTE_HT_ON_TEXT );
|
||||
CHECK( pos > 3 );
|
||||
}
|
||||
REQUIRE( m_text->HitTest(wxPoint(2*sizeChar.x, yMid), &pos) == wxTE_HT_ON_TEXT );
|
||||
CHECK( pos > 3 );
|
||||
|
||||
// Using negative coordinates works even under Xvfb, so test at least
|
||||
// for this -- however this only works in wxGTK, not wxMSW.
|
||||
|
@@ -292,6 +292,7 @@ void TextEntryTestCase::Editable()
|
||||
CPPUNIT_ASSERT_EQUAL("abcdef", entry->GetValue());
|
||||
CPPUNIT_ASSERT_EQUAL(6, updated.GetCount());
|
||||
|
||||
wxYield();
|
||||
|
||||
// And that the event carries the right value.
|
||||
TextEventHandler handler(window);
|
||||
|
@@ -49,10 +49,8 @@ private:
|
||||
CPPUNIT_TEST( DeleteAllItems );
|
||||
WXUISIM_TEST( LabelEdit );
|
||||
WXUISIM_TEST( KeyDown );
|
||||
#ifndef __WXGTK__
|
||||
WXUISIM_TEST( CollapseExpandEvents );
|
||||
WXUISIM_TEST( SelectionChange );
|
||||
#endif // !__WXGTK__
|
||||
WXUISIM_TEST( Menu );
|
||||
CPPUNIT_TEST( ItemData );
|
||||
CPPUNIT_TEST( Iteration );
|
||||
@@ -79,10 +77,8 @@ private:
|
||||
void DeleteAllItems();
|
||||
void LabelEdit();
|
||||
void KeyDown();
|
||||
#ifndef __WXGTK__
|
||||
void CollapseExpandEvents();
|
||||
void SelectionChange();
|
||||
#endif // !__WXGTK__
|
||||
void Menu();
|
||||
void ItemData();
|
||||
void Iteration();
|
||||
@@ -349,10 +345,14 @@ void TreeCtrlTestCase::KeyDown()
|
||||
CPPUNIT_ASSERT_EQUAL(6, keydown.GetCount());
|
||||
}
|
||||
|
||||
#if !defined(__WXGTK__)
|
||||
|
||||
void TreeCtrlTestCase::CollapseExpandEvents()
|
||||
{
|
||||
#ifdef __WXGTK20__
|
||||
// Works locally, but not when run on Travis CI.
|
||||
if ( IsAutomaticTest() )
|
||||
return;
|
||||
#endif
|
||||
|
||||
m_tree->CollapseAll();
|
||||
|
||||
EventCounter collapsed(m_tree, wxEVT_TREE_ITEM_COLLAPSED);
|
||||
@@ -377,6 +377,12 @@ void TreeCtrlTestCase::CollapseExpandEvents()
|
||||
CPPUNIT_ASSERT_EQUAL(1, expanding.GetCount());
|
||||
CPPUNIT_ASSERT_EQUAL(1, expanded.GetCount());
|
||||
|
||||
#ifdef __WXGTK__
|
||||
// Don't even know the reason why, but GTK has to sleep
|
||||
// no less than 1200 for the test case to succeed.
|
||||
wxMilliSleep(1200);
|
||||
#endif
|
||||
|
||||
sim.MouseDblClick();
|
||||
wxYield();
|
||||
|
||||
@@ -428,8 +434,6 @@ void TreeCtrlTestCase::SelectionChange()
|
||||
CPPUNIT_ASSERT_EQUAL(2, changing.GetCount());
|
||||
}
|
||||
|
||||
#endif // !__WXGTK__
|
||||
|
||||
void TreeCtrlTestCase::Menu()
|
||||
{
|
||||
EventCounter menu(m_tree, wxEVT_TREE_ITEM_MENU);
|
||||
@@ -612,12 +616,13 @@ void TreeCtrlTestCase::Sort()
|
||||
|
||||
void TreeCtrlTestCase::KeyNavigation()
|
||||
{
|
||||
#if wxUSE_UIACTIONSIMULATOR && !defined(__WXGTK__)
|
||||
#if wxUSE_UIACTIONSIMULATOR
|
||||
wxUIActionSimulator sim;
|
||||
|
||||
m_tree->CollapseAll();
|
||||
|
||||
m_tree->SelectItem(m_root);
|
||||
wxYield();
|
||||
|
||||
m_tree->SetFocus();
|
||||
sim.Char(WXK_RIGHT);
|
||||
@@ -635,6 +640,8 @@ void TreeCtrlTestCase::KeyNavigation()
|
||||
|
||||
CPPUNIT_ASSERT(!m_tree->IsExpanded(m_root));
|
||||
|
||||
wxYield();
|
||||
|
||||
sim.Char(WXK_RIGHT);
|
||||
sim.Char(WXK_DOWN);
|
||||
wxYield();
|
||||
|
@@ -27,6 +27,7 @@
|
||||
#include "wx/caret.h"
|
||||
#include "wx/cshelp.h"
|
||||
#include "wx/scopedptr.h"
|
||||
#include "wx/stopwatch.h"
|
||||
#include "wx/tooltip.h"
|
||||
|
||||
class WindowTestCase
|
||||
@@ -35,6 +36,13 @@ public:
|
||||
WindowTestCase()
|
||||
: m_window(new wxWindow(wxTheApp->GetTopWindow(), wxID_ANY))
|
||||
{
|
||||
#ifdef __WXGTK3__
|
||||
// Without this, when running this test suite solo it succeeds,
|
||||
// but not when running it together with the other tests !!
|
||||
// Not needed when run under Xvfb display.
|
||||
for ( wxStopWatch sw; sw.Time() < 50; )
|
||||
wxYield();
|
||||
#endif
|
||||
}
|
||||
|
||||
~WindowTestCase()
|
||||
|
Reference in New Issue
Block a user