From 17f524a37c81a05e6d448a7186df858a69ada635 Mon Sep 17 00:00:00 2001 From: Mike Kaganski Date: Tue, 17 Aug 2021 11:18:39 +0300 Subject: Fix o3tl::convert for Rectangle, to operate on right/bottom values ... instead of using confusing/ambiguous size having two interpretations. This reverts some of the unit test changes made in commit fa339b3adb53300ae68913bed87e18caf9f2e262. Change-Id: Ic56417703e32c1d92bcee76ad8ff494824bd4a1f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120564 Tested-by: Jenkins Reviewed-by: Mike Kaganski --- tools/qa/cppunit/test_rectangle.cxx | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'tools/qa/cppunit') diff --git a/tools/qa/cppunit/test_rectangle.cxx b/tools/qa/cppunit/test_rectangle.cxx index 29aa6cde94df..e213ed28daf8 100644 --- a/tools/qa/cppunit/test_rectangle.cxx +++ b/tools/qa/cppunit/test_rectangle.cxx @@ -68,6 +68,30 @@ void Test::test_rectangle() aRect2.SetSize(Size(-1, -2)); CPPUNIT_ASSERT_EQUAL(aRect, aRect2); } + + { + constexpr tools::Rectangle aRectTwip(100, 100, 100, 100); + constexpr tools::Rectangle aRectMm100( + o3tl::convert(aRectTwip, o3tl::Length::twip, o3tl::Length::mm100)); + static_assert(!aRectMm100.IsEmpty()); + // Make sure that we use coordinates for conversion, not width/height: + // the latter is ambiguous, and e.g. GetWidth(aRectTwip) gives 1, which + // would had been converted to 2, resulting in different LR coordinates + static_assert(aRectMm100.Left() == aRectMm100.Right()); + static_assert(aRectMm100.Top() == aRectMm100.Bottom()); + } + + { + constexpr tools::Rectangle aRectTwip(1, 1); + constexpr tools::Rectangle aRectMm100( + o3tl::convert(aRectTwip, o3tl::Length::twip, o3tl::Length::mm100)); + // Make sure that result keeps the empty flag + static_assert(aRectMm100.IsEmpty()); + static_assert(aRectMm100.IsWidthEmpty()); + static_assert(aRectMm100.IsHeightEmpty()); + static_assert(aRectMm100.GetWidth() == 0); + static_assert(aRectMm100.GetHeight() == 0); + } } CPPUNIT_TEST_SUITE_REGISTRATION(Test); -- cgit v1.2.3