[Libreoffice-commits] core.git: Branch 'feature/drawinglayercore' - 2 commits - include/tools tools/qa

Tomaž Vajngerl (via logerrit) logerrit at kemper.freedesktop.org
Sat May 23 09:55:36 UTC 2020


 include/tools/UnitConversion.hxx      |    6 ++++-
 tools/qa/cppunit/test_100mm2twips.cxx |   38 +++++++++++++++++++++-------------
 2 files changed, 29 insertions(+), 15 deletions(-)

New commits:
commit 9c0e8697e1c7d93df84ebc4cf0d9fc474e3be370
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Sat May 23 11:54:01 2020 +0200
Commit:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
CommitDate: Sat May 23 11:54:01 2020 +0200

     vcl: add conversion point to twip int64 & double values
    
    Change-Id: Id54d28b57c055269259317521f59d37dcdf9a456

diff --git a/include/tools/UnitConversion.hxx b/include/tools/UnitConversion.hxx
index 2093db6181d9..2585fecbb590 100644
--- a/include/tools/UnitConversion.hxx
+++ b/include/tools/UnitConversion.hxx
@@ -20,11 +20,15 @@ constexpr sal_Int64 convertMm100ToTwip(sal_Int64 n)
     return (n >= 0) ? (n * 72 + 63) / 127 : (n * 72 - 63) / 127;
 }
 
+constexpr sal_Int64 convertPointToTwip(sal_Int64 nNumber) { return nNumber * 20; }
+
 constexpr sal_Int64 convertPointToMm100(sal_Int64 nNumber)
 {
-    return convertTwipToMm100(nNumber * 20);
+    return convertTwipToMm100(convertPointToTwip(nNumber));
 }
 
+constexpr double convertPointToTwip(double fNumber) { return fNumber * 20.0; }
+
 constexpr double convertPointToMm100(double fNumber) { return fNumber * 35.27777777778; }
 
 // Convert PPT's "master unit" (1/576 inch) to twips
commit 14ac628950d5573e67df13786c88e6c3c60d53f2
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Thu May 21 11:47:34 2020 +0200
Commit:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
CommitDate: Thu May 21 11:47:34 2020 +0200

    tools: extend test for UnitConversion
    
    Change-Id: I8fbc2a83f40fb04656f690b4b63d3cac9f0410c1

diff --git a/tools/qa/cppunit/test_100mm2twips.cxx b/tools/qa/cppunit/test_100mm2twips.cxx
index 80ceda2ffb3f..010a2aab684d 100644
--- a/tools/qa/cppunit/test_100mm2twips.cxx
+++ b/tools/qa/cppunit/test_100mm2twips.cxx
@@ -23,29 +23,39 @@
 #include <cppunit/extensions/HelperMacros.h>
 
 #include <tools/helpers.hxx>
+#include <tools/UnitConversion.hxx>
 
-namespace tools
-{
-class cm2TwipsTest : public CppUnit::TestFixture
+class UnitConversionTest : public CppUnit::TestFixture
 {
 public:
-    void testConvert()
+    void testSanitiseMm100ToTwip()
+    {
+        CPPUNIT_ASSERT_EQUAL(sal_Int64(145), sanitiseMm100ToTwip(255));
+        CPPUNIT_ASSERT_EQUAL(sal_Int64(-145), sanitiseMm100ToTwip(-255));
+    }
+
+    void testConvertMm100ToTwip()
+    {
+        CPPUNIT_ASSERT_EQUAL(sal_Int64(145), convertMm100ToTwip(255));
+        CPPUNIT_ASSERT_EQUAL(sal_Int64(-145), convertMm100ToTwip(-255));
+    }
+
+    void testConvertPointToMm100()
     {
-        sal_Int32 nActual = sanitiseMm100ToTwip(255);
-        sal_Int32 nExpected = 145;
-        CPPUNIT_ASSERT_EQUAL(nExpected, nActual);
+        CPPUNIT_ASSERT_DOUBLES_EQUAL(double(599.72), convertPointToMm100(17.0), 1E-2);
+        CPPUNIT_ASSERT_EQUAL(sal_Int64(600), convertPointToMm100(sal_Int64(17)));
 
-        nActual = sanitiseMm100ToTwip(-255);
-        nExpected = -145;
-        CPPUNIT_ASSERT_EQUAL(nExpected, nActual);
+        CPPUNIT_ASSERT_DOUBLES_EQUAL(double(22930.55), convertPointToMm100(650.0), 1E-2);
+        CPPUNIT_ASSERT_EQUAL(sal_Int64(22931), convertPointToMm100(sal_Int64(650)));
     }
 
-    CPPUNIT_TEST_SUITE(cm2TwipsTest);
-    CPPUNIT_TEST(testConvert);
+    CPPUNIT_TEST_SUITE(UnitConversionTest);
+    CPPUNIT_TEST(testSanitiseMm100ToTwip);
+    CPPUNIT_TEST(testConvertMm100ToTwip);
+    CPPUNIT_TEST(testConvertPointToMm100);
     CPPUNIT_TEST_SUITE_END();
 };
 
-CPPUNIT_TEST_SUITE_REGISTRATION(cm2TwipsTest);
-} // namespace tools
+CPPUNIT_TEST_SUITE_REGISTRATION(UnitConversionTest);
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list