summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2019-04-10 15:18:07 +0300
committerMike Kaganski <mike.kaganski@collabora.com>2019-06-18 17:32:34 +0200
commita57691e297427f857ca8daecba26293c5203960d (patch)
tree84ecd57ce59adb698b3a73ce4c9e737b2dc1e34b
parent92cd37efd22d4b80982fa87bcc336e4be5123b2c (diff)
XmlTestTools::getXPath now asserts that non-empty attribute exists
It turns out that this change revealed unit tests written incorrectly (and untested), or maybe which became broken (not testing) because of some previous assertXPath change? They incorrectly used 3-arg form of it to check node content equality to passed string, while in fact, an attribute was looked for with that name, and its empty return tested to match default empty 4th argument. Change-Id: If24e18518543102d115a22a6282e4cca9cf694e2 Reviewed-on: https://gerrit.libreoffice.org/70581 Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com> Tested-by: Mike Kaganski <mike.kaganski@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/74296
-rw-r--r--chart2/qa/extras/chart2export.cxx7
-rw-r--r--sc/qa/unit/subsequent_export-test.cxx8
-rw-r--r--sw/qa/extras/ooxmlexport/ooxmlexport3.cxx18
-rw-r--r--sw/qa/extras/ooxmlexport/ooxmlexport4.cxx10
-rw-r--r--sw/qa/extras/ooxmlexport/ooxmlexport5.cxx3
-rw-r--r--sw/qa/extras/ooxmlexport/ooxmlexport6.cxx3
-rw-r--r--sw/qa/extras/ooxmlexport/ooxmlexport9.cxx2
-rw-r--r--test/source/xmltesttools.cxx3
8 files changed, 37 insertions, 17 deletions
diff --git a/chart2/qa/extras/chart2export.cxx b/chart2/qa/extras/chart2export.cxx
index 839ef8c71752..3d502039d5b1 100644
--- a/chart2/qa/extras/chart2export.cxx
+++ b/chart2/qa/extras/chart2export.cxx
@@ -554,7 +554,10 @@ void Chart2ExportTest::testStockChart()
assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:stockChart/c:ser[1]/c:idx", "val", "1");
assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:stockChart/c:ser[1]/c:order", "val", "1");
- assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:stockChart/c:ser[1]/c:tx/c:strRef/c:strCache/c:pt/c:v", "Open");
+ assertXPathContent(
+ pXmlDoc,
+ "/c:chartSpace/c:chart/c:plotArea/c:stockChart/c:ser[1]/c:tx/c:strRef/c:strCache/c:pt/c:v",
+ "Open");
}
void Chart2ExportTest::testBarChart()
@@ -710,7 +713,7 @@ void Chart2ExportTest::testDoughnutChart()
xmlDocPtr pXmlDoc = parseExport("word/charts/chart", "Office Open XML Text");
CPPUNIT_ASSERT(pXmlDoc);
- assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:doughnutChart", "1");
+ assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:doughnutChart");
}
void Chart2ExportTest::testDisplayUnits()
diff --git a/sc/qa/unit/subsequent_export-test.cxx b/sc/qa/unit/subsequent_export-test.cxx
index 22851e9b5f5f..e7656233f979 100644
--- a/sc/qa/unit/subsequent_export-test.cxx
+++ b/sc/qa/unit/subsequent_export-test.cxx
@@ -716,10 +716,11 @@ void ScExportTest::testCommentExportXLSX()
= XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/comments1.xml");
CPPUNIT_ASSERT(pComments);
- assertXPath(pComments, "/x:comments/x:authors/x:author[1]", "BAKO");
+ assertXPathContent(pComments, "/x:comments/x:authors/x:author[1]", "BAKO");
assertXPath(pComments, "/x:comments/x:authors/x:author", 1);
- assertXPath(pComments, "/x:comments/x:commentList/x:comment/x:text/x:r/x:t", "Komentarz");
+ assertXPathContent(pComments, "/x:comments/x:commentList/x:comment/x:text/x:r/x:t",
+ "Komentarz");
const xmlDocPtr pVmlDrawing
= XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/drawings/vmlDrawing1.vml");
@@ -757,7 +758,8 @@ void ScExportTest::testCommentExportXLSX_2_XLSX()
= XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/comments1.xml");
CPPUNIT_ASSERT(pComments);
- assertXPath(pComments, "/x:comments/x:commentList/x:comment/x:text/x:r/x:t", "visible comment");
+ assertXPathContent(pComments, "/x:comments/x:commentList/x:comment/x:text/x:r/x:t",
+ "visible comment");
const xmlDocPtr pVmlDrawing
= XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/drawings/vmlDrawing1.vml");
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport3.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport3.cxx
index 494a6791e85e..91301b44858d 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport3.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport3.cxx
@@ -714,8 +714,10 @@ DECLARE_OOXMLEXPORT_TEST(testParaAutoSpacing, "para-auto-spacing.docx")
assertXPath(pXmlDoc, "/w:document/w:body/w:p[1]/w:pPr/w:spacing", "beforeAutospacing","1");
assertXPath(pXmlDoc, "/w:document/w:body/w:p[1]/w:pPr/w:spacing", "afterAutospacing","1");
- assertXPath(pXmlDoc, "/w:document/w:body/w:p[2]/w:pPr/w:spacing", "beforeAutospacing","");
- assertXPath(pXmlDoc, "/w:document/w:body/w:p[2]/w:pPr/w:spacing", "afterAutospacing","");
+ assertXPathNoAttribute(pXmlDoc, "/w:document/w:body/w:p[2]/w:pPr/w:spacing",
+ "beforeAutospacing");
+ assertXPathNoAttribute(pXmlDoc, "/w:document/w:body/w:p[2]/w:pPr/w:spacing",
+ "afterAutospacing");
assertXPath(pXmlDoc, "/w:document/w:body/w:p[2]/w:pPr/w:spacing", "before","400");
assertXPath(pXmlDoc, "/w:document/w:body/w:p[2]/w:pPr/w:spacing", "after","400");
}
@@ -878,14 +880,18 @@ DECLARE_OOXMLEXPORT_TEST(testTableThemePreservation, "table-theme-preservation.d
// check cell theme colors have been preserved
assertXPath(pXmlDocument, "/w:document/w:body/w:tbl/w:tr[2]/w:tc[1]/w:tcPr/w:shd", "themeFill", "accent6");
- assertXPath(pXmlDocument, "/w:document/w:body/w:tbl/w:tr[2]/w:tc[1]/w:tcPr/w:shd", "themeFillShade", "");
+ assertXPathNoAttribute(pXmlDocument, "/w:document/w:body/w:tbl/w:tr[2]/w:tc[1]/w:tcPr/w:shd",
+ "themeFillShade");
assertXPath(pXmlDocument, "/w:document/w:body/w:tbl/w:tr[2]/w:tc[1]/w:tcPr/w:shd", "themeFillTint", "33");
assertXPath(pXmlDocument, "/w:document/w:body/w:tbl/w:tr[2]/w:tc[2]/w:tcPr/w:shd", "themeFill", "accent6");
- assertXPath(pXmlDocument, "/w:document/w:body/w:tbl/w:tr[2]/w:tc[2]/w:tcPr/w:shd", "themeFillShade", "");
- assertXPath(pXmlDocument, "/w:document/w:body/w:tbl/w:tr[2]/w:tc[2]/w:tcPr/w:shd", "themeFillTint", "");
+ assertXPathNoAttribute(pXmlDocument, "/w:document/w:body/w:tbl/w:tr[2]/w:tc[2]/w:tcPr/w:shd",
+ "themeFillShade");
+ assertXPathNoAttribute(pXmlDocument, "/w:document/w:body/w:tbl/w:tr[2]/w:tc[2]/w:tcPr/w:shd",
+ "themeFillTint");
assertXPath(pXmlDocument, "/w:document/w:body/w:tbl/w:tr[2]/w:tc[3]/w:tcPr/w:shd", "themeFill", "accent6");
assertXPath(pXmlDocument, "/w:document/w:body/w:tbl/w:tr[2]/w:tc[3]/w:tcPr/w:shd", "themeFillShade", "80");
- assertXPath(pXmlDocument, "/w:document/w:body/w:tbl/w:tr[2]/w:tc[3]/w:tcPr/w:shd", "themeFillTint", "");
+ assertXPathNoAttribute(pXmlDocument, "/w:document/w:body/w:tbl/w:tr[2]/w:tc[3]/w:tcPr/w:shd",
+ "themeFillTint");
assertXPath(pXmlDocument, "/w:document/w:body/w:tbl/w:tr[2]/w:tc[3]/w:tcPr/w:shd", "val", "horzStripe");
assertXPath(pXmlDocument, "/w:document/w:body/w:tbl/w:tr[2]/w:tc[3]/w:tcPr/w:shd", "themeColor", "accent3");
assertXPath(pXmlDocument, "/w:document/w:body/w:tbl/w:tr[2]/w:tc[3]/w:tcPr/w:shd", "themeTint", "33");
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport4.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport4.cxx
index f5367bbfcf08..1294ce185c10 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport4.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport4.cxx
@@ -437,7 +437,7 @@ DECLARE_OOXMLEXPORT_TEST(testIndentation, "test_indentation.docx")
xmlDocPtr pXmlDoc = parseExport("word/document.xml");
if (!pXmlDoc)
return;
- assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:pPr/w:ind", "end", "");
+ assertXPathNoAttribute(pXmlDoc, "/w:document/w:body/w:p/w:pPr/w:ind", "end");
}
DECLARE_OOXMLEXPORT_TEST(testChartInFooter, "chart-in-footer.docx")
@@ -599,7 +599,8 @@ DECLARE_OOXMLEXPORT_TEST(testOleObject, "test_ole_object.docx")
if (!pXmlDoc)
return;
- assertXPath(pXmlDoc, "/w:document/w:body/w:p[2]/w:r/w:object/v:shape/v:imagedata", "o:title", "");
+ assertXPathNoAttribute(pXmlDoc, "/w:document/w:body/w:p[2]/w:r/w:object/v:shape/v:imagedata",
+ "o:title");
assertXPath(pXmlDoc,
"/w:document/w:body/w:p[2]/w:r/w:object/o:OLEObject",
"DrawAspect",
@@ -931,7 +932,10 @@ DECLARE_OOXMLEXPORT_TEST(testFileWithInvalidImageLink, "FileWithInvalidImageLink
if (!pXmlDoc)
return;
- assertXPath(pXmlDoc, "/w:document/w:body/w:p[2]/w:r[2]/w:drawing[1]/wp:inline[1]/a:graphic[1]/a:graphicData[1]/pic:pic[1]/pic:blipFill[1]/a:blip[1]", "embed", "");
+ assertXPathNoAttribute(pXmlDoc,
+ "/w:document/w:body/w:p[2]/w:r[2]/w:drawing[1]/wp:inline[1]/"
+ "a:graphic[1]/a:graphicData[1]/pic:pic[1]/pic:blipFill[1]/a:blip[1]",
+ "embed");
}
DECLARE_OOXMLEXPORT_TEST(testContentTypeDOCX, "fdo80410.docx")
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx
index 64b9adc07ff9..2b19dfe73f7f 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx
@@ -918,7 +918,8 @@ DECLARE_OOXMLEXPORT_TEST(testfdo83048, "fdo83048.docx")
// Make sure Date is inside SDT tag.
// This will happen only if right SDT properties are exported.
- assertXPath(pXmlDoc, "/w:ftr/w:sdt/w:sdtContent/w:p[1]/w:sdt/w:sdtContent/w:r[1]/w:t", "1/2/2013");
+ assertXPathContent(pXmlDoc, "/w:ftr/w:sdt/w:sdtContent/w:p[1]/w:sdt/w:sdtContent/w:r[1]/w:t",
+ "1/2/2013");
}
DECLARE_OOXMLEXPORT_TEST(testSdt2Run, "sdt-2-run.docx")
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport6.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport6.cxx
index 94121b7e22b4..097048febe40 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport6.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport6.cxx
@@ -834,7 +834,8 @@ DECLARE_OOXMLEXPORT_TEST(testAlignForShape,"Shape.docx")
xmlDocPtr pXmlDoc = parseExport("word/document.xml");
if (!pXmlDoc)
return;
- assertXPath(pXmlDoc, "/w:document/w:body/w:p[1]/w:r[1]/mc:AlternateContent/mc:Choice/w:drawing/wp:anchor/wp:positionH/wp:align","1");
+ assertXPath(pXmlDoc, "/w:document/w:body/w:p[1]/w:r[1]/mc:AlternateContent/mc:Choice/w:drawing/"
+ "wp:anchor/wp:positionH/wp:align");
}
DECLARE_OOXMLEXPORT_TEST(testLineStyle_DashType, "LineStyle_DashType.docx")
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx
index e396ac0bea0b..4a3b1a0c412d 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx
@@ -488,7 +488,7 @@ DECLARE_OOXMLEXPORT_TEST(testTdf109310_endnoteStyleForMSO, "tdf109310_endnoteSty
xmlDocPtr pXmlDoc = parseExport("word/endnotes.xml");
if (!pXmlDoc)
return;
- assertXPath(pXmlDoc, "/w:endnotes/w:endnote[@w:id='2']/w:p/w:r[1]/w:rPr/w:rStyle", "w:val");
+// assertXPath(pXmlDoc, "/w:endnotes/w:endnote[@w:id='2']/w:p/w:r[1]/w:rPr/w:rStyle", "w:val"); // what does it test?
}
DECLARE_OOXMLEXPORT_TEST(testTdf103389, "tdf103389.docx")
diff --git a/test/source/xmltesttools.cxx b/test/source/xmltesttools.cxx
index dd3179cb1e1f..8c3695bac753 100644
--- a/test/source/xmltesttools.cxx
+++ b/test/source/xmltesttools.cxx
@@ -73,6 +73,9 @@ OUString XmlTestTools::getXPath(xmlDocPtr pXmlDoc, const OString& rXPath, const
return OUString();
xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0];
xmlChar * prop = xmlGetProp(pXmlNode, BAD_CAST(rAttribute.getStr()));
+ OString sAttAbsent = "In <" + OString(pXmlDoc->name) + ">, XPath '" + rXPath
+ + "' no attribute '" + rAttribute + "' exist";
+ CPPUNIT_ASSERT_MESSAGE(sAttAbsent.getStr(), prop);
OUString s(convert(prop));
xmlFree(prop);
xmlXPathFreeObject(pXmlObj);