From a18e00379ee313ccbead341ab02307aa888de138 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 20 Nov 2021 21:57:35 +0100 Subject: [PATCH] Get rid of CppUnit boilerplate in wxPoint and wxRealPoint tests Similar to the previous commit, this doesn't really change anything, but simplifies things. --- tests/geometry/point.cpp | 91 ++++++++++------------------------------ 1 file changed, 22 insertions(+), 69 deletions(-) diff --git a/tests/geometry/point.cpp b/tests/geometry/point.cpp index 30ca4181c0..aaf2867bd2 100644 --- a/tests/geometry/point.cpp +++ b/tests/geometry/point.cpp @@ -19,49 +19,7 @@ #include "wx/math.h" -// ---------------------------------------------------------------------------- -// test class -// ---------------------------------------------------------------------------- - -class PointTestCase : public CppUnit::TestCase -{ -public: - PointTestCase() { } - -private: - CPPUNIT_TEST_SUITE( PointTestCase ); - CPPUNIT_TEST( Operators ); - CPPUNIT_TEST_SUITE_END(); - - void Operators(); - - wxDECLARE_NO_COPY_CLASS(PointTestCase); -}; - -class RealPointTestCase : public CppUnit::TestCase -{ -public: - RealPointTestCase() { } - -private: - CPPUNIT_TEST_SUITE( RealPointTestCase ); - CPPUNIT_TEST( Operators ); - CPPUNIT_TEST_SUITE_END(); - - void Operators(); - - wxDECLARE_NO_COPY_CLASS(RealPointTestCase); -}; - -// register in the unnamed registry so that these tests are run by default -CPPUNIT_TEST_SUITE_REGISTRATION( PointTestCase ); -CPPUNIT_TEST_SUITE_REGISTRATION( RealPointTestCase ); - -// also include in its own registry so that these tests can be run alone -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( PointTestCase, "PointTestCase" ); -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( RealPointTestCase, "RealPointTestCase" ); - -void PointTestCase::Operators() +TEST_CASE("wxPoint::Operators", "[point]") { wxPoint p1(1,2); wxPoint p2(6,3); @@ -69,48 +27,43 @@ void PointTestCase::Operators() wxPoint p4(5,1); wxPoint p5 = p2 + p1; wxPoint p6 = p2 - p1; - CPPUNIT_ASSERT( p3.x == p5.x ); - CPPUNIT_ASSERT( p3.y == p5.y ); - CPPUNIT_ASSERT( p4.x == p6.x ); - CPPUNIT_ASSERT( p4.y == p6.y ); - CPPUNIT_ASSERT( p3 == p5 ); - CPPUNIT_ASSERT( p4 == p6 ); - CPPUNIT_ASSERT( p3 != p4 ); + CHECK( p3.x == p5.x ); + CHECK( p3.y == p5.y ); + CHECK( p4.x == p6.x ); + CHECK( p4.y == p6.y ); + CHECK( p3 == p5 ); + CHECK( p4 == p6 ); + CHECK( p3 != p4 ); p5 = p2; p5 += p1; p6 = p2; p6 -= p1; - CPPUNIT_ASSERT( p3 == p5 ); - CPPUNIT_ASSERT( p4 == p6 ); + CHECK( p3 == p5 ); + CHECK( p4 == p6 ); wxSize s(p1.x,p1.y); p5 = p2; p5 = p2 + s; p6 = p2; p6 = p2 - s; - CPPUNIT_ASSERT( p3 == p5 ); - CPPUNIT_ASSERT( p4 == p6 ); + CHECK( p3 == p5 ); + CHECK( p4 == p6 ); p5 = p2; p5 = s + p2; p6 = p2; p6 = s - p2; - CPPUNIT_ASSERT( p3 == p5 ); - CPPUNIT_ASSERT( p4 == -p6 ); + CHECK( p3 == p5 ); + CHECK( p4 == -p6 ); p5 = p2; p5 += s; p6 = p2; p6 -= s; - CPPUNIT_ASSERT( p3 == p5 ); - CPPUNIT_ASSERT( p4 == p6 ); + CHECK( p3 == p5 ); + CHECK( p4 == p6 ); } -void RealPointTestCase::Operators() +TEST_CASE("wxRealPoint::Operators", "[point]") { - const double EPSILON = 0.00001; wxRealPoint p1(1.2,3.4); wxRealPoint p2(8.7,5.4); wxRealPoint p3(9.9,8.8); wxRealPoint p4(7.5,2.0); wxRealPoint p5 = p2 + p1; wxRealPoint p6 = p2 - p1; - /* - CPPUNIT_ASSERT( p3 == p5 ); - CPPUNIT_ASSERT( p4 == p6 ); - CPPUNIT_ASSERT( p3 != p4 ); - */ - CPPUNIT_ASSERT( fabs( p3.x - p5.x ) < EPSILON ); - CPPUNIT_ASSERT( fabs( p3.y - p5.y ) < EPSILON ); - CPPUNIT_ASSERT( fabs( p4.x - p6.x ) < EPSILON ); - CPPUNIT_ASSERT( fabs( p4.y - p6.y ) < EPSILON ); + CHECK( p3.x == Approx(p5.x) ); + CHECK( p3.y == Approx(p5.y) ); + CHECK( p4.x == Approx(p6.x) ); + CHECK( p4.y == Approx(p6.y) ); + CHECK( p3.x != Approx(p4.x) ); }