19OUString
convert(xmlChar
const *
string) {
21 CPPUNIT_ASSERT_MESSAGE(
22 "xmlChar string is not UTF-8",
23 rtl_convertStringToUString(
24 &s.pData,
reinterpret_cast<char const *
>(
string), xmlStrlen(
string),
25 RTL_TEXTENCODING_UTF8,
26 (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR
27 | RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR
28 | RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR)));
32OString oconvert(xmlChar
const *
string)
34 return reinterpret_cast<char const *
>(string);
54 std::unique_ptr<sal_uInt8[]> pBuffer(
new sal_uInt8[nSize + 1]);
57 auto pCharBuffer =
reinterpret_cast<xmlChar*
>(pBuffer.get());
58 SAL_INFO(
"test",
"XmlTestTools::parseXmlStream: pBuffer is '" << pCharBuffer <<
"'");
65 rDumper.
dump(rGDIMetaFile, aStream);
72 xmlXPathContextPtr pXmlXpathCtx = xmlXPathNewContext(pXmlDoc.get());
74 xmlXPathObjectPtr pXmlXpathObj = xmlXPathEvalExpression(BAD_CAST(rXPath.getStr()), pXmlXpathCtx);
75 xmlXPathFreeContext(pXmlXpathCtx);
86 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST(
"reqif-xhtml"), BAD_CAST(
"http://www.w3.org/1999/xhtml"));
91 CPPUNIT_ASSERT(pXmlDoc);
92 xmlXPathObjectPtr pXmlObj =
getXPathNode(pXmlDoc, rXPath);
93 CPPUNIT_ASSERT(pXmlObj);
94 xmlNodeSetPtr pXmlNodes = pXmlObj->nodesetval;
95 CPPUNIT_ASSERT_EQUAL_MESSAGE(OString(OString::Concat(
"In <") + pXmlDoc->name +
">, XPath '" + rXPath +
"' number of nodes is incorrect").getStr(),
96 1, xmlXPathNodeSetGetLength(pXmlNodes));
97 CPPUNIT_ASSERT(!rAttribute.isEmpty());
98 xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0];
99 xmlChar * prop = xmlGetProp(pXmlNode, BAD_CAST(rAttribute.getStr()));
100 OString sAttAbsent = OString::Concat(
"In <") + pXmlDoc->name +
">, XPath '" + rXPath
101 +
"' no attribute '" + rAttribute +
"' exist";
102 CPPUNIT_ASSERT_MESSAGE(sAttAbsent.getStr(), prop);
105 xmlXPathFreeObject(pXmlObj);
111 xmlXPathObjectPtr pXmlObj =
getXPathNode(pXmlDoc, rXPath);
112 switch (pXmlObj->type)
114 case XPATH_UNDEFINED:
115 CPPUNIT_FAIL(
"Undefined XPath type");
118 xmlNodeSetPtr pXmlNodes = pXmlObj->nodesetval;
120 CPPUNIT_ASSERT_MESSAGE(
121 OString(OString::Concat(
"In <") + pXmlDoc->name +
">, XPath '" + rXPath +
"' not found")
123 xmlXPathNodeSetGetLength(pXmlNodes) > 0);
125 xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0];
126 xmlNodePtr pXmlChild = pXmlNode->children;
128 while (pXmlChild && pXmlChild->type != XML_TEXT_NODE)
129 pXmlChild = pXmlChild->next;
130 if (pXmlChild && pXmlChild->type == XML_TEXT_NODE)
131 s =
convert(pXmlChild->content);
132 xmlXPathFreeObject(pXmlObj);
137 auto boolVal = pXmlObj->boolval;
138 xmlXPathFreeObject(pXmlObj);
139 return boolVal ? OUString(
"true") : OUString(
"false");
143 auto floatVal = pXmlObj->floatval;
144 xmlXPathFreeObject(pXmlObj);
145 return OUString::number(floatVal);
149 auto convertedVal =
convert(pXmlObj->stringval);
150 xmlXPathFreeObject(pXmlObj);
153#if LIBXML_VERSION < 21000 || defined(LIBXML_XPTR_LOCS_ENABLED)
156 case XPATH_LOCATIONSET:
159 case XPATH_XSLT_TREE:
160 xmlXPathFreeObject(pXmlObj);
161 CPPUNIT_FAIL(
"Unsupported XPath type");
164 CPPUNIT_FAIL(
"Invalid XPath type");
169 OUString aValue =
getXPath(pXmlDoc, rXPath, rAttribute);
170 CPPUNIT_ASSERT_EQUAL_MESSAGE(OString(OString::Concat(
"In <") + pXmlDoc->name +
">, attribute '" + rAttribute +
"' of '" + rXPath +
"' incorrect value.").getStr(),
171 rExpectedValue, aValue);
175 const std::vector<std::pair<OString, OUString>>& aPairVector)
177 for (
auto& rPair : aPairVector)
179 assertXPath(pXmlDoc, rXPath, rPair.first, rPair.second);
185 xmlXPathObjectPtr pXmlObj =
getXPathNode(pXmlDoc, rXPath);
186 xmlNodeSetPtr pXmlNodes = pXmlObj->nodesetval;
187 const int n = xmlXPathNodeSetGetLength(pXmlNodes);
188 xmlXPathFreeObject(pXmlObj);
194 CPPUNIT_ASSERT_EQUAL_MESSAGE(OString(OString::Concat(
"In <") + pXmlDoc->name +
">, XPath '" + rXPath +
"' number of nodes is incorrect").getStr(),
200 CPPUNIT_ASSERT_EQUAL_MESSAGE(OString(OString::Concat(
"In <") + pXmlDoc->name +
">, XPath contents of child does not match").getStr(), rContent,
getXPathContent(pXmlDoc, rXPath));
204 std::u16string_view rNSPrefix, std::u16string_view rNSHref)
206 xmlXPathObjectPtr pXmlObj =
getXPathNode(pXmlDoc, rXPath);
207 xmlNodeSetPtr pXmlNodes = pXmlObj->nodesetval;
208 CPPUNIT_ASSERT_MESSAGE(
209 OString(OString::Concat(
"In <") + pXmlDoc->name +
">, XPath '" + rXPath +
"' not found").getStr(),
210 xmlXPathNodeSetGetLength(pXmlNodes) > 0);
212 xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0];
214 for (xmlNsPtr pNamespace = pXmlNode->nsDef; pNamespace; pNamespace = pNamespace->next)
216 if (!pNamespace->prefix)
219 CPPUNIT_ASSERT(pNamespace->href);
220 if (rNSPrefix ==
convert(pNamespace->prefix) && rNSHref ==
convert(pNamespace->href))
226 xmlXPathFreeObject(pXmlObj);
227 CPPUNIT_ASSERT(bFound);
232#if LIBXML_VERSION >= 20703
233 xmlXPathObjectPtr pXmlObj =
getXPathNode(pXmlDoc, rXPath);
234 xmlNodeSetPtr pXmlNodes = pXmlObj->nodesetval;
235 CPPUNIT_ASSERT_EQUAL_MESSAGE(OString(OString::Concat(
"In <") + pXmlDoc->name +
">, XPath '" + rXPath +
"' number of nodes is incorrect").getStr(),
236 1, xmlXPathNodeSetGetLength(pXmlNodes));
237 xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0];
238 CPPUNIT_ASSERT_EQUAL_MESSAGE(OString(OString::Concat(
"In <") + pXmlDoc->name +
">, XPath '" + rXPath +
"' number of child-nodes is incorrect").getStr(),
239 nNumberOfChildNodes,
static_cast<int>(xmlChildElementCount(pXmlNode)));
240 xmlXPathFreeObject(pXmlObj);
244 (void)nNumberOfChildNodes;
250 xmlXPathObjectPtr pXmlObj =
getXPathNode(pXmlDoc, rXPath);
251 xmlNodeSetPtr pXmlNodes = pXmlObj->nodesetval;
252 CPPUNIT_ASSERT_EQUAL_MESSAGE(OString(OString::Concat(
"In <") + pXmlDoc->name +
">, XPath '" + rXPath +
"' number of nodes is incorrect").getStr(),
253 1, xmlXPathNodeSetGetLength(pXmlNodes));
254 xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0];
255 CPPUNIT_ASSERT_MESSAGE(OString(OString::Concat(
"In <") + pXmlDoc->name +
">, XPath '" + rXPath +
"' unexpected '" + rAttribute +
"' attribute").getStr(),
256 !xmlGetProp(pXmlNode, BAD_CAST(rAttribute.getStr())));
257 xmlXPathFreeObject(pXmlObj);
262 xmlXPathObjectPtr pXmlObj =
getXPathNode(pXmlDoc, rXPath);
263 xmlNodeSetPtr pXmlNodes = pXmlObj->nodesetval;
264 CPPUNIT_ASSERT_EQUAL_MESSAGE(OString(OString::Concat(
"In <") + pXmlDoc->name +
">, XPath '" + rXPath +
"' number of nodes is incorrect").getStr(),
266 xmlXPathNodeSetGetLength(pXmlNodes));
267 xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0];
270 for (xmlNodePtr pChild = pXmlNode->children; pChild; pChild = pChild->next)
272 if (oconvert(pChild->name) == rChildName)
279 xmlXPathFreeObject(pXmlObj);
280 CPPUNIT_ASSERT_MESSAGE(OString(OString::Concat(
"In <") + pXmlDoc->name +
">, XPath '" + rXPath
281 +
"' child '" + rChildName +
"' not found")
289 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST(
"office"),
290 BAD_CAST(
"urn:oasis:names:tc:opendocument:xmlns:office:1.0"));
291 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST(
"style"),
292 BAD_CAST(
"urn:oasis:names:tc:opendocument:xmlns:style:1.0"));
293 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST(
"text"),
294 BAD_CAST(
"urn:oasis:names:tc:opendocument:xmlns:text:1.0"));
295 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST(
"table"),
296 BAD_CAST(
"urn:oasis:names:tc:opendocument:xmlns:table:1.0"));
297 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST(
"draw"),
298 BAD_CAST(
"urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"));
299 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST(
"fo"),
300 BAD_CAST(
"urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"));
301 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST(
"config"),
302 BAD_CAST(
"urn:oasis:names:tc:opendocument:xmlns:config:1.0"));
303 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST(
"xlink"), BAD_CAST(
"http://www.w3.org/1999/xlink"));
304 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST(
"dc"), BAD_CAST(
"http://purl.org/dc/elements/1.1/"));
305 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST(
"meta"),
306 BAD_CAST(
"urn:oasis:names:tc:opendocument:xmlns:meta:1.0"));
307 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST(
"number"),
308 BAD_CAST(
"urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0"));
309 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST(
"svg"),
310 BAD_CAST(
"urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"));
311 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST(
"chart"),
312 BAD_CAST(
"urn:oasis:names:tc:opendocument:xmlns:chart:1.0"));
313 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST(
"dr3d"),
314 BAD_CAST(
"urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0"));
315 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST(
"math"),
316 BAD_CAST(
"http://www.w3.org/1998/Math/MathML"));
317 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST(
"form"),
318 BAD_CAST(
"urn:oasis:names:tc:opendocument:xmlns:form:1.0"));
319 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST(
"script"),
320 BAD_CAST(
"urn:oasis:names:tc:opendocument:xmlns:script:1.0"));
321 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST(
"ooo"),
322 BAD_CAST(
"http://openoffice.org/2004/office"));
323 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST(
"ooow"),
324 BAD_CAST(
"http://openoffice.org/2004/writer"));
325 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST(
"oooc"), BAD_CAST(
"http://openoffice.org/2004/calc"));
326 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST(
"dom"),
327 BAD_CAST(
"http://www.w3.org/2001/xml-events"));
328 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST(
"xforms"), BAD_CAST(
"http://www.w3.org/2002/xforms"));
329 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST(
"xsd"), BAD_CAST(
"http://www.w3.org/2001/XMLSchema"));
330 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST(
"xsi"),
331 BAD_CAST(
"http://www.w3.org/2001/XMLSchema-instance"));
332 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST(
"rpt"),
333 BAD_CAST(
"http://openoffice.org/2005/report"));
334 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST(
"of"),
335 BAD_CAST(
"urn:oasis:names:tc:opendocument:xmlns:of:1.2"));
336 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST(
"xhtml"), BAD_CAST(
"http://www.w3.org/1999/xhtml"));
337 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST(
"grddl"),
338 BAD_CAST(
"http://www.w3.org/2003/g/data-view#"));
339 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST(
"officeooo"),
340 BAD_CAST(
"http://openoffice.org/2009/office"));
341 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST(
"tableooo"),
342 BAD_CAST(
"http://openoffice.org/2009/table"));
343 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST(
"drawooo"),
344 BAD_CAST(
"http://openoffice.org/2010/draw"));
346 pXmlXpathCtx, BAD_CAST(
"calcext"),
347 BAD_CAST(
"urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0"));
349 pXmlXpathCtx, BAD_CAST(
"loext"),
350 BAD_CAST(
"urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0"));
352 pXmlXpathCtx, BAD_CAST(
"field"),
353 BAD_CAST(
"urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0"));
355 pXmlXpathCtx, BAD_CAST(
"formx"),
356 BAD_CAST(
"urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0"));
357 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST(
"css3t"),
358 BAD_CAST(
"http://www.w3.org/TR/css3-text/"));
359 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST(
"anim"),
360 BAD_CAST(
"urn:oasis:names:tc:opendocument:xmlns:animation:1.0"));
361 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST(
"smil"),
362 BAD_CAST(
"urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0"));
363 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST(
"presentation"),
364 BAD_CAST(
"urn:oasis:names:tc:opendocument:xmlns:presentation:1.0"));
366 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST(
"foo"),
367 BAD_CAST(
"http://example.com/"));
372 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST(
"w"),
373 BAD_CAST(
"http://schemas.openxmlformats.org/wordprocessingml/2006/main"));
374 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST(
"v"), BAD_CAST(
"urn:schemas-microsoft-com:vml"));
375 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST(
"mc"),
376 BAD_CAST(
"http://schemas.openxmlformats.org/markup-compatibility/2006"));
378 pXmlXpathCtx, BAD_CAST(
"wps"),
379 BAD_CAST(
"http://schemas.microsoft.com/office/word/2010/wordprocessingShape"));
381 pXmlXpathCtx, BAD_CAST(
"wpg"),
382 BAD_CAST(
"http://schemas.microsoft.com/office/word/2010/wordprocessingGroup"));
384 pXmlXpathCtx, BAD_CAST(
"wp"),
385 BAD_CAST(
"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"));
387 pXmlXpathCtx, BAD_CAST(
"wp14"),
388 BAD_CAST(
"http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing"));
389 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST(
"a"),
390 BAD_CAST(
"http://schemas.openxmlformats.org/drawingml/2006/main"));
391 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST(
"pic"),
392 BAD_CAST(
"http://schemas.openxmlformats.org/drawingml/2006/picture"));
393 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST(
"rels"),
394 BAD_CAST(
"http://schemas.openxmlformats.org/package/2006/relationships"));
395 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST(
"w14"),
396 BAD_CAST(
"http://schemas.microsoft.com/office/word/2010/wordml"));
397 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST(
"w15"),
398 BAD_CAST(
"http://schemas.microsoft.com/office/word/2012/wordml"));
399 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST(
"m"),
400 BAD_CAST(
"http://schemas.openxmlformats.org/officeDocument/2006/math"));
401 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST(
"ContentType"),
402 BAD_CAST(
"http://schemas.openxmlformats.org/package/2006/content-types"));
403 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST(
"lc"),
404 BAD_CAST(
"http://schemas.openxmlformats.org/drawingml/2006/lockedCanvas"));
406 pXmlXpathCtx, BAD_CAST(
"cp"),
407 BAD_CAST(
"http://schemas.openxmlformats.org/package/2006/metadata/core-properties"));
409 pXmlXpathCtx, BAD_CAST(
"extended-properties"),
410 BAD_CAST(
"http://schemas.openxmlformats.org/officeDocument/2006/extended-properties"));
412 pXmlXpathCtx, BAD_CAST(
"custom-properties"),
413 BAD_CAST(
"http://schemas.openxmlformats.org/officeDocument/2006/custom-properties"));
415 pXmlXpathCtx, BAD_CAST(
"vt"),
416 BAD_CAST(
"http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes"));
417 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST(
"dcterms"), BAD_CAST(
"http://purl.org/dc/terms/"));
418 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST(
"a14"),
419 BAD_CAST(
"http://schemas.microsoft.com/office/drawing/2010/main"));
420 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST(
"c"),
421 BAD_CAST(
"http://schemas.openxmlformats.org/drawingml/2006/chart"));
422 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST(
"x"),
423 BAD_CAST(
"http://schemas.openxmlformats.org/spreadsheetml/2006/main"));
424 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST(
"r"),
425 BAD_CAST(
"http://schemas.openxmlformats.org/officeDocument/2006/relationships"));
426 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST(
"xx"),
427 BAD_CAST(
"urn:schemas-microsoft-com:office:excel"));
428 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST(
"xdr"),
429 BAD_CAST(
"http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing"));
430 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST(
"x14"),
431 BAD_CAST(
"http://schemas.microsoft.com/office/spreadsheetml/2009/9/main"));
432 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST(
"xm"),
433 BAD_CAST(
"http://schemas.microsoft.com/office/excel/2006/main"));
434 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST(
"x12ac"),
435 BAD_CAST(
"http://schemas.microsoft.com/office/spreadsheetml/2011/1/ac"));
436 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST(
"o"),
437 BAD_CAST(
"urn:schemas-microsoft-com:office:office"));
438 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST(
"w10"),
439 BAD_CAST(
"urn:schemas-microsoft-com:office:word"));
440 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST(
"p"),
441 BAD_CAST(
"http://schemas.openxmlformats.org/presentationml/2006/main"));
442 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST(
"p14"),
443 BAD_CAST(
"http://schemas.microsoft.com/office/powerpoint/2010/main"));
444 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST(
"dgm"),
445 BAD_CAST(
"http://schemas.openxmlformats.org/drawingml/2006/diagram"));
446 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST(
"c15"),
447 BAD_CAST(
"http://schemas.microsoft.com/office/drawing/2012/chart"));
448 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST(
"xr2"),
449 BAD_CAST(
"http://schemas.microsoft.com/office/spreadsheetml/2015/revision2"));
sal_uInt64 Seek(sal_uInt64 nPos)
std::size_t ReadBytes(void *pData, std::size_t nSize)
sal_uInt64 remainingSize()
OUString const & GetURL() const
#define SAL_INFO(area, stream)
#define STREAM_SEEK_TO_BEGIN
std::unique_ptr< xmlDoc, xmlDocDeleter > xmlDocUniquePtr