[Libreoffice-commits] core.git: sw/qa test/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Tue Oct 30 13:43:12 UTC 2018


 sw/qa/extras/layout/data/tdf116989.docx |binary
 sw/qa/extras/layout/layout.cxx          |   24 +++++++++++++++
 test/source/xmltesttools.cxx            |   51 +++++++++++++++++++++++---------
 3 files changed, 62 insertions(+), 13 deletions(-)

New commits:
commit ac12028bf29aad389f03a296402e7af51a86a3e6
Author:     Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Tue Oct 30 12:54:56 2018 +0300
Commit:     Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Tue Oct 30 14:42:45 2018 +0100

    tdf#116989: add unit test
    
    Change-Id: Ia8b5478b0d2a15f91add4ee76455e73c2c970392
    Reviewed-on: https://gerrit.libreoffice.org/62544
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>

diff --git a/sw/qa/extras/layout/data/tdf116989.docx b/sw/qa/extras/layout/data/tdf116989.docx
new file mode 100644
index 000000000000..498b60dbf345
Binary files /dev/null and b/sw/qa/extras/layout/data/tdf116989.docx differ
diff --git a/sw/qa/extras/layout/layout.cxx b/sw/qa/extras/layout/layout.cxx
index da45f2e9198e..40f67c84f444 100644
--- a/sw/qa/extras/layout/layout.cxx
+++ b/sw/qa/extras/layout/layout.cxx
@@ -60,6 +60,7 @@ public:
     void testTdf120287();
     void testTdf120287b();
     void testTdf120287c();
+    void testTdf116989();
 
     CPPUNIT_TEST_SUITE(SwLayoutWriter);
     CPPUNIT_TEST(testRedlineFootnotes);
@@ -92,6 +93,7 @@ public:
     CPPUNIT_TEST(testTdf120287);
     CPPUNIT_TEST(testTdf120287b);
     CPPUNIT_TEST(testTdf120287c);
+    CPPUNIT_TEST(testTdf116989);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -2583,6 +2585,28 @@ void SwLayoutWriter::testTdf120287c()
     assertXPath(pXmlDoc, "/root/page/body/txt[1]/LineBreak", 3);
 }
 
+void SwLayoutWriter::testTdf116989()
+{
+    createDoc("tdf116989.docx");
+    xmlDocPtr pXmlDoc = parseLayoutDump();
+    // FIXME: the XPath should be adjusted when the proper floating table would be imported
+    const sal_Int32 nTblTop
+        = getXPath(pXmlDoc, "/root/page[1]/footer/tab/infos/bounds", "top").toInt32();
+    const sal_Int32 nFirstPageParaCount
+        = getXPathContent(pXmlDoc, "count(/root/page[1]/body/txt)").toInt32();
+    // FIXME: should be exactly 30, when proper floating tables in footers are supported
+    CPPUNIT_ASSERT_GREATEREQUAL(sal_Int32(30), nFirstPageParaCount);
+    for (sal_Int32 i = 1; i <= nFirstPageParaCount; ++i)
+    {
+        const OString xPath = "/root/page[1]/body/txt[" + OString::number(i) + "]/infos/bounds";
+        const sal_Int32 nTxtBottom = getXPath(pXmlDoc, xPath.getStr(), "top").toInt32()
+                                     + getXPath(pXmlDoc, xPath.getStr(), "height").toInt32();
+        // No body paragraphs should overlap the table in the footer
+        CPPUNIT_ASSERT_MESSAGE(OString("testing paragraph #" + OString::number(i)).getStr(),
+                               nTxtBottom <= nTblTop);
+    }
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(SwLayoutWriter);
 CPPUNIT_PLUGIN_IMPLEMENT();
 
diff --git a/test/source/xmltesttools.cxx b/test/source/xmltesttools.cxx
index cae81afa77a3..dd3179cb1e1f 100644
--- a/test/source/xmltesttools.cxx
+++ b/test/source/xmltesttools.cxx
@@ -82,20 +82,45 @@ OUString XmlTestTools::getXPath(xmlDocPtr pXmlDoc, const OString& rXPath, const
 OUString XmlTestTools::getXPathContent(xmlDocPtr pXmlDoc, const OString& rXPath)
 {
     xmlXPathObjectPtr pXmlObj = getXPathNode(pXmlDoc, rXPath);
-    xmlNodeSetPtr pXmlNodes = pXmlObj->nodesetval;
-
-    CPPUNIT_ASSERT_MESSAGE(OString("In <" + OString(pXmlDoc->name) + ">, XPath '" + rXPath + "' not found").getStr(),
-            xmlXPathNodeSetGetLength(pXmlNodes) > 0);
+    switch (pXmlObj->type)
+    {
+        case XPATH_UNDEFINED:
+            CPPUNIT_FAIL("Undefined XPath type");
+        case XPATH_NODESET:
+        {
+            xmlNodeSetPtr pXmlNodes = pXmlObj->nodesetval;
+
+            CPPUNIT_ASSERT_MESSAGE(
+                OString("In <" + OString(pXmlDoc->name) + ">, XPath '" + rXPath + "' not found")
+                    .getStr(),
+                xmlXPathNodeSetGetLength(pXmlNodes) > 0);
+
+            xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0];
+            xmlNodePtr pXmlChild = pXmlNode->children;
+            OUString s;
+            while (pXmlChild && pXmlChild->type != XML_TEXT_NODE)
+                pXmlChild = pXmlChild->next;
+            if (pXmlChild && pXmlChild->type == XML_TEXT_NODE)
+                s = convert(pXmlChild->content);
+            xmlXPathFreeObject(pXmlObj);
+            return s;
+        }
+        case XPATH_BOOLEAN:
+            return pXmlObj->boolval ? OUString("true") : OUString("false");
+        case XPATH_NUMBER:
+            return OUString::number(pXmlObj->floatval);
+        case XPATH_STRING:
+            return convert(pXmlObj->stringval);
+        case XPATH_POINT:
+        case XPATH_RANGE:
+        case XPATH_LOCATIONSET:
+        case XPATH_USERS:
+        case XPATH_XSLT_TREE:
+            CPPUNIT_FAIL("Unsupported XPath type");
+    }
 
-    xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0];
-    xmlNodePtr pXmlChild = pXmlNode->children;
-    OUString s;
-    while (pXmlChild && pXmlChild->type != XML_TEXT_NODE)
-        pXmlChild = pXmlChild->next;
-    if (pXmlChild && pXmlChild->type == XML_TEXT_NODE)
-        s = convert(pXmlChild->content);
-    xmlXPathFreeObject(pXmlObj);
-    return s;
+    CPPUNIT_FAIL("Invalid XPath type");
+    return OUString(); // to suppress "Not all control paths return a value" warning on MSVC
 }
 
 void XmlTestTools::assertXPath(xmlDocPtr pXmlDoc, const OString& rXPath, const OString& rAttribute, const OUString& rExpectedValue)


More information about the Libreoffice-commits mailing list