vcl/CppunitTest_vcl_map.mk    |   44 ++++++++++++++
 vcl/Module_vcl.mk             |    1 
 vcl/qa/cppunit/vclmaptest.cxx |  132 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 177 insertions(+)

New commits:
commit 4b4065ac96bb1417ee9d2829ca7810719108ea00
Author:     Christopher Sherlock <[email protected]>
AuthorDate: Fri Dec 26 05:43:43 2025 +1100
Commit:     Tomaž Vajngerl <[email protected]>
CommitDate: Mon Jan 5 06:19:21 2026 +0100

    vcl: introduce some OutputDevice mapping tests specifically for fn5()
    
    Change-Id: I6b5327dd9cdc584baa4df323b781e4ebe6135b34
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/196220
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <[email protected]>

diff --git a/vcl/CppunitTest_vcl_map.mk b/vcl/CppunitTest_vcl_map.mk
new file mode 100644
index 000000000000..e4252597a7ce
--- /dev/null
+++ b/vcl/CppunitTest_vcl_map.mk
@@ -0,0 +1,44 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+$(eval $(call gb_CppunitTest_CppunitTest,vcl_map))
+
+$(eval $(call gb_CppunitTest_set_include,vcl_map,\
+    -I$(SRCDIR)/vcl/inc \
+    $$(INCLUDE) \
+))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,vcl_map, \
+       vcl/qa/cppunit/vclmaptest \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,vcl_map, \
+       test \
+       tl \
+       unotest \
+       vcl \
+))
+
+$(eval $(call gb_CppunitTest_use_externals,vcl_map, \
+       boost_headers \
+))
+
+$(eval $(call gb_CppunitTest_use_sdk_api,vcl_map))
+
+$(eval $(call gb_CppunitTest_use_ure,vcl_map))
+$(eval $(call gb_CppunitTest_use_vcl,vcl_map))
+
+$(eval $(call gb_CppunitTest_use_components,vcl_map,\
+       configmgr/source/configmgr \
+       i18npool/util/i18npool \
+))
+
+$(eval $(call gb_CppunitTest_use_configuration,vcl_map))
+
+# vim: set noet sw=4 ts=4:
diff --git a/vcl/Module_vcl.mk b/vcl/Module_vcl.mk
index ed9247d58d4e..d5989ebb1147 100644
--- a/vcl/Module_vcl.mk
+++ b/vcl/Module_vcl.mk
@@ -219,6 +219,7 @@ $(eval $(call gb_Module_add_targets,vcl,\
 endif
 
 $(eval $(call gb_Module_add_check_targets,vcl,\
+    CppunitTest_vcl_map \
     CppunitTest_vcl_drawmode \
     CppunitTest_vcl_lifecycle \
     CppunitTest_vcl_bitmap_test \
diff --git a/vcl/qa/cppunit/vclmaptest.cxx b/vcl/qa/cppunit/vclmaptest.cxx
new file mode 100644
index 000000000000..d06e6f34d0f3
--- /dev/null
+++ b/vcl/qa/cppunit/vclmaptest.cxx
@@ -0,0 +1,132 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; 
fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/plugin/TestPlugIn.h>
+
+#include <tools/fract.hxx>
+
+#include <vcl/outdev.hxx>
+#include <vcl/virdev.hxx>
+#include <vcl/print.hxx>
+
+namespace
+{
+class VclMapTest : public CppUnit::TestFixture
+{
+public:
+    CPPUNIT_TEST_SUITE(VclMapTest);
+    CPPUNIT_TEST(testIdentity);
+    CPPUNIT_TEST(testSimpleUnitConversion);
+    CPPUNIT_TEST(testFractionScaling);
+    CPPUNIT_TEST(testIntermediateOverflow);
+    CPPUNIT_TEST(testRoundingBehavior);
+    CPPUNIT_TEST_SUITE_END();
+
+public:
+    void testIdentity()
+    {
+        // Test that converting to the same MapMode changes nothing
+        MapMode aMode(MapUnit::MapMM);
+        Point aPt(1234, 5678);
+
+        Point aResult = OutputDevice::LogicToLogic(aPt, aMode, aMode);
+
+        CPPUNIT_ASSERT_EQUAL(tools::Long(1234), aResult.X());
+        CPPUNIT_ASSERT_EQUAL(tools::Long(5678), aResult.Y());
+    }
+
+    void testSimpleUnitConversion()
+    {
+        // Test MM to CM (10mm = 1cm)
+        MapMode aSource(MapUnit::MapMM);
+        MapMode aDest(MapUnit::MapCM);
+        Point aPt(100, 200); // 100mm, 200mm
+
+        Point aResult = OutputDevice::LogicToLogic(aPt, aSource, aDest);
+
+        CPPUNIT_ASSERT_EQUAL(tools::Long(10), aResult.X()); // 10cm
+        CPPUNIT_ASSERT_EQUAL(tools::Long(20), aResult.Y()); // 20cm
+    }
+
+    void testFractionScaling()
+    {
+        // Converting 100 Source -> 50 Dest
+
+        MapMode aSource(MapUnit::MapMM);
+        aSource.SetScaleX(Fraction(1, 2));
+        aSource.SetScaleY(Fraction(1, 2));
+
+        MapMode aDest(MapUnit::MapMM); // Default 1:1
+
+        Point aPt(100, 200);
+        Point aResult = OutputDevice::LogicToLogic(aPt, aSource, aDest);
+
+        CPPUNIT_ASSERT_EQUAL(tools::Long(50), aResult.X());
+        CPPUNIT_ASSERT_EQUAL(tools::Long(100), aResult.Y());
+    }
+
+    void testIntermediateOverflow()
+    {
+        tools::Long nLarge = 1LL << 30;
+
+        MapMode aSource(MapUnit::MapInch);
+        aSource.SetScaleX(Fraction(nLarge, 1));
+
+        MapMode aDest(MapUnit::Map100thMM);
+        aDest.SetScaleX(Fraction(nLarge, 1));
+
+        // n1 (Coord) = 10,000,000
+        // n2 (Scale) = 2^30 (~10^9)
+        // n3 (Unit)  = 2540
+        // Product = 10^7 * 10^9 * 2540 ~= 2.5 * 10^19
+        // Max Int64 ~= 9 * 10^18
+        // THIS WILL OVERFLOW 64-bit integer logic if BigInt is missing.
+        Point aPt(10000000, 0);
+
+        Point aResult = OutputDevice::LogicToLogic(aPt, aSource, aDest);
+
+        // Expected: 10,000,000 inches = 25,400,000,000 100thMM
+        CPPUNIT_ASSERT_EQUAL(tools::Long(25400000000), aResult.X());
+    }
+
+    void testRoundingBehavior()
+    {
+        // Test that 0.5 rounds correctly (usually to nearest)
+        // Source: 100thMM
+        // Dest:   MM
+        // 150 100thMM = 1.5 MM -> Should round to 2
+        // 140 100thMM = 1.4 MM -> Should round to 1
+
+        MapMode aSource(MapUnit::Map100thMM);
+        MapMode aDest(MapUnit::MapMM);
+
+        Point aPt1(150, 140);
+        Point aResult1 = OutputDevice::LogicToLogic(aPt1, aSource, aDest);
+
+        CPPUNIT_ASSERT_EQUAL(tools::Long(2), aResult1.X()); // 1.5 -> 2
+        CPPUNIT_ASSERT_EQUAL(tools::Long(1), aResult1.Y()); // 1.4 -> 1
+
+        // Test Negative Rounding
+        Point aPt2(-150, -140);
+        Point aResult2 = OutputDevice::LogicToLogic(aPt2, aSource, aDest);
+
+        CPPUNIT_ASSERT_EQUAL(tools::Long(-2), aResult2.X()); // -1.5 -> -2
+        CPPUNIT_ASSERT_EQUAL(tools::Long(-1), aResult2.Y()); // -1.4 -> -1
+    }
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(VclMapTest);
+
+} // end anonymous namespace
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */

Reply via email to