sw/qa/extras/layout/data/tdf128966-2-min.odt |binary
 sw/qa/extras/layout/layout3.cxx              |   52 +++++++++++++++++++++++++++
 2 files changed, 52 insertions(+)

New commits:
commit 4aa8fea8ac515e55bf3542e2717a3d85f1354054
Author:     Michael Stahl <michael.st...@allotropia.de>
AuthorDate: Fri Aug 25 12:09:07 2023 +0200
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Fri Aug 25 14:35:36 2023 +0200

    tdf#128966 sw: add unit test
    
    Reverting commit c303981cfd95ce1c3881366023d5495ae2edce97 it fails with:
    
      Test name: testTdf128966::TestBody
      assertion failed
      - Expression: nContentBottom > nCellCenter
      - Cell nr.: 80 id=207
    
    So probably bfa81a200ab59971b69823f9a29d8ce222d655e6 was the wrong commit
    to contain the bug id...
    
    Change-Id: I69d309d5d5ddeacf66e865db4bb666d8120e717f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156092
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>

diff --git a/sw/qa/extras/layout/data/tdf128966-2-min.odt 
b/sw/qa/extras/layout/data/tdf128966-2-min.odt
new file mode 100644
index 000000000000..d741f3d9378f
Binary files /dev/null and b/sw/qa/extras/layout/data/tdf128966-2-min.odt differ
diff --git a/sw/qa/extras/layout/layout3.cxx b/sw/qa/extras/layout/layout3.cxx
index 685e65bea085..60da1bcbd9af 100644
--- a/sw/qa/extras/layout/layout3.cxx
+++ b/sw/qa/extras/layout/layout3.cxx
@@ -120,6 +120,58 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf120287)
     assertXPath(pXmlDoc, "/root/page/body/txt[1]/SwParaPortion/SwLineLayout", 
1);
 }
 
+static auto getXPathIntAttributeValue(xmlXPathContextPtr pXmlXpathCtx, char 
const* const pXPath)
+    -> sal_Int32
+{
+    xmlXPathObjectPtr pXmlXpathObj = xmlXPathEvalExpression(BAD_CAST(pXPath), 
pXmlXpathCtx);
+    CPPUNIT_ASSERT(pXmlXpathObj->nodesetval);
+    CPPUNIT_ASSERT_EQUAL(1, 
xmlXPathNodeSetGetLength(pXmlXpathObj->nodesetval));
+    auto ret
+        = 
sal_Int32(xmlXPathCastNodeToNumber(xmlXPathNodeSetItem(pXmlXpathObj->nodesetval,
 0)));
+    xmlXPathFreeObject(pXmlXpathObj);
+    return ret;
+}
+
+CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf128966)
+{
+    createSwDoc("tdf128966-2-min.odt");
+
+    xmlDocUniquePtr pXmlDoc = parseLayoutDump();
+
+    xmlXPathObjectPtr pXmlObj
+        = getXPathNode(pXmlDoc, "/root/page/body/tab/row/cell[@rowspan > 
0][child::txt]");
+    xmlNodeSetPtr pXmlNodes = pXmlObj->nodesetval;
+    CPPUNIT_ASSERT(pXmlNodes);
+    CPPUNIT_ASSERT_GREATER(300, xmlXPathNodeSetGetLength(pXmlNodes)); // 
many...
+
+    xmlXPathContextPtr pXmlXpathCtx = xmlXPathNewContext(pXmlDoc.get());
+    registerNamespaces(pXmlXpathCtx);
+
+    for (int i = 0; i < xmlXPathNodeSetGetLength(pXmlNodes); ++i)
+    {
+        xmlNodePtr pNode = xmlXPathNodeSetItem(pXmlNodes, i);
+        xmlXPathSetContextNode(pNode, pXmlXpathCtx);
+
+        OString msg("Cell nr.: " + OString::number(i)
+                    + " id=" + 
OString::number(getXPathIntAttributeValue(pXmlXpathCtx, "@id")));
+
+        auto nCellTop = getXPathIntAttributeValue(pXmlXpathCtx, 
"infos/bounds/@top");
+        auto nCellHeight = getXPathIntAttributeValue(pXmlXpathCtx, 
"infos/bounds/@height");
+        auto nCellCenter = nCellTop + (nCellHeight / 2);
+
+        auto nContentTop
+            = getXPathIntAttributeValue(pXmlXpathCtx, 
"txt[position()=1]/infos/bounds/@top");
+        auto nContentBottom = getXPathIntAttributeValue(
+            pXmlXpathCtx, "txt[position()=last()]/infos/bounds/@bottom");
+
+        CPPUNIT_ASSERT_MESSAGE(msg.getStr(), nContentTop < nCellCenter);
+        CPPUNIT_ASSERT_MESSAGE(msg.getStr(), nContentBottom > nCellCenter);
+    }
+
+    xmlXPathFreeContext(pXmlXpathCtx);
+    xmlXPathFreeObject(pXmlObj);
+}
+
 CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf106234)
 {
     createSwDoc("tdf106234.fodt");

Reply via email to