Kaydet (Commit) ac12028b authored tarafından Mike Kaganski's avatar Mike Kaganski

tdf#116989: add unit test

Change-Id: Ia8b5478b0d2a15f91add4ee76455e73c2c970392
Reviewed-on: https://gerrit.libreoffice.org/62544
Tested-by: Jenkins
Reviewed-by: 's avatarMike Kaganski <mike.kaganski@collabora.com>
üst 8780fa41
......@@ -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();
......
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment