From 7ccd305c847b2bf3273983d3e61b80dd4aa8fce5 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 30 Nov 2022 23:41:56 +0100 Subject: [PATCH] Tighten checks in NotebookTestCase::GetTabRect() unit test Check we get the expected values instead of just "something non zero". Also still perform the checks that are supposed to work under Wine when running there too, instead of just skipping the test entirely. --- tests/controls/notebooktest.cpp | 39 +++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/tests/controls/notebooktest.cpp b/tests/controls/notebooktest.cpp index 5a3e41def9..aede906f0b 100644 --- a/tests/controls/notebooktest.cpp +++ b/tests/controls/notebooktest.cpp @@ -19,6 +19,7 @@ #include "wx/notebook.h" #include "wx/scopedptr.h" +#include "asserthelper.h" #include "bookctrlbasetest.h" #include "testableframe.h" @@ -167,19 +168,11 @@ TEST_CASE("wxNotebook::AddPageEvents", "[wxNotebook][AddPage][event]") void NotebookTestCase::GetTabRect() { - if (wxIsRunningUnderWine()) - { - // Wine behaves different than Windows. Windows reports the size of a - // tab even if it is not visible while Wine returns an empty rectangle. - WARN("Skipping test known to fail under Wine."); - return; - } - wxNotebook *notebook = new wxNotebook(wxTheApp->GetTopWindow(), wxID_ANY, wxDefaultPosition, wxSize(400, 200)); wxScopedPtr cleanup(notebook); - notebook->AddPage(new wxPanel(notebook), "First"); + notebook->AddPage(new wxPanel(notebook), "Page"); // This function is only really implemented for wxMSW and wxUniv currently. #if defined(__WXMSW__) || defined(__WXUNIVERSAL__) @@ -187,11 +180,33 @@ void NotebookTestCase::GetTabRect() for ( size_t i = 0; i < 30; i++ ) notebook->AddPage(new wxPanel(notebook), "Page"); - for ( size_t i = 0; i < notebook->GetPageCount(); i++ ) + const wxRect rectPage = notebook->GetTabRect(0); + REQUIRE(rectPage.width != 0); + REQUIRE(rectPage.height != 0); + + int x = rectPage.x + rectPage.width; + for ( size_t i = 1; i < notebook->GetPageCount(); i++ ) { wxRect r = notebook->GetTabRect(i); - CHECK(r.width != 0); - CHECK(r.height != 0); + + if (wxIsRunningUnderWine()) + { + // Wine behaves different than Windows. Windows reports the size of a + // tab even if it is not visible while Wine returns an empty rectangle. + if ( r == wxRect() ) + { + WARN("Skipping test for pages after " << i << " under Wine."); + break; + } + } + + INFO("Page #" << i << ": rect=" << r); + REQUIRE(r.x == x); + REQUIRE(r.y == rectPage.y); + REQUIRE(r.width == rectPage.width); + REQUIRE(r.height == rectPage.height); + + x += r.width; } #else // !(__WXMSW__ || __WXUNIVERSAL__) WX_ASSERT_FAILS_WITH_ASSERT( notebook->GetTabRect(0) );