LibreOffice Module test (master) 1
xmltesttools.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
9
10#include <test/xmltesttools.hxx>
11
12#include <memory>
13
14#include <vcl/mtfxmldump.hxx>
15#include <sal/log.hxx>
16
17namespace {
18
19OUString convert(xmlChar const * string) {
20 OUString s;
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)));
29 return s;
30}
31
32OString oconvert(xmlChar const * string)
33{
34 return reinterpret_cast<char const *>(string);
35}
36
37}
38
40{}
41
43{}
44
46{
47 SvFileStream aFileStream(aTempFile.GetURL(), StreamMode::READ);
48 return parseXmlStream(&aFileStream);
49}
50
52{
53 std::size_t nSize = pStream->remainingSize();
54 std::unique_ptr<sal_uInt8[]> pBuffer(new sal_uInt8[nSize + 1]);
55 pStream->ReadBytes(pBuffer.get(), nSize);
56 pBuffer[nSize] = 0;
57 auto pCharBuffer = reinterpret_cast<xmlChar*>(pBuffer.get());
58 SAL_INFO("test", "XmlTestTools::parseXmlStream: pBuffer is '" << pCharBuffer << "'");
59 return xmlDocUniquePtr(xmlParseDoc(pCharBuffer));
60}
61
63{
64 SvMemoryStream aStream;
65 rDumper.dump(rGDIMetaFile, aStream);
67 return XmlTestTools::parseXmlStream(&aStream);
68}
69
70xmlXPathObjectPtr XmlTestTools::getXPathNode(const xmlDocUniquePtr& pXmlDoc, const OString& rXPath)
71{
72 xmlXPathContextPtr pXmlXpathCtx = xmlXPathNewContext(pXmlDoc.get());
73 registerNamespaces(pXmlXpathCtx);
74 xmlXPathObjectPtr pXmlXpathObj = xmlXPathEvalExpression(BAD_CAST(rXPath.getStr()), pXmlXpathCtx);
75 xmlXPathFreeContext(pXmlXpathCtx);
76 return pXmlXpathObj;
77}
78
79void XmlTestTools::registerNamespaces(xmlXPathContextPtr& pXmlXpathCtx)
80{
81 // ooxml
83 // odf
85 // reqif-xhtml
86 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("reqif-xhtml"), BAD_CAST("http://www.w3.org/1999/xhtml"));
87}
88
89OUString XmlTestTools::getXPath(const xmlDocUniquePtr& pXmlDoc, const OString& rXPath, const OString& rAttribute)
90{
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);
103 OUString s(convert(prop));
104 xmlFree(prop);
105 xmlXPathFreeObject(pXmlObj);
106 return s;
107}
108
109OUString XmlTestTools::getXPathContent(const xmlDocUniquePtr& pXmlDoc, const OString& rXPath)
110{
111 xmlXPathObjectPtr pXmlObj = getXPathNode(pXmlDoc, rXPath);
112 switch (pXmlObj->type)
113 {
114 case XPATH_UNDEFINED:
115 CPPUNIT_FAIL("Undefined XPath type");
116 case XPATH_NODESET:
117 {
118 xmlNodeSetPtr pXmlNodes = pXmlObj->nodesetval;
119
120 CPPUNIT_ASSERT_MESSAGE(
121 OString(OString::Concat("In <") + pXmlDoc->name + ">, XPath '" + rXPath + "' not found")
122 .getStr(),
123 xmlXPathNodeSetGetLength(pXmlNodes) > 0);
124
125 xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0];
126 xmlNodePtr pXmlChild = pXmlNode->children;
127 OUString s;
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);
133 return s;
134 }
135 case XPATH_BOOLEAN:
136 {
137 auto boolVal = pXmlObj->boolval;
138 xmlXPathFreeObject(pXmlObj);
139 return boolVal ? OUString("true") : OUString("false");
140 }
141 case XPATH_NUMBER:
142 {
143 auto floatVal = pXmlObj->floatval;
144 xmlXPathFreeObject(pXmlObj);
145 return OUString::number(floatVal);
146 }
147 case XPATH_STRING:
148 {
149 auto convertedVal = convert(pXmlObj->stringval);
150 xmlXPathFreeObject(pXmlObj);
151 return convertedVal;
152 }
153#if LIBXML_VERSION < 21000 || defined(LIBXML_XPTR_LOCS_ENABLED)
154 case XPATH_POINT:
155 case XPATH_RANGE:
156 case XPATH_LOCATIONSET:
157#endif
158 case XPATH_USERS:
159 case XPATH_XSLT_TREE:
160 xmlXPathFreeObject(pXmlObj);
161 CPPUNIT_FAIL("Unsupported XPath type");
162 }
163
164 CPPUNIT_FAIL("Invalid XPath type");
165}
166
167void XmlTestTools::assertXPath(const xmlDocUniquePtr& pXmlDoc, const OString& rXPath, const OString& rAttribute, const OUString& rExpectedValue)
168{
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);
172}
173
174void XmlTestTools::assertXPathAttrs(const xmlDocUniquePtr& pXmlDoc, const OString& rXPath,
175 const std::vector<std::pair<OString, OUString>>& aPairVector)
176{
177 for (auto& rPair : aPairVector)
178 {
179 assertXPath(pXmlDoc, rXPath, rPair.first, rPair.second);
180 }
181}
182
183int XmlTestTools::countXPathNodes(const xmlDocUniquePtr& pXmlDoc, const OString& rXPath)
184{
185 xmlXPathObjectPtr pXmlObj = getXPathNode(pXmlDoc, rXPath);
186 xmlNodeSetPtr pXmlNodes = pXmlObj->nodesetval;
187 const int n = xmlXPathNodeSetGetLength(pXmlNodes);
188 xmlXPathFreeObject(pXmlObj);
189 return n;
190}
191
192void XmlTestTools::assertXPath(const xmlDocUniquePtr& pXmlDoc, const OString& rXPath, int nNumberOfNodes)
193{
194 CPPUNIT_ASSERT_EQUAL_MESSAGE(OString(OString::Concat("In <") + pXmlDoc->name + ">, XPath '" + rXPath + "' number of nodes is incorrect").getStr(),
195 nNumberOfNodes, countXPathNodes(pXmlDoc, rXPath));
196}
197
198void XmlTestTools::assertXPathContent(const xmlDocUniquePtr& pXmlDoc, const OString& rXPath, const OUString& rContent)
199{
200 CPPUNIT_ASSERT_EQUAL_MESSAGE(OString(OString::Concat("In <") + pXmlDoc->name + ">, XPath contents of child does not match").getStr(), rContent, getXPathContent(pXmlDoc, rXPath));
201}
202
203void XmlTestTools::assertXPathNSDef(const xmlDocUniquePtr& pXmlDoc, const OString& rXPath,
204 std::u16string_view rNSPrefix, std::u16string_view rNSHref)
205{
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);
211
212 xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0];
213 bool bFound = false;
214 for (xmlNsPtr pNamespace = pXmlNode->nsDef; pNamespace; pNamespace = pNamespace->next)
215 {
216 if (!pNamespace->prefix)
217 continue;
218
219 CPPUNIT_ASSERT(pNamespace->href);
220 if (rNSPrefix == convert(pNamespace->prefix) && rNSHref == convert(pNamespace->href))
221 {
222 bFound = true;
223 break;
224 }
225 }
226 xmlXPathFreeObject(pXmlObj);
227 CPPUNIT_ASSERT(bFound);
228}
229
230void XmlTestTools::assertXPathChildren(const xmlDocUniquePtr& pXmlDoc, const OString& rXPath, int nNumberOfChildNodes)
231{
232#if LIBXML_VERSION >= 20703 /* xmlChildElementCount is only available in libxml2 >= 2.7.3 */
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);
241#else
242 (void)pXmlDoc;
243 (void)rXPath;
244 (void)nNumberOfChildNodes;
245#endif
246}
247
248void XmlTestTools::assertXPathNoAttribute(const xmlDocUniquePtr& pXmlDoc, const OString& rXPath, const OString& rAttribute)
249{
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);
258}
259
260int XmlTestTools::getXPathPosition(const xmlDocUniquePtr& pXmlDoc, const OString& rXPath, std::string_view rChildName)
261{
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(),
265 1,
266 xmlXPathNodeSetGetLength(pXmlNodes));
267 xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0];
268 int nRet = 0;
269 bool bFound = false;
270 for (xmlNodePtr pChild = pXmlNode->children; pChild; pChild = pChild->next)
271 {
272 if (oconvert(pChild->name) == rChildName)
273 {
274 bFound = true;
275 break;
276 }
277 ++nRet;
278 }
279 xmlXPathFreeObject(pXmlObj);
280 CPPUNIT_ASSERT_MESSAGE(OString(OString::Concat("In <") + pXmlDoc->name + ">, XPath '" + rXPath
281 + "' child '" + rChildName + "' not found")
282 .getStr(),
283 bFound);
284 return nRet;
285}
286
287void XmlTestTools::registerODFNamespaces(xmlXPathContextPtr& pXmlXpathCtx)
288{
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"));
345 xmlXPathRegisterNs(
346 pXmlXpathCtx, BAD_CAST("calcext"),
347 BAD_CAST("urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0"));
348 xmlXPathRegisterNs(
349 pXmlXpathCtx, BAD_CAST("loext"),
350 BAD_CAST("urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0"));
351 xmlXPathRegisterNs(
352 pXmlXpathCtx, BAD_CAST("field"),
353 BAD_CAST("urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0"));
354 xmlXPathRegisterNs(
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"));
365 // user-defined
366 xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("foo"),
367 BAD_CAST("http://example.com/"));
368}
369
370void XmlTestTools::registerOOXMLNamespaces(xmlXPathContextPtr& pXmlXpathCtx)
371{
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"));
377 xmlXPathRegisterNs(
378 pXmlXpathCtx, BAD_CAST("wps"),
379 BAD_CAST("http://schemas.microsoft.com/office/word/2010/wordprocessingShape"));
380 xmlXPathRegisterNs(
381 pXmlXpathCtx, BAD_CAST("wpg"),
382 BAD_CAST("http://schemas.microsoft.com/office/word/2010/wordprocessingGroup"));
383 xmlXPathRegisterNs(
384 pXmlXpathCtx, BAD_CAST("wp"),
385 BAD_CAST("http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"));
386 xmlXPathRegisterNs(
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"));
405 xmlXPathRegisterNs(
406 pXmlXpathCtx, BAD_CAST("cp"),
407 BAD_CAST("http://schemas.openxmlformats.org/package/2006/metadata/core-properties"));
408 xmlXPathRegisterNs(
409 pXmlXpathCtx, BAD_CAST("extended-properties"),
410 BAD_CAST("http://schemas.openxmlformats.org/officeDocument/2006/extended-properties"));
411 xmlXPathRegisterNs(
412 pXmlXpathCtx, BAD_CAST("custom-properties"),
413 BAD_CAST("http://schemas.openxmlformats.org/officeDocument/2006/custom-properties"));
414 xmlXPathRegisterNs(
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"));
450}
451
452/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void dump(const GDIMetaFile &rMetaFile, SvStream &rStream)
sal_uInt64 Seek(sal_uInt64 nPos)
std::size_t ReadBytes(void *pData, std::size_t nSize)
sal_uInt64 remainingSize()
static xmlDocUniquePtr dumpAndParse(MetafileXmlDump &rDumper, const GDIMetaFile &rGDIMetaFile)
static xmlDocUniquePtr parseXml(utl::TempFileNamed const &aTempFile)
void assertXPathNoAttribute(const xmlDocUniquePtr &pXmlDoc, const OString &rXPath, const OString &rAttribute)
Assert that rXPath exists, has exactly 1 result set nodes and does not have an attribute named rAttri...
static void registerODFNamespaces(xmlXPathContextPtr &pXmlXpathCtx)
void assertXPath(const xmlDocUniquePtr &pXmlDoc, const OString &rXPath, const OString &rAttribute, const OUString &rExpectedValue)
Assert that rXPath exists, returns exactly one node, and the rXPath's attribute's value equals to the...
virtual void registerNamespaces(xmlXPathContextPtr &pXmlXpathCtx)
xmlXPathObjectPtr getXPathNode(const xmlDocUniquePtr &pXmlDoc, const OString &rXPath)
static xmlDocUniquePtr parseXmlStream(SvStream *pStream)
Return xmlDocPtr representation of the XML stream read from pStream.
int countXPathNodes(const xmlDocUniquePtr &pXmlDoc, const OString &rXPath)
Get the number of the nodes returned by the rXPath.
void assertXPathChildren(const xmlDocUniquePtr &pXmlDoc, const OString &rXPath, int nNumberOfChildNodes)
Assert that rXPath exists, and has exactly nNumberOfChildNodes child nodes.
int getXPathPosition(const xmlDocUniquePtr &pXmlDoc, const OString &rXPath, std::string_view rChildName)
Get the position of the child named rName of the parent node specified by rXPath.
void assertXPathAttrs(const xmlDocUniquePtr &pXmlDoc, const OString &rXPath, const std::vector< std::pair< OString, OUString > > &aPairVector)
OUString getXPath(const xmlDocUniquePtr &pXmlDoc, const OString &rXPath, const OString &rAttribute)
Same as the assertXPath(), but don't assert: return the string instead.
void assertXPathContent(const xmlDocUniquePtr &pXmlDoc, const OString &rXPath, const OUString &rContent)
Assert that rXPath exists, and its content equals rContent.
virtual ~XmlTestTools()
OUString getXPathContent(const xmlDocUniquePtr &pXmlDoc, const OString &rXPath)
Same as the assertXPathContent(), but don't assert: return the string instead.
void assertXPathNSDef(const xmlDocUniquePtr &pXmlDoc, const OString &rXPath, std::u16string_view rNSPrefix, std::u16string_view rNSHref)
Assert that rXPath exists and it has an rNSPrefix=rNSHref namespace definition.
static void registerOOXMLNamespaces(xmlXPathContextPtr &pXmlXpathCtx)
OUString const & GetURL() const
sal_Int64 n
#define SAL_INFO(area, stream)
convert
#define STREAM_SEEK_TO_BEGIN
unsigned char sal_uInt8
std::unique_ptr< xmlDoc, xmlDocDeleter > xmlDocUniquePtr
Definition: xmldocptr.hxx:18