diff --git a/tests/controls/listbasetest.cpp b/tests/controls/listbasetest.cpp index 240ef3e676..4764bf294d 100644 --- a/tests/controls/listbasetest.cpp +++ b/tests/controls/listbasetest.cpp @@ -1,9 +1,9 @@ /////////////////////////////////////////////////////////////////////////////// // Name: tests/controls/listbasetest.cpp -// Purpose: Base class for wxListCtrl and wxListView tests +// Purpose: Common wxListCtrl and wxListView tests // Author: Steven Lamerton // Created: 2010-07-20 -// Copyright: (c) 2008 Vadim Zeitlin , +// Copyright: (c) 2008,2025 Vadim Zeitlin , // (c) 2010 Steven Lamerton /////////////////////////////////////////////////////////////////////////////// @@ -178,6 +178,8 @@ void ListBaseTestCase::ChangeMode() void ListBaseTestCase::MultiSelect() { #if wxUSE_UIACTIONSIMULATOR + if ( !EnableUITests() ) + return; #if defined(__WXGTK__) && !defined(__WXGTK3__) // FIXME: This test fails on GitHub CI under wxGTK2 although works fine on @@ -310,6 +312,8 @@ void ListBaseTestCase::MultiSelect() void ListBaseTestCase::ItemClick() { #if wxUSE_UIACTIONSIMULATOR + if ( !EnableUITests() ) + return; #ifdef __WXMSW__ // FIXME: This test fails on MSW buildbot slaves although works fine on @@ -377,6 +381,9 @@ void ListBaseTestCase::ItemClick() void ListBaseTestCase::KeyDown() { #if wxUSE_UIACTIONSIMULATOR + if ( !EnableUITests() ) + return; + wxListCtrl* const list = GetList(); EventCounter keydown(list, wxEVT_LIST_KEY_DOWN); @@ -526,6 +533,9 @@ void ListBaseTestCase::ItemFormatting() void ListBaseTestCase::EditLabel() { #if wxUSE_UIACTIONSIMULATOR + if ( !EnableUITests() ) + return; + wxListCtrl* const list = GetList(); list->SetWindowStyleFlag(wxLC_REPORT | wxLC_EDIT_LABELS); diff --git a/tests/controls/listbasetest.h b/tests/controls/listbasetest.h index 8b8df808b7..664a9a2e5e 100644 --- a/tests/controls/listbasetest.h +++ b/tests/controls/listbasetest.h @@ -1,9 +1,9 @@ /////////////////////////////////////////////////////////////////////////////// // Name: tests/controls/listbasetest.cpp -// Purpose: Base class for wxListCtrl and wxListView tests +// Purpose: Common wxListCtrl and wxListView tests // Author: Steven Lamerton // Created: 2010-07-20 -// Copyright: (c) 2008 Vadim Zeitlin , +// Copyright: (c) 2008,2025 Vadim Zeitlin , // (c) 2010 Steven Lamerton /////////////////////////////////////////////////////////////////////////////// @@ -19,24 +19,6 @@ public: protected: virtual wxListCtrl *GetList() const = 0; - #define wxLIST_BASE_TESTS() \ - CPPUNIT_TEST( ColumnsOrder ); \ - CPPUNIT_TEST( ItemRect ); \ - CPPUNIT_TEST( ItemText ); \ - CPPUNIT_TEST( ChangeMode ); \ - WXUISIM_TEST( ItemClick ); \ - WXUISIM_TEST( KeyDown ); \ - WXUISIM_TEST( MultiSelect ); \ - CPPUNIT_TEST( DeleteItems ); \ - CPPUNIT_TEST( InsertItem ); \ - CPPUNIT_TEST( Find ); \ - CPPUNIT_TEST( Visible ); \ - CPPUNIT_TEST( ItemFormatting ); \ - WXUISIM_TEST( EditLabel ); \ - CPPUNIT_TEST( ImageList ); \ - CPPUNIT_TEST( HitTest ); \ - CPPUNIT_TEST( Sort ) - void ColumnsOrder(); void ItemRect(); void ItemText(); @@ -57,4 +39,36 @@ protected: wxDECLARE_NO_COPY_CLASS(ListBaseTestCase); }; +// In the macros below, ClassName is the name of the class (without "wx" +// prefix), i.e. an identifier, and ClassTag is the string containing the +// tag to be used in the test registration macro. + +// Define a test case delegating to ListBaseTestCase. +#define wxLIST_TEST_CASE(ClassName, ClassTag, TestName) \ + TEST_CASE_METHOD(ClassName ## TestCase, \ + #ClassName "::" #TestName, \ + ClassTag) \ + { \ + TestName(); \ + } + +// Define all common test cases. +#define wxLIST_BASE_TESTS(ClassName, TagName) \ + wxLIST_TEST_CASE(ClassName, TagName, ColumnsOrder) \ + wxLIST_TEST_CASE(ClassName, TagName, ItemRect) \ + wxLIST_TEST_CASE(ClassName, TagName, ItemText) \ + wxLIST_TEST_CASE(ClassName, TagName, ChangeMode) \ + wxLIST_TEST_CASE(ClassName, TagName, ItemClick) \ + wxLIST_TEST_CASE(ClassName, TagName, KeyDown) \ + wxLIST_TEST_CASE(ClassName, TagName, MultiSelect) \ + wxLIST_TEST_CASE(ClassName, TagName, DeleteItems) \ + wxLIST_TEST_CASE(ClassName, TagName, InsertItem) \ + wxLIST_TEST_CASE(ClassName, TagName, Find) \ + wxLIST_TEST_CASE(ClassName, TagName, Visible) \ + wxLIST_TEST_CASE(ClassName, TagName, ItemFormatting) \ + wxLIST_TEST_CASE(ClassName, TagName, EditLabel) \ + wxLIST_TEST_CASE(ClassName, TagName, ImageList) \ + wxLIST_TEST_CASE(ClassName, TagName, HitTest) \ + wxLIST_TEST_CASE(ClassName, TagName, Sort) + #endif diff --git a/tests/controls/listctrltest.cpp b/tests/controls/listctrltest.cpp index 8dd0af687b..26dc86ecc6 100644 --- a/tests/controls/listctrltest.cpp +++ b/tests/controls/listctrltest.cpp @@ -31,52 +31,25 @@ // test class // ---------------------------------------------------------------------------- -class ListCtrlTestCase : public ListBaseTestCase, public CppUnit::TestCase +class ListCtrlTestCase : public ListBaseTestCase { public: - ListCtrlTestCase() { } - - virtual void setUp() override; - virtual void tearDown() override; + ListCtrlTestCase(); + virtual ~ListCtrlTestCase() override; virtual wxListCtrl *GetList() const override { return m_list; } -private: - CPPUNIT_TEST_SUITE( ListCtrlTestCase ); - wxLIST_BASE_TESTS(); - CPPUNIT_TEST( EditLabel ); - WXUISIM_TEST( ColumnClick ); - WXUISIM_TEST( ColumnDrag ); - CPPUNIT_TEST( SubitemRect ); - CPPUNIT_TEST( ColumnCount ); - CPPUNIT_TEST_SUITE_END(); - - void EditLabel(); - void SubitemRect(); - void ColumnCount(); -#if wxUSE_UIACTIONSIMULATOR - // Column events are only supported in wxListCtrl currently so we test them - // here rather than in ListBaseTest - void ColumnClick(); - void ColumnDrag(); -#endif // wxUSE_UIACTIONSIMULATOR - +protected: wxListCtrl *m_list; wxDECLARE_NO_COPY_CLASS(ListCtrlTestCase); }; -// register in the unnamed registry so that these tests are run by default -CPPUNIT_TEST_SUITE_REGISTRATION( ListCtrlTestCase ); - -// also include in its own registry so that these tests can be run alone -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ListCtrlTestCase, "ListCtrlTestCase" ); - // ---------------------------------------------------------------------------- // test initialization // ---------------------------------------------------------------------------- -void ListCtrlTestCase::setUp() +ListCtrlTestCase::ListCtrlTestCase() { m_list = new wxListCtrl(wxTheApp->GetTopWindow()); m_list->SetWindowStyle(wxLC_REPORT | wxLC_EDIT_LABELS); @@ -85,13 +58,15 @@ void ListCtrlTestCase::setUp() wxTheApp->GetTopWindow()->Raise(); } -void ListCtrlTestCase::tearDown() +ListCtrlTestCase::~ListCtrlTestCase() { DeleteTestWindow(m_list); - m_list = nullptr; } -void ListCtrlTestCase::EditLabel() +wxLIST_BASE_TESTS(ListCtrl, "[listctrl]") + +// Note that wxLIST_BASE_TESTS() already defines "ListCtrl::EditLabel" test. +TEST_CASE_METHOD(ListCtrlTestCase, "ListCtrl::CallEditLabel", "[listctrl]") { EventCounter editItem(m_list, wxEVT_LIST_BEGIN_LABEL_EDIT); EventCounter endEditItem(m_list, wxEVT_LIST_END_LABEL_EDIT); @@ -106,7 +81,7 @@ void ListCtrlTestCase::EditLabel() CHECK(endEditItem.GetCount() == 1); } -void ListCtrlTestCase::SubitemRect() +TEST_CASE_METHOD(ListCtrlTestCase, "ListCtrl::SubitemRect", "[listctrl]") { wxBitmap bmp = wxArtProvider::GetBitmap(wxART_ERROR); @@ -151,7 +126,7 @@ void ListCtrlTestCase::SubitemRect() CHECK(rectLabel.GetRight() == rectItem.GetRight()); } -void ListCtrlTestCase::ColumnCount() +TEST_CASE_METHOD(ListCtrlTestCase, "ListCtrl::ColumnCount", "[listctrl]") { CHECK(m_list->GetColumnCount() == 0); m_list->InsertColumn(0, "Column 0"); @@ -179,8 +154,12 @@ void ListCtrlTestCase::ColumnCount() } #if wxUSE_UIACTIONSIMULATOR -void ListCtrlTestCase::ColumnDrag() + +TEST_CASE_METHOD(ListCtrlTestCase, "ListCtrl::ColumnDrag", "[listctrl]") { + if ( !EnableUITests() ) + return; + EventCounter begindrag(m_list, wxEVT_LIST_COL_BEGIN_DRAG); EventCounter dragging(m_list, wxEVT_LIST_COL_DRAGGING); EventCounter enddrag(m_list, wxEVT_LIST_COL_END_DRAG); @@ -214,8 +193,11 @@ void ListCtrlTestCase::ColumnDrag() m_list->ClearAll(); } -void ListCtrlTestCase::ColumnClick() +TEST_CASE_METHOD(ListCtrlTestCase, "ListCtrl::ColumnClick", "[listctrl]") { + if ( !EnableUITests() ) + return; + EventCounter colclick(m_list, wxEVT_LIST_COL_CLICK); EventCounter colrclick(m_list, wxEVT_LIST_COL_RIGHT_CLICK); diff --git a/tests/controls/listviewtest.cpp b/tests/controls/listviewtest.cpp index f10154b4d4..c03c4bc4c7 100644 --- a/tests/controls/listviewtest.cpp +++ b/tests/controls/listviewtest.cpp @@ -19,51 +19,35 @@ #include "listbasetest.h" #include "testableframe.h" -class ListViewTestCase : public ListBaseTestCase, public CppUnit::TestCase +class ListViewTestCase : public ListBaseTestCase { public: - ListViewTestCase() { } - - virtual void setUp() override; - virtual void tearDown() override; + ListViewTestCase(); + virtual ~ListViewTestCase() override; virtual wxListCtrl *GetList() const override { return m_list; } -private: - CPPUNIT_TEST_SUITE( ListViewTestCase ); - wxLIST_BASE_TESTS(); - CPPUNIT_TEST( Selection ); - CPPUNIT_TEST( Focus ); - CPPUNIT_TEST_SUITE_END(); - - void Selection(); - void Focus(); - +protected: wxListView *m_list; wxDECLARE_NO_COPY_CLASS(ListViewTestCase); }; -// register in the unnamed registry so that these tests are run by default -CPPUNIT_TEST_SUITE_REGISTRATION( ListViewTestCase ); - -// also include in its own registry so that these tests can be run alone -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ListViewTestCase, "ListViewTestCase" ); - -void ListViewTestCase::setUp() +ListViewTestCase::ListViewTestCase() { m_list = new wxListView(wxTheApp->GetTopWindow()); m_list->SetWindowStyle(wxLC_REPORT); m_list->SetSize(400, 200); } -void ListViewTestCase::tearDown() +ListViewTestCase::~ListViewTestCase() { DeleteTestWindow(m_list); - m_list = nullptr; } -void ListViewTestCase::Selection() +wxLIST_BASE_TESTS(ListView, "[listctrl][listview]") + +TEST_CASE_METHOD(ListViewTestCase, "ListView::Selection", "[listctrl][listview]") { m_list->InsertColumn(0, "Column 0"); @@ -101,7 +85,7 @@ void ListViewTestCase::Selection() CPPUNIT_ASSERT_EQUAL(2, m_list->GetFirstSelected()); } -void ListViewTestCase::Focus() +TEST_CASE_METHOD(ListViewTestCase, "ListView::Focus", "[listctrl][listview]") { EventCounter focused(m_list, wxEVT_LIST_ITEM_FOCUSED);