emfio/qa/cppunit/wmf/wmfimporttest.cxx |   26 +++++++++++++-------------
 include/test/xmltesttools.hxx          |    8 ++++++++
 test/source/xmltesttools.cxx           |    8 ++++++++
 3 files changed, 29 insertions(+), 13 deletions(-)

New commits:
commit b693d19884a09b5f841b30f2e8b586778584ed16
Author:     Ilmari Lauhakangas <ilmari.lauhakan...@libreoffice.org>
AuthorDate: Thu Sep 28 16:42:18 2023 +0300
Commit:     Ilmari Lauhakangas <ilmari.lauhakan...@libreoffice.org>
CommitDate: Fri Oct 6 12:48:17 2023 +0200

    xmltesttools: add assertXPathDoubleValue that takes a double with delta
    
    and use it to make WmfTest::testSetTextAlignWmf independent of DPI
    
    Change-Id: I2048239088a8dcc3e3ab1db96413894b5bcc56d6
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157377
    Tested-by: Jenkins
    Tested-by: Ilmari Lauhakangas <ilmari.lauhakan...@libreoffice.org>
    Reviewed-by: Ilmari Lauhakangas <ilmari.lauhakan...@libreoffice.org>

diff --git a/emfio/qa/cppunit/wmf/wmfimporttest.cxx 
b/emfio/qa/cppunit/wmf/wmfimporttest.cxx
index 172d20d99fed..de9be9ba0a52 100644
--- a/emfio/qa/cppunit/wmf/wmfimporttest.cxx
+++ b/emfio/qa/cppunit/wmf/wmfimporttest.cxx
@@ -207,70 +207,70 @@ void WmfTest::testSetTextAlignWmf()
     assertXPathContent(pDoc, "/metafile/push[2]/textarray[2]/text", 
"textalignment:default");
 
     assertXPath(pDoc, "/metafile/push[2]/textalign[3]", "align", "top");
-    assertXPath(pDoc, "/metafile/push[2]/textarray[3]", "x", "12700");
+    assertXPathDoubleValue(pDoc, "/metafile/push[2]/textarray[3]", "x", 12700, 
30);
     assertXPath(pDoc, "/metafile/push[2]/textarray[3]", "y", "212");
     assertXPathContent(pDoc, "/metafile/push[2]/textarray[3]/text", 
"textalignment:0x00");
 
     assertXPath(pDoc, "/metafile/push[2]/textalign[4]", "align", "top");
-    assertXPath(pDoc, "/metafile/push[2]/textarray[4]", "x", "12026");
+    assertXPathDoubleValue(pDoc, "/metafile/push[2]/textarray[4]", "x", 12026, 
30);
     assertXPath(pDoc, "/metafile/push[2]/textarray[4]", "y", "423");
     assertXPathContent(pDoc, "/metafile/push[2]/textarray[4]/text", 
"textalignment:0x02");
 
     assertXPath(pDoc, "/metafile/push[2]/textalign[5]", "align", "top");
     // Fails without the fix: Expected: 12026, Actual: 12350
-    assertXPath(pDoc, "/metafile/push[2]/textarray[5]", "x", "12026");
+    assertXPathDoubleValue(pDoc, "/metafile/push[2]/textarray[5]", "x", 12026, 
30);
     assertXPath(pDoc, "/metafile/push[2]/textarray[5]", "y", "635");
     assertXPathContent(pDoc, "/metafile/push[2]/textarray[5]/text", 
"textalignment:0x04");
 
     assertXPath(pDoc, "/metafile/push[2]/textalign[6]", "align", "top");
-    assertXPath(pDoc, "/metafile/push[2]/textarray[6]", "x", "12363");
+    assertXPathDoubleValue(pDoc, "/metafile/push[2]/textarray[6]", "x", 12363, 
30);
     assertXPath(pDoc, "/metafile/push[2]/textarray[6]", "y", "847");
     assertXPathContent(pDoc, "/metafile/push[2]/textarray[6]/text", 
"textalignment:0x06");
 
     assertXPath(pDoc, "/metafile/push[2]/textalign[7]", "align", "top");
-    assertXPath(pDoc, "/metafile/push[2]/textarray[7]", "x", "12700");
+    assertXPathDoubleValue(pDoc, "/metafile/push[2]/textarray[7]", "x", 12700, 
30);
     assertXPath(pDoc, "/metafile/push[2]/textarray[7]", "y", "1058");
     assertXPathContent(pDoc, "/metafile/push[2]/textarray[7]/text", 
"textalignment:0x08");
 
     assertXPath(pDoc, "/metafile/push[2]/textalign[8]", "align", "top");
-    assertXPath(pDoc, "/metafile/push[2]/textarray[8]", "x", "12026");
+    assertXPathDoubleValue(pDoc, "/metafile/push[2]/textarray[8]", "x", 12026, 
30);
     assertXPath(pDoc, "/metafile/push[2]/textarray[8]", "y", "1270");
     assertXPathContent(pDoc, "/metafile/push[2]/textarray[8]/text", 
"textalignment:0x0A");
 
     assertXPath(pDoc, "/metafile/push[2]/textalign[9]", "align", "bottom");
     // Fails without the fix: Expected: 12026, Actual: 12350
-    assertXPath(pDoc, "/metafile/push[2]/textarray[9]", "x", "12026");
+    assertXPathDoubleValue(pDoc, "/metafile/push[2]/textarray[9]", "x", 12026, 
30);
     assertXPath(pDoc, "/metafile/push[2]/textarray[9]", "y", "1482");
     assertXPathContent(pDoc, "/metafile/push[2]/textarray[9]/text", 
"textalignment:0x0C");
 
     assertXPath(pDoc, "/metafile/push[2]/textalign[10]", "align", "bottom");
-    assertXPath(pDoc, "/metafile/push[2]/textarray[10]", "x", "12363");
+    assertXPathDoubleValue(pDoc, "/metafile/push[2]/textarray[10]", "x", 
12363, 30);
     assertXPath(pDoc, "/metafile/push[2]/textarray[10]", "y", "1693");
     assertXPathContent(pDoc, "/metafile/push[2]/textarray[10]/text", 
"textalignment:0x0E");
 
     assertXPath(pDoc, "/metafile/push[2]/textalign[11]", "align", "bottom");
-    assertXPath(pDoc, "/metafile/push[2]/textarray[11]", "x", "12700");
+    assertXPathDoubleValue(pDoc, "/metafile/push[2]/textarray[11]", "x", 
12700, 30);
     assertXPath(pDoc, "/metafile/push[2]/textarray[11]", "y", "1905");
     assertXPathContent(pDoc, "/metafile/push[2]/textarray[11]/text", 
"textalignment:0x10");
 
     assertXPath(pDoc, "/metafile/push[2]/textalign[12]", "align", "bottom");
-    assertXPath(pDoc, "/metafile/push[2]/textarray[12]", "x", "12026");
+    assertXPathDoubleValue(pDoc, "/metafile/push[2]/textarray[12]", "x", 
12026, 30);
     assertXPath(pDoc, "/metafile/push[2]/textarray[12]", "y", "2117");
     assertXPathContent(pDoc, "/metafile/push[2]/textarray[12]/text", 
"textalignment:0x12");
 
     assertXPath(pDoc, "/metafile/push[2]/textalign[13]", "align", "bottom");
     // Fails without the fix: Expected: 12026, Actual: 12350
-    assertXPath(pDoc, "/metafile/push[2]/textarray[13]", "x", "12026");
+    assertXPathDoubleValue(pDoc, "/metafile/push[2]/textarray[13]", "x", 
12026, 30);
     assertXPath(pDoc, "/metafile/push[2]/textarray[13]", "y", "2328");
     assertXPathContent(pDoc, "/metafile/push[2]/textarray[13]/text", 
"textalignment:0x14");
 
     assertXPath(pDoc, "/metafile/push[2]/textalign[14]", "align", "bottom");
-    assertXPath(pDoc, "/metafile/push[2]/textarray[14]", "x", "12363");
+    assertXPathDoubleValue(pDoc, "/metafile/push[2]/textarray[14]", "x", 
12363, 30);
     assertXPath(pDoc, "/metafile/push[2]/textarray[14]", "y", "2540");
     assertXPathContent(pDoc, "/metafile/push[2]/textarray[14]/text", 
"textalignment:0x16");
 
     assertXPath(pDoc, "/metafile/push[2]/textalign[15]", "align", "bottom");
-    assertXPath(pDoc, "/metafile/push[2]/textarray[15]", "x", "12700");
+    assertXPathDoubleValue(pDoc, "/metafile/push[2]/textarray[15]", "x", 
12700, 30);
     assertXPath(pDoc, "/metafile/push[2]/textarray[15]", "y", "2752");
     assertXPathContent(pDoc, "/metafile/push[2]/textarray[15]/text", 
"textalignment:0x18");
 }
diff --git a/include/test/xmltesttools.hxx b/include/test/xmltesttools.hxx
index 09f06af5eb0d..d18b5d51e813 100644
--- a/include/test/xmltesttools.hxx
+++ b/include/test/xmltesttools.hxx
@@ -73,6 +73,14 @@ protected:
                               const OUString& rExpectedValue);
     void          assertXPathAttrs(const xmlDocUniquePtr& pXmlDoc, const 
OString& rXPath,
                           const std::vector<std::pair<OString, OUString>>& 
aPairVector);
+
+    /**
+     * Given a double for the rExpected value, assert that rXPath exists, 
returns exactly one node,
+     * and the rXPath's attribute's value matches the rExpected value within 
tolerance provided
+     * by delta. This is used to account for HiDPI scaling.
+     */
+    void          assertXPathDoubleValue(const xmlDocUniquePtr& pXmlDoc, const 
OString& rXPath, const OString& rAttribute,
+                              double expectedValue, double delta);
     /**
      * Assert that rXPath exists, and returns exactly nNumberOfNodes nodes (1 
by default).
      * Also useful for checking that we do _not_ export some node 
(nNumberOfNodes == 0).
diff --git a/test/source/xmltesttools.cxx b/test/source/xmltesttools.cxx
index db743e5688aa..8f96a399caff 100644
--- a/test/source/xmltesttools.cxx
+++ b/test/source/xmltesttools.cxx
@@ -171,6 +171,14 @@ void XmlTestTools::assertXPath(const xmlDocUniquePtr& 
pXmlDoc, const OString& rX
                                  rExpectedValue, aValue);
 }
 
+void XmlTestTools::assertXPathDoubleValue(const xmlDocUniquePtr& pXmlDoc, 
const OString& rXPath, const OString& rAttribute, double expectedValue, double 
delta)
+{
+    OUString aValue = getXPath(pXmlDoc, rXPath, rAttribute);
+    double pathValue = aValue.toDouble();
+    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(std::string("In <") + 
std::string(pXmlDoc->name ? pXmlDoc->name : "") + ">, attribute '" + 
std::string(rAttribute) + "' of '" + std::string(rXPath) + "' incorrect value.",
+                                         expectedValue, pathValue, delta);
+}
+
 void XmlTestTools::assertXPathAttrs(const xmlDocUniquePtr& pXmlDoc, const 
OString& rXPath,
                                     const std::vector<std::pair<OString, 
OUString>>& aPairVector)
 {

Reply via email to