From 187d7f8f527217c1f958feec7d3a83f866a8e477 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Thu, 6 Oct 2016 16:34:21 +0200 Subject: CPPUNIT_ASSERT[_DOUBLES]_EQUAL Change-Id: I417cea926abcc511e74a090ee90a851c138ac0c0 --- basegfx/test/basegfx2d.cxx | 81 +++++++++++++++++++++------------- basegfx/test/basegfxtools.cxx | 3 +- sdext/source/pdfimport/test/tests.cxx | 11 +++-- test/source/sheet/xdatapilottable2.cxx | 3 +- vcl/qa/cppunit/mapmode.cxx | 8 ++-- 5 files changed, 63 insertions(+), 43 deletions(-) diff --git a/basegfx/test/basegfx2d.cxx b/basegfx/test/basegfx2d.cxx index fbc093052a69..502f7844c7f4 100644 --- a/basegfx/test/basegfx2d.cxx +++ b/basegfx/test/basegfx2d.cxx @@ -440,37 +440,57 @@ public: { B2DHomMatrix mat; mat.rotate(90*F_PI180); - CPPUNIT_ASSERT_MESSAGE("rotate pi/2 yields exact matrix", - mat.get(0,0) == 0.0 && - mat.get(0,1) == -1.0 && - mat.get(0,2) == 0.0 && - mat.get(1,0) == 1.0 && - mat.get(1,1) == 0.0 && - mat.get(1,2) == 0.0); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( + "rotate pi/2 yields exact matrix", 0.0, mat.get(0,0), 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( + "rotate pi/2 yields exact matrix", -1.0, mat.get(0,1), 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( + "rotate pi/2 yields exact matrix", 0.0, mat.get(0,2), 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( + "rotate pi/2 yields exact matrix", 1.0, mat.get(1,0), 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( + "rotate pi/2 yields exact matrix", 0.0, mat.get(1,1), 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( + "rotate pi/2 yields exact matrix", 0.0, mat.get(1,2), 1E-12); mat.rotate(90*F_PI180); - CPPUNIT_ASSERT_MESSAGE("rotate pi yields exact matrix", - mat.get(0,0) == -1.0 && - mat.get(0,1) == 0.0 && - mat.get(0,2) == 0.0 && - mat.get(1,0) == 0.0 && - mat.get(1,1) == -1.0 && - mat.get(1,2) == 0.0); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( + "rotate pi yields exact matrix", -1.0, mat.get(0,0), 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( + "rotate pi yields exact matrix", 0.0, mat.get(0,1), 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( + "rotate pi yields exact matrix", 0.0, mat.get(0,2), 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( + "rotate pi yields exact matrix", 0.0, mat.get(1,0), 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( + "rotate pi yields exact matrix", -1.0, mat.get(1,1), 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( + "rotate pi yields exact matrix", 0.0, mat.get(1,2), 1E-12); mat.rotate(90*F_PI180); - CPPUNIT_ASSERT_MESSAGE("rotate 3/2 pi yields exact matrix", - mat.get(0,0) == 0.0 && - mat.get(0,1) == 1.0 && - mat.get(0,2) == 0.0 && - mat.get(1,0) == -1.0 && - mat.get(1,1) == 0.0 && - mat.get(1,2) == 0.0); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( + "rotate 3/2 pi yields exact matrix", 0.0, mat.get(0,0), 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( + "rotate 3/2 pi yields exact matrix", 1.0, mat.get(0,1), 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( + "rotate 3/2 pi yields exact matrix", 0.0, mat.get(0,2), 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( + "rotate 3/2 pi yields exact matrix", -1.0, mat.get(1,0), 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( + "rotate 3/2 pi yields exact matrix", 0.0, mat.get(1,1), 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( + "rotate 3/2 pi yields exact matrix", 0.0, mat.get(1,2), 1E-12); mat.rotate(90*F_PI180); - CPPUNIT_ASSERT_MESSAGE("rotate 2 pi yields exact matrix", - mat.get(0,0) == 1.0 && - mat.get(0,1) == 0.0 && - mat.get(0,2) == 0.0 && - mat.get(1,0) == 0.0 && - mat.get(1,1) == 1.0 && - mat.get(1,2) == 0.0); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( + "rotate 2 pi yields exact matrix", 1.0, mat.get(0,0), 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( + "rotate 2 pi yields exact matrix", 0.0, mat.get(0,1), 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( + "rotate 2 pi yields exact matrix", 0.0, mat.get(0,2), 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( + "rotate 2 pi yields exact matrix", 0.0, mat.get(1,0), 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( + "rotate 2 pi yields exact matrix", 1.0, mat.get(1,1), 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( + "rotate 2 pi yields exact matrix", 0.0, mat.get(1,2), 1E-12); } void translate() @@ -661,9 +681,10 @@ public: double fDRot; double fDShX; aTest.decompose(aDScale, aDTrans, fDRot, fDShX); - CPPUNIT_ASSERT_MESSAGE("decompose: error test J1", aDScale.getX() == 6425 && aDScale.getY() == 3938); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("decompose: error test J1", 6425.0, aDScale.getX(), 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("decompose: error test J1", 3938.0, aDScale.getY(), 1E-12); CPPUNIT_ASSERT_MESSAGE("decompose: error test J1", aDTrans.getX() == 10482 && aDTrans.getY() == 4921); - CPPUNIT_ASSERT_MESSAGE("decompose: error test J1", fDRot == 180*F_PI180); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("decompose: error test J1", 180*F_PI180, fDRot, 1E-12 ); } // Change the following lines only, if you add, remove or rename diff --git a/basegfx/test/basegfxtools.cxx b/basegfx/test/basegfxtools.cxx index 7d27fa50eb44..dc0dfb9152f9 100644 --- a/basegfx/test/basegfxtools.cxx +++ b/basegfx/test/basegfxtools.cxx @@ -73,7 +73,8 @@ public: CPPUNIT_ASSERT_MESSAGE("0.51", nIndex==1 && fTools::equal(fAlpha,1.0)); std::tie(nIndex,fAlpha) = maKeyStops.lerp(1.0); - CPPUNIT_ASSERT_MESSAGE("0.51", nIndex==1 && fAlpha==1.0); + CPPUNIT_ASSERT_EQUAL_MESSAGE("0.51", std::ptrdiff_t(1), nIndex); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("0.51", 1.0, fAlpha, 1E-12); } // Change the following lines only, if you add, remove or rename diff --git a/sdext/source/pdfimport/test/tests.cxx b/sdext/source/pdfimport/test/tests.cxx index f24a8b4cef73..091f6432bb35 100644 --- a/sdext/source/pdfimport/test/tests.cxx +++ b/sdext/source/pdfimport/test/tests.cxx @@ -239,12 +239,11 @@ namespace } else { - CPPUNIT_ASSERT_MESSAGE( "Dash array consists of four entries", - rContext.DashArray.size() == 4 && - rtl::math::approxEqual(rContext.DashArray[0],14.3764) && - rContext.DashArray[0] == rContext.DashArray[1] && - rContext.DashArray[1] == rContext.DashArray[2] && - rContext.DashArray[2] == rContext.DashArray[3] ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Dash array consists of four entries", std::vector::size_type(4), rContext.DashArray.size()); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 14.3764, rContext.DashArray[0], 1E-12 ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( rContext.DashArray[0], rContext.DashArray[1], 1E-12 ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( rContext.DashArray[1], rContext.DashArray[2], 1E-12 ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( rContext.DashArray[2], rContext.DashArray[3], 1E-12 ); CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line color is black", 1.0, rContext.LineColor.Alpha, 0.00000001); CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line color is black", 0.0, rContext.LineColor.Blue, 0.00000001); diff --git a/test/source/sheet/xdatapilottable2.cxx b/test/source/sheet/xdatapilottable2.cxx index 7be89cbd6883..235fa5090878 100644 --- a/test/source/sheet/xdatapilottable2.cxx +++ b/test/source/sheet/xdatapilottable2.cxx @@ -88,8 +88,7 @@ void XDataPilotTable2::testGetDrillDownData() } } - std::cout << "Sum: " << sum << "; nVal: " << nVal << std::endl; - CPPUNIT_ASSERT(sum == nVal); + CPPUNIT_ASSERT_DOUBLES_EQUAL(nVal, sum, 1E-12); } diff --git a/vcl/qa/cppunit/mapmode.cxx b/vcl/qa/cppunit/mapmode.cxx index d4c7e820d4a6..94e6d4be321c 100644 --- a/vcl/qa/cppunit/mapmode.cxx +++ b/vcl/qa/cppunit/mapmode.cxx @@ -45,17 +45,17 @@ void VclMapModeTest::testMultiplier() aMapMode.SetMapUnit( MapUnit::MapCM ); CPPUNIT_ASSERT_MESSAGE( "Map mode is MapUnit::MapCM, multiplier should be 1000", aMapMode.GetUnitMultiplier() == 1000 ); aMapMode.SetMapUnit( MapUnit::Map1000thInch ); - CPPUNIT_ASSERT_MESSAGE( "Map mode is MapUnit::Map1000thInch, multiplier should be 2.54", aMapMode.GetUnitMultiplier() == 2.54 ); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Map mode is MapUnit::Map1000thInch, multiplier should be 2.54", 2.54, aMapMode.GetUnitMultiplier(), 1E-12 ); aMapMode.SetMapUnit( MapUnit::Map100thInch ); - CPPUNIT_ASSERT_MESSAGE( "Map mode is MapUnit::Map100thInch, multiplier should be 2.54", aMapMode.GetUnitMultiplier() == 25.4 ); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Map mode is MapUnit::Map100thInch, multiplier should be 2.54", 25.4, aMapMode.GetUnitMultiplier(), 1E-12 ); aMapMode.SetMapUnit( MapUnit::Map10thInch ); CPPUNIT_ASSERT_MESSAGE( "Map mode is MapUnit::Map10thInch, multiplier should be 254", aMapMode.GetUnitMultiplier() == 254 ); aMapMode.SetMapUnit( MapUnit::MapInch ); CPPUNIT_ASSERT_MESSAGE( "Map mode is MapUnit::MapInch, multiplier should be 2540", aMapMode.GetUnitMultiplier() == 2540 ); aMapMode.SetMapUnit( MapUnit::MapTwip ); - CPPUNIT_ASSERT_MESSAGE( "Map mode is MapUnit::MapTwip, multiplier should be 1.76388889", aMapMode.GetUnitMultiplier() == 1.76388889 ); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Map mode is MapUnit::MapTwip, multiplier should be 1.76388889", 1.76388889, aMapMode.GetUnitMultiplier(), 1E-12 ); aMapMode.SetMapUnit( MapUnit::MapPoint ); - CPPUNIT_ASSERT_MESSAGE( "Map mode is MapUnit::MapPoint, multiplier should be 35.27777778", aMapMode.GetUnitMultiplier() == 35.27777778 ); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Map mode is MapUnit::MapPoint, multiplier should be 35.27777778", 35.27777778, aMapMode.GetUnitMultiplier(), 1E-12 ); } CPPUNIT_TEST_SUITE_REGISTRATION(VclMapModeTest); -- cgit