From 85503d1dcd6614996f7fa97e226e23f71695568e Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 20 Oct 2021 23:32:50 +0100 Subject: [PATCH] Get rid of CppUnit boilerplate in MiscGUIFuncsTestCase Simplify code by not defining an unnecessary test case class and using CATCH macros directly. No real changes. --- tests/misc/guifuncs.cpp | 149 +++++++++++----------------------------- 1 file changed, 42 insertions(+), 107 deletions(-) diff --git a/tests/misc/guifuncs.cpp b/tests/misc/guifuncs.cpp index b0c4af4aea..c47b941d6a 100644 --- a/tests/misc/guifuncs.cpp +++ b/tests/misc/guifuncs.cpp @@ -30,103 +30,74 @@ #include "asserthelper.h" // ---------------------------------------------------------------------------- -// test class +// the tests // ---------------------------------------------------------------------------- -class MiscGUIFuncsTestCase : public CppUnit::TestCase -{ -public: - MiscGUIFuncsTestCase() { } - -private: - CPPUNIT_TEST_SUITE( MiscGUIFuncsTestCase ); - CPPUNIT_TEST( DisplaySize ); - CPPUNIT_TEST( URLDataObject ); - CPPUNIT_TEST( ParseFileDialogFilter ); - CPPUNIT_TEST( ClientToScreen ); - CPPUNIT_TEST( FindWindowAtPoint ); - CPPUNIT_TEST_SUITE_END(); - - void DisplaySize(); - void URLDataObject(); - void ParseFileDialogFilter(); - void ClientToScreen(); - void FindWindowAtPoint(); - - wxDECLARE_NO_COPY_CLASS(MiscGUIFuncsTestCase); -}; - -// register in the unnamed registry so that these tests are run by default -CPPUNIT_TEST_SUITE_REGISTRATION( MiscGUIFuncsTestCase ); - -// also include in its own registry so that these tests can be run alone -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( MiscGUIFuncsTestCase, "MiscGUIFuncsTestCase" ); - -void MiscGUIFuncsTestCase::DisplaySize() +TEST_CASE("GUI::DisplaySize", "[guifuncs]") { // test that different (almost) overloads return the same results int w, h; wxDisplaySize(&w, &h); wxSize sz = wxGetDisplaySize(); - CPPUNIT_ASSERT_EQUAL( w, sz.x ); - CPPUNIT_ASSERT_EQUAL( h, sz.y ); + CHECK( sz.x == w ); + CHECK( sz.y == h ); // test that passing NULL works as expected, e.g. doesn't crash wxDisplaySize(NULL, NULL); wxDisplaySize(&w, NULL); wxDisplaySize(NULL, &h); - CPPUNIT_ASSERT_EQUAL( w, sz.x ); - CPPUNIT_ASSERT_EQUAL( h, sz.y ); + CHECK( sz.x == w ); + CHECK( sz.y == h ); // test that display PPI is something reasonable sz = wxGetDisplayPPI(); - CPPUNIT_ASSERT( sz.x < 1000 ); - CPPUNIT_ASSERT( sz.y < 1000 ); + CHECK( sz.x < 1000 ); + CHECK( sz.y < 1000 ); } -void MiscGUIFuncsTestCase::URLDataObject() -{ #if wxUSE_DATAOBJ +TEST_CASE("GUI::URLDataObject", "[guifuncs]") +{ // this tests for buffer overflow, see #11102 const char * const url = "http://something.long.to.overwrite.plenty.memory.example.com"; wxURLDataObject * const dobj = new wxURLDataObject(url); - CPPUNIT_ASSERT_EQUAL( url, dobj->GetURL() ); + CHECK( dobj->GetURL() == url ); wxClipboardLocker lockClip; - CPPUNIT_ASSERT( wxTheClipboard->SetData(dobj) ); + CHECK( wxTheClipboard->SetData(dobj) ); wxTheClipboard->Flush(); -#endif // wxUSE_DATAOBJ } +#endif // wxUSE_DATAOBJ -void MiscGUIFuncsTestCase::ParseFileDialogFilter() +TEST_CASE("GUI::ParseFileDialogFilter", "[guifuncs]") { wxArrayString descs, filters; - CPPUNIT_ASSERT_EQUAL + REQUIRE ( - 1, wxParseCommonDialogsFilter("Image files|*.jpg;*.png", descs, filters) + == 1 ); - CPPUNIT_ASSERT_EQUAL( "Image files", descs[0] ); - CPPUNIT_ASSERT_EQUAL( "*.jpg;*.png", filters[0] ); + CHECK( descs[0] == "Image files" ); + CHECK( filters[0] == "*.jpg;*.png" ); - CPPUNIT_ASSERT_EQUAL + REQUIRE ( - 2, wxParseCommonDialogsFilter ( "All files (*.*)|*.*|Python source (*.py)|*.py", descs, filters ) + == 2 ); - CPPUNIT_ASSERT_EQUAL( "*.*", filters[0] ); - CPPUNIT_ASSERT_EQUAL( "*.py", filters[1] ); + CHECK( filters[0] == "*.*" ); + CHECK( filters[1] == "*.py" ); // Test some invalid ones too. WX_ASSERT_FAILS_WITH_ASSERT @@ -139,10 +110,10 @@ void MiscGUIFuncsTestCase::ParseFileDialogFilter() ); } -void MiscGUIFuncsTestCase::ClientToScreen() +TEST_CASE("GUI::ClientToScreen", "[guifuncs]") { wxWindow* const tlw = wxTheApp->GetTopWindow(); - CPPUNIT_ASSERT( tlw ); + REQUIRE( tlw ); wxScopedPtr const p1(new wxPanel(tlw, wxID_ANY, wxPoint(0, 0), wxSize(100, 50))); @@ -156,17 +127,9 @@ void MiscGUIFuncsTestCase::ClientToScreen() const wxPoint tlwOrig = tlw->ClientToScreen(wxPoint(0, 0)); - CPPUNIT_ASSERT_EQUAL - ( - tlwOrig + wxPoint(0, 50), - p2->ClientToScreen(wxPoint(0, 0)) - ); + CHECK( p2->ClientToScreen(wxPoint(0, 0)) == tlwOrig + wxPoint(0, 50) ); - CPPUNIT_ASSERT_EQUAL - ( - tlwOrig + wxPoint(10, 60), - b->ClientToScreen(wxPoint(0, 0)) - ); + CHECK( b->ClientToScreen(wxPoint(0, 0)) == tlwOrig + wxPoint(10, 60) ); } namespace @@ -195,10 +158,10 @@ wxString GetLabelOfWindowAtPoint(wxWindow* parent, int x, int y) } // anonymous namespace -void MiscGUIFuncsTestCase::FindWindowAtPoint() +TEST_CASE("GUI::FindWindowAtPoint", "[guifuncs]") { wxWindow* const parent = wxTheApp->GetTopWindow(); - CPPUNIT_ASSERT( parent ); + REQUIRE( parent ); // Set a label to allow distinguishing it from the other windows in the // assertion messages. @@ -213,56 +176,28 @@ void MiscGUIFuncsTestCase::FindWindowAtPoint() // We need this to realize the windows created above under wxGTK. wxYield(); - CPPUNIT_ASSERT_EQUAL_MESSAGE - ( - "No window for a point outside of the window", - "NONE", - GetLabelOfWindowAtPoint(parent, 900, 900) - ); + INFO("No window for a point outside of the window"); + CHECK( GetLabelOfWindowAtPoint(parent, 900, 900) == "NONE" ); - CPPUNIT_ASSERT_EQUAL_MESSAGE - ( - "Point over a child control corresponds to it", - btn1->GetLabel(), - GetLabelOfWindowAtPoint(parent, 11, 11) - ); + INFO( "Point over a child control corresponds to it" ); + CHECK( GetLabelOfWindowAtPoint(parent, 11, 11) == btn1->GetLabel() ); - CPPUNIT_ASSERT_EQUAL_MESSAGE - ( - "Point outside of any child control returns the TLW itself", - parent->GetLabel(), - GetLabelOfWindowAtPoint(parent, 5, 5) - ); + INFO("Point outside of any child control returns the TLW itself"); + CHECK( GetLabelOfWindowAtPoint(parent, 5, 5) == parent->GetLabel() ); btn2->Disable(); - CPPUNIT_ASSERT_EQUAL_MESSAGE - ( - "Point over a disabled child control still corresponds to it", - btn2->GetLabel(), - GetLabelOfWindowAtPoint(parent, 11, 91) - ); + INFO("Point over a disabled child control still corresponds to it"); + CHECK( GetLabelOfWindowAtPoint(parent, 11, 91) == btn2->GetLabel() ); btn2->Hide(); - CPPUNIT_ASSERT_EQUAL_MESSAGE - ( - "Point over a hidden child control doesn't take it into account", - parent->GetLabel(), - GetLabelOfWindowAtPoint(parent, 11, 91) - ); + INFO("Point over a hidden child control doesn't take it into account"); + CHECK( GetLabelOfWindowAtPoint(parent, 11, 91) == parent->GetLabel() ); btn2->Show(); - CPPUNIT_ASSERT_EQUAL_MESSAGE - ( - "Point over child control corresponds to the child", - btn3->GetLabel(), - GetLabelOfWindowAtPoint(parent, 31, 111) - ); + INFO("Point over child control corresponds to the child"); + CHECK( GetLabelOfWindowAtPoint(parent, 31, 111) == btn3->GetLabel() ); btn3->Disable(); - CPPUNIT_ASSERT_EQUAL_MESSAGE - ( - "Point over disabled child controls still corresponds to this child", - btn3->GetLabel(), - GetLabelOfWindowAtPoint(parent, 31, 111) - ); + INFO("Point over disabled child controls still corresponds to this child"); + CHECK( GetLabelOfWindowAtPoint(parent, 31, 111) == btn3->GetLabel() ); }