diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2022-11-25 19:26:46 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2022-11-25 20:57:39 +0100 |
commit | c802c5f390a30a66118f56a01e47772a54743a6a (patch) | |
tree | 10294873ba14d82ab801ae5dc5e1d3ca95718cc8 | |
parent | 66e93c7a74af4d7078762ef4f2071e2f8ae15c27 (diff) |
Require valid attribute in getXPath
The reason for accepting empty attribute was eliminated in commit
2f91ab025de850fe5af8114565755a8deed55911 (Merge two assertXPath
overloads that both check number of nodes, Nov 25 16:36:57 2022)
Change-Id: I6cd77eb0f73650dfdafd55946b5269ffe3f0bde5
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143304
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlexport17.cxx | 6 | ||||
-rw-r--r-- | test/qa/cppunit/test_xpath.cxx | 6 | ||||
-rw-r--r-- | test/source/xmltesttools.cxx | 6 |
3 files changed, 6 insertions, 12 deletions
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx index e294a51feabb..87e7d0c68b21 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx @@ -873,7 +873,7 @@ DECLARE_OOXMLEXPORT_TEST(testTdf81507, "tdf81507.docx") CPPUNIT_ASSERT_EQUAL(OUString("0"), getXPath(pXmlDoc, "/w:document/w:body/w:p[2]/w:sdt/w:sdtPr/w:text", "multiLine")); // Ensure that we have <w:text/> - getXPath(pXmlDoc, "/w:document/w:body/w:p[3]/w:sdt/w:sdtPr/w:text", ""); + assertXPath(pXmlDoc, "/w:document/w:body/w:p[3]/w:sdt/w:sdtPr/w:text"); // Ensure that we have no <w:text/> (not quite correct case, but to ensure import/export are okay) xmlXPathObjectPtr pXmlObj = getXPathNode(pXmlDoc, "/w:document/w:body/w:p[4]/w:sdt/w:sdtPr/w:text"); @@ -974,8 +974,8 @@ DECLARE_OOXMLEXPORT_TEST(testTdf148455_2, "tdf148455_2.docx") xmlDocUniquePtr pNumberingDoc = parseExport("word/numbering.xml"); // Ensure we have empty lvlOverride for levels 0 - 1 - getXPath(pNumberingDoc, "/w:numbering/w:num[@w:numId='" + OString::number(nListId) +"']/w:lvlOverride[@w:ilvl='0']", ""); - getXPath(pNumberingDoc, "/w:numbering/w:num[@w:numId='" + OString::number(nListId) +"']/w:lvlOverride[@w:ilvl='1']", ""); + assertXPath(pNumberingDoc, "/w:numbering/w:num[@w:numId='" + OString::number(nListId) +"']/w:lvlOverride[@w:ilvl='0']"); + assertXPath(pNumberingDoc, "/w:numbering/w:num[@w:numId='" + OString::number(nListId) +"']/w:lvlOverride[@w:ilvl='1']"); // And normal override for level 2 getXPath(pNumberingDoc, "/w:numbering/w:num[@w:numId='" + OString::number(nListId) +"']/w:lvlOverride[@w:ilvl='2']/w:startOverride", "val"); } diff --git a/test/qa/cppunit/test_xpath.cxx b/test/qa/cppunit/test_xpath.cxx index c622e59617ec..599ae8dbcfc1 100644 --- a/test/qa/cppunit/test_xpath.cxx +++ b/test/qa/cppunit/test_xpath.cxx @@ -25,15 +25,13 @@ CPPUNIT_TEST_FIXTURE(TestXPath, test_getXPath) xmlDocUniquePtr pTable(xmlParseDoc(s_xml)); CPPUNIT_ASSERT(pTable); // Must get existing element content without errors - CPPUNIT_ASSERT_ASSERTION_PASS(getXPath(pTable, "/xml/item", "")); + CPPUNIT_ASSERT_ASSERTION_PASS(assertXPath(pTable, "/xml/item")); // Must error out when getting non-existing element - CPPUNIT_ASSERT_ASSERTION_FAIL(getXPath(pTable, "/xml/no_item", "")); + CPPUNIT_ASSERT_ASSERTION_FAIL(assertXPath(pTable, "/xml/no_item")); // Must get existing attribute value correctly CPPUNIT_ASSERT_ASSERTION_PASS(getXPath(pTable, "/xml/item", "attrib")); // Must fail when requested non-empty attribute doesn't exist CPPUNIT_ASSERT_ASSERTION_FAIL(getXPath(pTable, "/xml/item", "no_attrib")); - // Must return empty string if not asking an attribute, regardless what is its content - CPPUNIT_ASSERT_EQUAL(OUString(), getXPath(pTable, "/xml/item", "")); // Must properly return attribute content CPPUNIT_ASSERT_EQUAL(OUString("val"), getXPath(pTable, "/xml/item", "attrib")); // Trying to get position of missing child of a node must fail assertion diff --git a/test/source/xmltesttools.cxx b/test/source/xmltesttools.cxx index e329bc968760..7cf4bb53c6d9 100644 --- a/test/source/xmltesttools.cxx +++ b/test/source/xmltesttools.cxx @@ -88,11 +88,7 @@ OUString XmlTestTools::getXPath(const xmlDocUniquePtr& pXmlDoc, const OString& r xmlNodeSetPtr pXmlNodes = pXmlObj->nodesetval; CPPUNIT_ASSERT_EQUAL_MESSAGE(OString(OString::Concat("In <") + pXmlDoc->name + ">, XPath '" + rXPath + "' number of nodes is incorrect").getStr(), 1, xmlXPathNodeSetGetLength(pXmlNodes)); - if (rAttribute.isEmpty()) - { - xmlXPathFreeObject(pXmlObj); - return OUString(); - } + CPPUNIT_ASSERT(!rAttribute.isEmpty()); xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0]; xmlChar * prop = xmlGetProp(pXmlNode, BAD_CAST(rAttribute.getStr())); OString sAttAbsent = OString::Concat("In <") + pXmlDoc->name + ">, XPath '" + rXPath |