Merge branch 'qt-uiaction-tests' of https://github.com/AliKet/wxWidgets

Enable automatic tests using wxUIActionSimulator under wxQt.

See #24015.
This commit is contained in:
Vadim Zeitlin 2023-11-17 01:05:56 +01:00
commit 5a184d423b
21 changed files with 257 additions and 67 deletions

View file

@ -134,7 +134,7 @@ void ComboBoxTestCase::Size()
void ComboBoxTestCase::PopDismiss()
{
#if defined(__WXMSW__) || defined(__WXGTK210__)
#if defined(__WXMSW__) || defined(__WXGTK210__) || defined(__WXQT__)
EventCounter drop(m_combo, wxEVT_COMBOBOX_DROPDOWN);
EventCounter close(m_combo, wxEVT_COMBOBOX_CLOSEUP);

View file

@ -873,6 +873,7 @@ TEST_CASE_METHOD(SingleSelectDataViewCtrlTestCase,
EventCounter keyEvents(m_dvc, wxEVT_KEY_DOWN);
m_dvc->SetFocus();
wxYield();
wxUIActionSimulator sim;
sim.Char(WXK_DOWN);

View file

@ -639,7 +639,11 @@ TEST_CASE_METHOD(GridTestCase, "Grid::Size", "[grid]")
wxUIActionSimulator sim;
wxPoint pt = m_grid->ClientToScreen(wxPoint(m_grid->GetRowLabelSize() +
m_grid->GetColSize(0), 5));
m_grid->GetColSize(0), 5));
#ifdef __WXQT__
pt += wxPoint(1, 0); // FIXME: why this is needed?
#endif
sim.MouseMove(pt);
wxYield();
@ -659,6 +663,10 @@ TEST_CASE_METHOD(GridTestCase, "Grid::Size", "[grid]")
pt = m_grid->ClientToScreen(wxPoint(5, m_grid->GetColLabelSize() +
m_grid->GetRowSize(0)));
#ifdef __WXQT__
pt += wxPoint(0, 1); // FIXME: why this is needed?
#endif
sim.MouseDragDrop(pt.x, pt.y, pt.x, pt.y + 50);
WaitFor("mouse drag to be processed", [&]() {
@ -973,6 +981,7 @@ TEST_CASE_METHOD(GridTestCase, "Grid::MoveGridCursorUsingEndKey", "[grid]")
m_grid->SetColPos(10, 5);
m_grid->SetFocus();
wxYield();
sim.KeyDown(WXK_END, wxMOD_CONTROL);
sim.KeyUp(WXK_END, wxMOD_CONTROL);
@ -999,6 +1008,7 @@ TEST_CASE_METHOD(GridTestCase, "Grid::SelectUsingEndKey", "[grid]")
REQUIRE( m_grid->IsVisible(0, 0) );
m_grid->SetFocus();
wxYield();
sim.KeyDown(WXK_END, wxMOD_CONTROL | wxMOD_SHIFT);
sim.KeyUp(WXK_END, wxMOD_CONTROL | wxMOD_SHIFT);
@ -1373,6 +1383,8 @@ TEST_CASE_METHOD(GridTestCase, "Grid::Editable", "[grid]")
m_grid->SetFocus();
m_grid->SetGridCursor(1, 1);
wxYield();
sim.Text("abab");
wxYield();
@ -1404,6 +1416,8 @@ TEST_CASE_METHOD(GridTestCase, "Grid::ReadOnly", "[grid]")
m_grid->SetGridCursor(1, 1);
wxYield();
CHECK(m_grid->IsCurrentCellReadOnly());
sim.Text("abab");
@ -1481,8 +1495,8 @@ TEST_CASE_METHOD(GridTestCase, "Grid::WindowAsEditorControl", "[grid]")
TEST_CASE_METHOD(GridTestCase, "Grid::ResizeScrolledHeader", "[grid]")
{
// TODO this test currently works only under Windows and GTK unfortunately
#if wxUSE_UIACTIONSIMULATOR && (defined(__WXMSW__) || defined(__WXGTK__))
// TODO this test currently works only under Windows, GTK and Qt unfortunately
#if wxUSE_UIACTIONSIMULATOR && (defined(__WXMSW__) || defined(__WXGTK__) || defined(__WXQT__))
if ( !EnableUITests() )
return;
@ -1506,6 +1520,10 @@ TEST_CASE_METHOD(GridTestCase, "Grid::ResizeScrolledHeader", "[grid]")
m_grid->GetColLabelSize())
- wxPoint(0, 5));
#ifdef __WXQT__
point += wxPoint(1, 0); // FIXME: why this is needed?
#endif
wxUIActionSimulator sim;
wxYield();
@ -1528,8 +1546,8 @@ TEST_CASE_METHOD(GridTestCase, "Grid::ResizeScrolledHeader", "[grid]")
TEST_CASE_METHOD(GridTestCase, "Grid::ColumnMinWidth", "[grid]")
{
// TODO this test currently works only under Windows and GTK unfortunately
#if wxUSE_UIACTIONSIMULATOR && (defined(__WXMSW__) || defined(__WXGTK__))
// TODO this test currently works only under Windows, GTK and Qt unfortunately
#if wxUSE_UIACTIONSIMULATOR && (defined(__WXMSW__) || defined(__WXGTK__) || defined(__WXQT__))
if ( !EnableUITests() )
return;
@ -1561,6 +1579,10 @@ TEST_CASE_METHOD(GridTestCase, "Grid::ColumnMinWidth", "[grid]")
m_grid->GetColLabelSize())
- wxPoint(0, 5));
#ifdef __WXQT__
point += wxPoint(1, 0); // FIXME: why this is needed?
#endif
wxUIActionSimulator sim;
// Drag to reach the minimal width.

View file

@ -345,6 +345,7 @@ void ItemContainerTestCase::SimSelect()
container->Append("third");
GetContainerWindow()->SetFocus();
wxYield();
wxUIActionSimulator sim;
CPPUNIT_ASSERT( sim.Select("third") );

View file

@ -199,8 +199,8 @@ void ListBoxTestCase::ClickEvents()
m_list->Append(testitems);
m_list->Update();
m_list->Refresh();
m_list->Update();
sim.MouseMove(m_list->ClientToScreen(wxPoint(10, 10)));
wxYield();
@ -242,8 +242,8 @@ void ListBoxTestCase::ClickNotOnItem()
// simply avoid it by starting with a valid selection.
m_list->SetSelection(0);
m_list->Update();
m_list->Refresh();
m_list->Update();
sim.MouseMove(m_list->ClientToScreen(wxPoint(m_list->GetSize().x - 10, m_list->GetSize().y - 10)));
wxYield();

View file

@ -1477,8 +1477,11 @@ TEST_CASE("PropertyGridTestCase", "[propgrid]")
SECTION("SetSplitterPosition")
{
#ifndef __WXQT__
const int trySplitterPos = 50;
#else
const int trySplitterPos = 51; // FIXME!
#endif
int style = wxPG_AUTO_SORT; // wxPG_SPLITTER_AUTO_CENTER;
ReplaceGrid(pgManager, style, -1);

View file

@ -145,7 +145,7 @@ TEST_CASE_METHOD(RadioBoxTestCase, "RadioBox::HelpText", "[radiobox][help]")
TEST_CASE_METHOD(RadioBoxTestCase, "RadioBox::ToolTip", "[radiobox][tooltip]")
{
#if defined (__WXMSW__) || defined(__WXGTK__)
#if defined (__WXMSW__) || defined(__WXGTK__) || defined(__WXQT__)
//GetItemToolTip returns null if there is no tooltip set
CHECK(!m_radio->GetItemToolTip(0));

View file

@ -93,6 +93,7 @@ void SliderTestCase::PageUpDown()
wxUIActionSimulator sim;
m_slider->SetFocus();
wxYield();
sim.Char(WXK_PAGEUP);
sim.Char(WXK_PAGEDOWN);
@ -111,8 +112,9 @@ void SliderTestCase::LineUpDown()
EventCounter linedown(m_slider, wxEVT_SCROLL_LINEDOWN);
wxUIActionSimulator sim;
wxYield();
m_slider->SetFocus();
wxYield();
sim.Char(WXK_UP);
sim.Char(WXK_DOWN);
@ -130,8 +132,9 @@ void SliderTestCase::EvtSlider()
EventCounter slider(m_slider, wxEVT_SLIDER);
wxUIActionSimulator sim;
wxYield();
m_slider->SetFocus();
wxYield();
sim.Char(WXK_UP);
sim.Char(WXK_DOWN);
@ -146,8 +149,9 @@ void SliderTestCase::LinePageSize()
{
#if wxUSE_UIACTIONSIMULATOR
wxUIActionSimulator sim;
wxYield();
m_slider->SetFocus();
wxYield();
m_slider->SetPageSize(20);
@ -221,7 +225,7 @@ void SliderTestCase::Thumb()
CPPUNIT_ASSERT(track.GetCount() != 0);
CPPUNIT_ASSERT_EQUAL(1, release.GetCount());
#if defined(__WXMSW__) || defined(__WXGTK__)
#if defined(__WXMSW__) || defined(__WXGTK__) || defined(__WXQT__)
CPPUNIT_ASSERT_EQUAL(1, changed.GetCount());
#endif
#endif

View file

@ -32,6 +32,10 @@
#include "waitfor.h"
#endif
#ifdef __WXQT__
#include <QtGlobal>
#endif
#include "wx/private/localeset.h"
#include "textentrytest.h"
@ -241,6 +245,10 @@ void TextCtrlTestCase::ReadOnly()
m_text->SetFocus();
#endif
// We get spurious update under wxQt. get rid of it before doing
// the next simulation.
updated.Clear();
sim.Text("abcdef");
wxYield();
@ -252,6 +260,13 @@ void TextCtrlTestCase::ReadOnly()
void TextCtrlTestCase::MaxLength()
{
#if wxUSE_UIACTIONSIMULATOR
#ifdef __WXQT__
#if (QT_VERSION < QT_VERSION_CHECK(5, 12, 0))
WARN("wxEVT_TEXT_MAXLEN event is only generated if Qt version is 5.12 or greater");
return;
#endif
#endif
EventCounter updated(m_text, wxEVT_TEXT);
EventCounter maxlen(m_text, wxEVT_TEXT_MAXLEN);

View file

@ -317,6 +317,11 @@ void TreeCtrlTestCase::LabelEdit()
wxUIActionSimulator sim;
#ifdef __WXQT__
m_tree->SetFocus();
wxYield();
#endif
m_tree->SetFocusedItem(m_tree->GetRootItem());
m_tree->EditLabel(m_tree->GetRootItem());
@ -338,6 +343,7 @@ void TreeCtrlTestCase::KeyDown()
wxUIActionSimulator sim;
m_tree->SetFocus();
wxYield();
sim.Text("aAbB");
wxYield();

View file

@ -243,6 +243,9 @@ void KeyboardEventTestCase::tearDown()
void KeyboardEventTestCase::NormalLetter()
{
#ifdef __WXQT__
WARN("FIXME! doesn't work like the other ports.");
#else
wxUIActionSimulator sim;
sim.Char('a');
wxYield();
@ -255,6 +258,7 @@ void KeyboardEventTestCase::NormalLetter()
CPPUNIT_ASSERT_EQUAL( 1, m_win->GetKeyUpCount() );
ASSERT_KEY_EVENT_IS( m_win->GetKeyUpEvent(), 'A' );
#endif
}
void KeyboardEventTestCase::NormalSpecial()
@ -275,6 +279,9 @@ void KeyboardEventTestCase::NormalSpecial()
void KeyboardEventTestCase::CtrlLetter()
{
#ifdef __WXQT__
WARN("FIXME! doesn't work like the other ports.");
#else
wxUIActionSimulator sim;
sim.Char('z', wxMOD_CONTROL);
wxYield();
@ -294,6 +301,7 @@ void KeyboardEventTestCase::CtrlLetter()
KeyDesc('Z', wxMOD_CONTROL) );
ASSERT_KEY_EVENT_IS( m_win->GetKeyUpEvent(1),
ModKeyUp(WXK_CONTROL) );
#endif
}
void KeyboardEventTestCase::CtrlSpecial()

View file

@ -171,6 +171,9 @@ TEST_CASE("wxDC::GetPartialTextExtent", "[dc][text-extent][partial]")
TEST_CASE("wxGC::GetTextExtent", "[dc][text-extent]")
{
#ifdef __WXQT__
WARN("Skip test known to fail under wxQt");
#else
wxGraphicsRenderer* renderer = wxGraphicsRenderer::GetDefaultRenderer();
REQUIRE(renderer);
wxGraphicsContext* context = renderer->CreateMeasuringContext();
@ -185,7 +188,7 @@ TEST_CASE("wxGC::GetTextExtent", "[dc][text-extent]")
// TODO: Determine a way to make these tests more robust.
CHECK(width > 0.0);
CHECK(height > 0.0);
#endif
}
#endif // TEST_GC

View file

@ -23,6 +23,8 @@
#include "wx/translation.h"
#include "wx/uiaction.h"
#include "waitfor.h"
#include <stdarg.h>
#include <memory>
@ -604,7 +606,13 @@ void MenuTestCase::Events()
// Invoke the accelerator.
m_frame->Show();
m_frame->SetFocus();
wxYield();
// Wait for m_frame to become focused. Because (at least under wxQt when running
// the entire test suite) the first test below would fail due to the simulation
// starts before the frame become focused.
WaitFor("the frame to become focused", [this]() {
return m_frame->HasFocus();
});
wxUIActionSimulator sim;
sim.KeyDown(WXK_F1);

View file

@ -524,11 +524,11 @@ bool EnableUITests()
if ( s_enabled == -1 )
{
#if defined(__WXMSW__) || defined(__WXGTK__)
#if defined(__WXMSW__) || defined(__WXGTK__) || defined(__WXQT__)
s_enabled = 1;
#else // !(__WXMSW__ || __WXGTK__)
#else // !(__WXMSW__ || __WXGTK__ || __WXQT__)
s_enabled = 0;
#endif // (__WXMSW__ || __WXGTK__)
#endif // (__WXMSW__ || __WXGTK__ || __WXQT__)
}
}

View file

@ -281,6 +281,7 @@ TEST_CASE_METHOD(NumValidatorTestCase, "ValNum::Interactive", "[valnum]")
// Entering '-' in a control with positive range is not allowed.
m_text->SetFocus();
wxYield();
sim.Char('-');
wxYield();
CHECK( m_text->GetValue() == "" );