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

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/70581Reviewed-by: 's avatarMike Kaganski <mike.kaganski@collabora.com>
Tested-by: 's avatarMike Kaganski <mike.kaganski@collabora.com>
üst 99d641a5
......@@ -565,7 +565,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()
......@@ -721,7 +724,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()
......
......@@ -717,10 +717,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");
......@@ -758,7 +759,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");
......
......@@ -1374,7 +1374,8 @@ void SdOOXMLExportTest2::testSmartartRotation2()
xDocShRef->DoClose();
xmlDocPtr pXmlDocContent = parseExport(tempFile, "ppt/slides/slide1.xml");
assertXPath(pXmlDocContent, "/p:sld/p:cSld/p:spTree/p:grpSp/p:sp[3]/p:txBody/a:p/a:r/a:t", "Text");
assertXPathContent(pXmlDocContent,
"/p:sld/p:cSld/p:spTree/p:grpSp/p:sp[3]/p:txBody/a:p/a:r/a:t", "Text");
assertXPath(pXmlDocContent, "/p:sld/p:cSld/p:spTree/p:grpSp/p:sp[3]/p:txBody/a:bodyPr", "rot", "10800000");
double dX = getXPath(pXmlDocContent, "/p:sld/p:cSld/p:spTree/p:grpSp/p:sp[3]/p:spPr/a:xfrm/a:off", "x").toDouble();
double dY = getXPath(pXmlDocContent, "/p:sld/p:cSld/p:spTree/p:grpSp/p:sp[3]/p:spPr/a:xfrm/a:off", "y").toDouble();
......
......@@ -713,8 +713,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");
}
......@@ -877,14 +879,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");
......
......@@ -436,7 +436,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")
......@@ -598,7 +598,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",
......@@ -930,7 +931,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")
......
......@@ -930,7 +930,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")
......
......@@ -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")
......
......@@ -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")
......
......@@ -83,6 +83,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);
......
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