Added SelectItemMultiInteractive test case to TreeCtrlTestCase

Selecting multiple items (in wxTreeCtrl with wxTR_MULTIPLE flag) and then
deselecting them by clicking on the current item that is also part of the
selection should deselect everything but the current item without starting
to edit that item.
This commit is contained in:
ali kettab
2024-07-06 20:31:49 +01:00
parent 73cb4320c6
commit 8567dfd08c
2 changed files with 78 additions and 1 deletions
+1 -1
View File
@@ -232,7 +232,7 @@ jobs:
# used by std::vector<>::insert().
export ASAN_OPTIONS='fast_unwind_on_malloc=0 detect_container_overflow=0'
# Exclude tests that are currently known to fail
wx_tests_selection='~[.] ~[valnum] ~wxPersistTLW ~wxPersistDVC ~wxTopLevel::Show ~wxFont::Weight ~wxFont::NativeFontInfo ~WebView ~RadioButton::Single ~RadioButton::Focus ~wxHtmlPrintout::Pagination ~wxTextCtrl::GetBestSize ~TextCtrlTestCase ~wxExecute::RedirectUTF8 ~Ellipsization::NormalCase ~SpinCtrl::* ~SpinCtrlDouble::* ~NotebookTestCase ~SettingsTestCase ~Window::Show ~ModalDialogsTestCase ~Button::Click ~Button::Disabled ~wxDVC::GetItemRect ~wxDVC::AppendTextColumn ~Grid::KeyboardSelection ~Grid::CellClick ~Grid::ReorderedColumnsCellClick ~Grid::CellSelect ~wxStyledTextCtrl::AutoComp ~EvtLoopTestCase ~EventPropagationTestCase ~wxTreeCtrl::ItemClick ~wxTreeCtrl::LabelEdit ~wxTreeCtrl::KeyDown ~wxTreeCtrl::CollapseExpandEvents ~wxTreeCtrl::SelectionChange ~wxTreeCtrl::Menu ~wxTreeCtrl::KeyNavigation'
wx_tests_selection='~[.] ~[valnum] ~wxPersistTLW ~wxPersistDVC ~wxTopLevel::Show ~wxFont::Weight ~wxFont::NativeFontInfo ~WebView ~RadioButton::Single ~RadioButton::Focus ~wxHtmlPrintout::Pagination ~wxTextCtrl::GetBestSize ~TextCtrlTestCase ~wxExecute::RedirectUTF8 ~Ellipsization::NormalCase ~SpinCtrl::* ~SpinCtrlDouble::* ~NotebookTestCase ~SettingsTestCase ~Window::Show ~ModalDialogsTestCase ~Button::Click ~Button::Disabled ~wxDVC::GetItemRect ~wxDVC::AppendTextColumn ~Grid::KeyboardSelection ~Grid::CellClick ~Grid::ReorderedColumnsCellClick ~Grid::CellSelect ~wxStyledTextCtrl::AutoComp ~EvtLoopTestCase ~EventPropagationTestCase ~wxTreeCtrl::ItemClick ~wxTreeCtrl::LabelEdit ~wxTreeCtrl::KeyDown ~wxTreeCtrl::CollapseExpandEvents ~wxTreeCtrl::SelectionChange ~wxTreeCtrl::SelectItemMultiInteractive ~wxTreeCtrl::Menu ~wxTreeCtrl::KeyNavigation'
./test_gui.app/Contents/MacOS/test_gui $wx_tests_selection
- name: Building samples
+77
View File
@@ -25,6 +25,7 @@
#include "wx/treectrl.h"
#include "wx/uiaction.h"
#include "testableframe.h"
#include "waitfor.h"
// ----------------------------------------------------------------------------
// test class
@@ -58,6 +59,7 @@ public:
}
protected:
// the tree control itself
wxTreeCtrl *m_tree = nullptr;
@@ -400,6 +402,81 @@ TEST_CASE_METHOD(TreeCtrlTestCase, "wxTreeCtrl::SelectionChange", "[treectrl]")
}
}
TEST_CASE_METHOD(TreeCtrlTestCase, "wxTreeCtrl::SelectItemMultiInteractive", "[treectrl]")
{
#if defined(__WXGTK__) && !defined(__WXGTK3__)
// FIXME: This test fails on GitHub CI under wxGTK2 although works fine on
// development machine, no idea why though!
if ( IsAutomaticTest() )
return;
#endif // wxGTK2
// this test should be only ran in multi-selection control
m_tree->ToggleWindowStyle(wxTR_MULTIPLE);
m_tree->ExpandAll();
// This is currently needed to work around a problem under wxMSW: clicking
// on an item in an unfocused control generates two selection change events
// because of the SetFocus() call in TVN_SELCHANGED handler in wxMSW code.
// This is, of course, wrong on its own, but fixing it without breaking
// anything else is non-obvious, so for now at least work around this
// problem in the test.
m_tree->SetFocus();
EventCounter beginedit(m_tree, wxEVT_TREE_BEGIN_LABEL_EDIT);
wxUIActionSimulator sim;
wxRect poschild1, poschild2;
m_tree->GetBoundingRect(m_child1, poschild1, true);
m_tree->GetBoundingRect(m_child2, poschild2, true);
// We move in slightly so we are not on the edge
wxPoint point1 = m_tree->ClientToScreen(poschild1.GetPosition()) + wxPoint(4, 4);
wxPoint point2 = m_tree->ClientToScreen(poschild2.GetPosition()) + wxPoint(4, 4);
sim.MouseMove(point1);
wxYield();
sim.MouseClick();
wxYield();
sim.MouseMove(point2);
wxYield();
sim.KeyDown(WXK_CONTROL);
sim.MouseClick();
sim.KeyUp(WXK_CONTROL);
wxYield();
// m_child1 and m_child2 should be selected.
CHECK( m_tree->IsSelected(m_child1) );
CHECK( m_tree->IsSelected(m_child2) );
CHECK( beginedit.GetCount() == 0 );
// Time needed (in ms) for the editor to display. The test will not pass
// if the value is less than 400, 510, 800 under wxQt, wxGTK, wxMSW resp.
const int BEGIN_EDIT_TIMEOUT = 800;
YieldForAWhile(BEGIN_EDIT_TIMEOUT);
sim.MouseClick();
YieldForAWhile(BEGIN_EDIT_TIMEOUT);
// Only m_child2 should be selected now.
CHECK_FALSE( m_tree->IsSelected(m_child1) );
CHECK( m_tree->IsSelected(m_child2) );
CHECK( beginedit.GetCount() == 0 ); // No editing should take place in the event of deselection.
sim.MouseClick();
YieldForAWhile(BEGIN_EDIT_TIMEOUT);
CHECK( beginedit.GetCount() == 1 ); // Start editing as usual.
sim.Char(WXK_RETURN); // End editing and close the editor.
wxYield();
}
TEST_CASE_METHOD(TreeCtrlTestCase, "wxTreeCtrl::Menu", "[treectrl]")
{
EventCounter menu(m_tree, wxEVT_TREE_ITEM_MENU);