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 
17 namespace {
18 
19 OUString 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 
32 OString 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);
66  aStream.Seek(STREAM_SEEK_TO_BEGIN);
67  return XmlTestTools::parseXmlStream(&aStream);
68 }
69 
70 xmlXPathObjectPtr 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 
79 void XmlTestTools::registerNamespaces(xmlXPathContextPtr& /*pXmlXpathCtx*/)
80 {
81 }
82 
83 OUString XmlTestTools::getXPath(const xmlDocUniquePtr& pXmlDoc, const OString& rXPath, const OString& rAttribute)
84 {
85  CPPUNIT_ASSERT(pXmlDoc);
86  xmlXPathObjectPtr pXmlObj = getXPathNode(pXmlDoc, rXPath);
87  CPPUNIT_ASSERT(pXmlObj);
88  xmlNodeSetPtr pXmlNodes = pXmlObj->nodesetval;
89  CPPUNIT_ASSERT_EQUAL_MESSAGE(OString(OString::Concat("In <") + pXmlDoc->name + ">, XPath '" + rXPath + "' number of nodes is incorrect").getStr(),
90  1, xmlXPathNodeSetGetLength(pXmlNodes));
91  if (rAttribute.isEmpty())
92  {
93  xmlXPathFreeObject(pXmlObj);
94  return OUString();
95  }
96  xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0];
97  xmlChar * prop = xmlGetProp(pXmlNode, BAD_CAST(rAttribute.getStr()));
98  OString sAttAbsent = OString::Concat("In <") + pXmlDoc->name + ">, XPath '" + rXPath
99  + "' no attribute '" + rAttribute + "' exist";
100  CPPUNIT_ASSERT_MESSAGE(sAttAbsent.getStr(), prop);
101  OUString s(convert(prop));
102  xmlFree(prop);
103  xmlXPathFreeObject(pXmlObj);
104  return s;
105 }
106 
107 OUString XmlTestTools::getXPathContent(const xmlDocUniquePtr& pXmlDoc, const OString& rXPath)
108 {
109  xmlXPathObjectPtr pXmlObj = getXPathNode(pXmlDoc, rXPath);
110  switch (pXmlObj->type)
111  {
112  case XPATH_UNDEFINED:
113  CPPUNIT_FAIL("Undefined XPath type");
114  case XPATH_NODESET:
115  {
116  xmlNodeSetPtr pXmlNodes = pXmlObj->nodesetval;
117 
118  CPPUNIT_ASSERT_MESSAGE(
119  OString(OString::Concat("In <") + pXmlDoc->name + ">, XPath '" + rXPath + "' not found")
120  .getStr(),
121  xmlXPathNodeSetGetLength(pXmlNodes) > 0);
122 
123  xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0];
124  xmlNodePtr pXmlChild = pXmlNode->children;
125  OUString s;
126  while (pXmlChild && pXmlChild->type != XML_TEXT_NODE)
127  pXmlChild = pXmlChild->next;
128  if (pXmlChild && pXmlChild->type == XML_TEXT_NODE)
129  s = convert(pXmlChild->content);
130  xmlXPathFreeObject(pXmlObj);
131  return s;
132  }
133  case XPATH_BOOLEAN:
134  {
135  auto boolVal = pXmlObj->boolval;
136  xmlXPathFreeObject(pXmlObj);
137  return boolVal ? OUString("true") : OUString("false");
138  }
139  case XPATH_NUMBER:
140  {
141  auto floatVal = pXmlObj->floatval;
142  xmlXPathFreeObject(pXmlObj);
143  return OUString::number(floatVal);
144  }
145  case XPATH_STRING:
146  {
147  auto convertedVal = convert(pXmlObj->stringval);
148  xmlXPathFreeObject(pXmlObj);
149  return convertedVal;
150  }
151  case XPATH_POINT:
152  case XPATH_RANGE:
153  case XPATH_LOCATIONSET:
154  case XPATH_USERS:
155  case XPATH_XSLT_TREE:
156  xmlXPathFreeObject(pXmlObj);
157  CPPUNIT_FAIL("Unsupported XPath type");
158  }
159 
160  CPPUNIT_FAIL("Invalid XPath type");
161 }
162 
163 void XmlTestTools::assertXPath(const xmlDocUniquePtr& pXmlDoc, const OString& rXPath)
164 {
165  getXPath(pXmlDoc, rXPath, ""); // it asserts that rXPath exists, and returns exactly one node
166 }
167 
168 void XmlTestTools::assertXPath(const xmlDocUniquePtr& pXmlDoc, const OString& rXPath, const OString& rAttribute, const OUString& rExpectedValue)
169 {
170  OUString aValue = getXPath(pXmlDoc, rXPath, rAttribute);
171  CPPUNIT_ASSERT_EQUAL_MESSAGE(OString(OString::Concat("In <") + pXmlDoc->name + ">, attribute '" + rAttribute + "' of '" + rXPath + "' incorrect value.").getStr(),
172  rExpectedValue, aValue);
173 }
174 
175 void XmlTestTools::assertXPathAttrs(const xmlDocUniquePtr& pXmlDoc, const OString& rXPath,
176  const std::vector<std::pair<OString, OUString>>& aPairVector)
177 {
178  for (auto& rPair : aPairVector)
179  {
180  assertXPath(pXmlDoc, rXPath, rPair.first, rPair.second);
181  }
182 }
183 
184 void XmlTestTools::assertXPath(const xmlDocUniquePtr& pXmlDoc, const OString& rXPath, int nNumberOfNodes)
185 {
186  xmlXPathObjectPtr pXmlObj = getXPathNode(pXmlDoc, rXPath);
187  xmlNodeSetPtr pXmlNodes = pXmlObj->nodesetval;
188  CPPUNIT_ASSERT_EQUAL_MESSAGE(OString(OString::Concat("In <") + pXmlDoc->name + ">, XPath '" + rXPath + "' number of nodes is incorrect").getStr(),
189  nNumberOfNodes, xmlXPathNodeSetGetLength(pXmlNodes));
190  xmlXPathFreeObject(pXmlObj);
191 }
192 
193 void XmlTestTools::assertXPathContent(const xmlDocUniquePtr& pXmlDoc, const OString& rXPath, const OUString& rContent)
194 {
195  CPPUNIT_ASSERT_EQUAL_MESSAGE(OString(OString::Concat("In <") + pXmlDoc->name + ">, XPath contents of child does not match").getStr(), rContent, getXPathContent(pXmlDoc, rXPath));
196 }
197 
198 void XmlTestTools::assertXPathNSDef(const xmlDocUniquePtr& pXmlDoc, const OString& rXPath,
199  std::u16string_view rNSPrefix, std::u16string_view rNSHref)
200 {
201  xmlXPathObjectPtr pXmlObj = getXPathNode(pXmlDoc, rXPath);
202  xmlNodeSetPtr pXmlNodes = pXmlObj->nodesetval;
203  CPPUNIT_ASSERT_MESSAGE(
204  OString(OString::Concat("In <") + pXmlDoc->name + ">, XPath '" + rXPath + "' not found").getStr(),
205  xmlXPathNodeSetGetLength(pXmlNodes) > 0);
206 
207  xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0];
208  bool bFound = false;
209  for (xmlNsPtr pNamespace = pXmlNode->nsDef; pNamespace; pNamespace = pNamespace->next)
210  {
211  if (!pNamespace->prefix)
212  continue;
213 
214  CPPUNIT_ASSERT(pNamespace->href);
215  if (rNSPrefix == convert(pNamespace->prefix) && rNSHref == convert(pNamespace->href))
216  {
217  bFound = true;
218  break;
219  }
220  }
221  xmlXPathFreeObject(pXmlObj);
222  CPPUNIT_ASSERT(bFound);
223 }
224 
225 void XmlTestTools::assertXPathChildren(const xmlDocUniquePtr& pXmlDoc, const OString& rXPath, int nNumberOfChildNodes)
226 {
227 #if LIBXML_VERSION >= 20703 /* xmlChildElementCount is only available in libxml2 >= 2.7.3 */
228  xmlXPathObjectPtr pXmlObj = getXPathNode(pXmlDoc, rXPath);
229  xmlNodeSetPtr pXmlNodes = pXmlObj->nodesetval;
230  CPPUNIT_ASSERT_EQUAL_MESSAGE(OString(OString::Concat("In <") + pXmlDoc->name + ">, XPath '" + rXPath + "' number of nodes is incorrect").getStr(),
231  1, xmlXPathNodeSetGetLength(pXmlNodes));
232  xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0];
233  CPPUNIT_ASSERT_EQUAL_MESSAGE(OString(OString::Concat("In <") + pXmlDoc->name + ">, XPath '" + rXPath + "' number of child-nodes is incorrect").getStr(),
234  nNumberOfChildNodes, static_cast<int>(xmlChildElementCount(pXmlNode)));
235  xmlXPathFreeObject(pXmlObj);
236 #else
237  (void)pXmlDoc;
238  (void)rXPath;
239  (void)nNumberOfChildNodes;
240 #endif
241 }
242 
243 void XmlTestTools::assertXPathNoAttribute(const xmlDocUniquePtr& pXmlDoc, const OString& rXPath, const OString& rAttribute)
244 {
245  xmlXPathObjectPtr pXmlObj = getXPathNode(pXmlDoc, rXPath);
246  xmlNodeSetPtr pXmlNodes = pXmlObj->nodesetval;
247  CPPUNIT_ASSERT_EQUAL_MESSAGE(OString(OString::Concat("In <") + pXmlDoc->name + ">, XPath '" + rXPath + "' number of nodes is incorrect").getStr(),
248  1, xmlXPathNodeSetGetLength(pXmlNodes));
249  xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0];
250  CPPUNIT_ASSERT_MESSAGE(OString(OString::Concat("In <") + pXmlDoc->name + ">, XPath '" + rXPath + "' unexpected '" + rAttribute + "' attribute").getStr(),
251  !xmlGetProp(pXmlNode, BAD_CAST(rAttribute.getStr())));
252  xmlXPathFreeObject(pXmlObj);
253 }
254 
255 int XmlTestTools::getXPathPosition(const xmlDocUniquePtr& pXmlDoc, const OString& rXPath, std::string_view rChildName)
256 {
257  xmlXPathObjectPtr pXmlObj = getXPathNode(pXmlDoc, rXPath);
258  xmlNodeSetPtr pXmlNodes = pXmlObj->nodesetval;
259  CPPUNIT_ASSERT_EQUAL_MESSAGE(OString(OString::Concat("In <") + pXmlDoc->name + ">, XPath '" + rXPath + "' number of nodes is incorrect").getStr(),
260  1,
261  xmlXPathNodeSetGetLength(pXmlNodes));
262  xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0];
263  int nRet = 0;
264  bool bFound = false;
265  for (xmlNodePtr pChild = pXmlNode->children; pChild; pChild = pChild->next)
266  {
267  if (oconvert(pChild->name) == rChildName)
268  {
269  bFound = true;
270  break;
271  }
272  ++nRet;
273  }
274  xmlXPathFreeObject(pXmlObj);
275  CPPUNIT_ASSERT_MESSAGE(OString(OString::Concat("In <") + pXmlDoc->name + ">, XPath '" + rXPath
276  + "' child '" + rChildName + "' not found")
277  .getStr(),
278  bFound);
279  return nRet;
280 }
281 
282 void XmlTestTools::registerODFNamespaces(xmlXPathContextPtr& pXmlXpathCtx)
283 {
284  xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("office"),
285  BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:office:1.0"));
286  xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("style"),
287  BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:style:1.0"));
288  xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("text"),
289  BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:text:1.0"));
290  xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("table"),
291  BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:table:1.0"));
292  xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("draw"),
293  BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"));
294  xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("fo"),
295  BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"));
296  xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("config"),
297  BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:config:1.0"));
298  xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("xlink"), BAD_CAST("http://www.w3.org/1999/xlink"));
299  xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("dc"), BAD_CAST("http://purl.org/dc/elements/1.1/"));
300  xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("meta"),
301  BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:meta:1.0"));
302  xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("number"),
303  BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0"));
304  xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("svg"),
305  BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"));
306  xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("chart"),
307  BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:chart:1.0"));
308  xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("dr3d"),
309  BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0"));
310  xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("math"),
311  BAD_CAST("http://www.w3.org/1998/Math/MathML"));
312  xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("form"),
313  BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:form:1.0"));
314  xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("script"),
315  BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:script:1.0"));
316  xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("ooo"),
317  BAD_CAST("http://openoffice.org/2004/office"));
318  xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("ooow"),
319  BAD_CAST("http://openoffice.org/2004/writer"));
320  xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("oooc"), BAD_CAST("http://openoffice.org/2004/calc"));
321  xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("dom"),
322  BAD_CAST("http://www.w3.org/2001/xml-events"));
323  xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("xforms"), BAD_CAST("http://www.w3.org/2002/xforms"));
324  xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("xsd"), BAD_CAST("http://www.w3.org/2001/XMLSchema"));
325  xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("xsi"),
326  BAD_CAST("http://www.w3.org/2001/XMLSchema-instance"));
327  xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("rpt"),
328  BAD_CAST("http://openoffice.org/2005/report"));
329  xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("of"),
330  BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:of:1.2"));
331  xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("xhtml"), BAD_CAST("http://www.w3.org/1999/xhtml"));
332  xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("grddl"),
333  BAD_CAST("http://www.w3.org/2003/g/data-view#"));
334  xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("officeooo"),
335  BAD_CAST("http://openoffice.org/2009/office"));
336  xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("tableooo"),
337  BAD_CAST("http://openoffice.org/2009/table"));
338  xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("drawooo"),
339  BAD_CAST("http://openoffice.org/2010/draw"));
340  xmlXPathRegisterNs(
341  pXmlXpathCtx, BAD_CAST("calcext"),
342  BAD_CAST("urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0"));
343  xmlXPathRegisterNs(
344  pXmlXpathCtx, BAD_CAST("loext"),
345  BAD_CAST("urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0"));
346  xmlXPathRegisterNs(
347  pXmlXpathCtx, BAD_CAST("field"),
348  BAD_CAST("urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0"));
349  xmlXPathRegisterNs(
350  pXmlXpathCtx, BAD_CAST("formx"),
351  BAD_CAST("urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0"));
352  xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("css3t"),
353  BAD_CAST("http://www.w3.org/TR/css3-text/"));
354  xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("anim"),
355  BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:animation:1.0"));
356  xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("smil"),
357  BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0"));
358  xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("presentation"),
359  BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:presentation:1.0"));
360  // user-defined
361  xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("foo"),
362  BAD_CAST("http://example.com/"));
363 }
364 
365 void XmlTestTools::registerOOXMLNamespaces(xmlXPathContextPtr& pXmlXpathCtx)
366 {
367  xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("w"),
368  BAD_CAST("http://schemas.openxmlformats.org/wordprocessingml/2006/main"));
369  xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("v"), BAD_CAST("urn:schemas-microsoft-com:vml"));
370  xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("mc"),
371  BAD_CAST("http://schemas.openxmlformats.org/markup-compatibility/2006"));
372  xmlXPathRegisterNs(
373  pXmlXpathCtx, BAD_CAST("wps"),
374  BAD_CAST("http://schemas.microsoft.com/office/word/2010/wordprocessingShape"));
375  xmlXPathRegisterNs(
376  pXmlXpathCtx, BAD_CAST("wpg"),
377  BAD_CAST("http://schemas.microsoft.com/office/word/2010/wordprocessingGroup"));
378  xmlXPathRegisterNs(
379  pXmlXpathCtx, BAD_CAST("wp"),
380  BAD_CAST("http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"));
381  xmlXPathRegisterNs(
382  pXmlXpathCtx, BAD_CAST("wp14"),
383  BAD_CAST("http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing"));
384  xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("a"),
385  BAD_CAST("http://schemas.openxmlformats.org/drawingml/2006/main"));
386  xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("pic"),
387  BAD_CAST("http://schemas.openxmlformats.org/drawingml/2006/picture"));
388  xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("rels"),
389  BAD_CAST("http://schemas.openxmlformats.org/package/2006/relationships"));
390  xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("w14"),
391  BAD_CAST("http://schemas.microsoft.com/office/word/2010/wordml"));
392  xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("w15"),
393  BAD_CAST("http://schemas.microsoft.com/office/word/2012/wordml"));
394  xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("m"),
395  BAD_CAST("http://schemas.openxmlformats.org/officeDocument/2006/math"));
396  xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("ContentType"),
397  BAD_CAST("http://schemas.openxmlformats.org/package/2006/content-types"));
398  xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("lc"),
399  BAD_CAST("http://schemas.openxmlformats.org/drawingml/2006/lockedCanvas"));
400  xmlXPathRegisterNs(
401  pXmlXpathCtx, BAD_CAST("cp"),
402  BAD_CAST("http://schemas.openxmlformats.org/package/2006/metadata/core-properties"));
403  xmlXPathRegisterNs(
404  pXmlXpathCtx, BAD_CAST("extended-properties"),
405  BAD_CAST("http://schemas.openxmlformats.org/officeDocument/2006/extended-properties"));
406  xmlXPathRegisterNs(
407  pXmlXpathCtx, BAD_CAST("custom-properties"),
408  BAD_CAST("http://schemas.openxmlformats.org/officeDocument/2006/custom-properties"));
409  xmlXPathRegisterNs(
410  pXmlXpathCtx, BAD_CAST("vt"),
411  BAD_CAST("http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes"));
412  xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("dcterms"), BAD_CAST("http://purl.org/dc/terms/"));
413  xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("a14"),
414  BAD_CAST("http://schemas.microsoft.com/office/drawing/2010/main"));
415  xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("c"),
416  BAD_CAST("http://schemas.openxmlformats.org/drawingml/2006/chart"));
417  xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("x"),
418  BAD_CAST("http://schemas.openxmlformats.org/spreadsheetml/2006/main"));
419  xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("r"),
420  BAD_CAST("http://schemas.openxmlformats.org/officeDocument/2006/relationships"));
421  xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("xx"),
422  BAD_CAST("urn:schemas-microsoft-com:office:excel"));
423  xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("xdr"),
424  BAD_CAST("http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing"));
425  xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("x14"),
426  BAD_CAST("http://schemas.microsoft.com/office/spreadsheetml/2009/9/main"));
427  xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("xm"),
428  BAD_CAST("http://schemas.microsoft.com/office/excel/2006/main"));
429  xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("x12ac"),
430  BAD_CAST("http://schemas.microsoft.com/office/spreadsheetml/2011/1/ac"));
431  xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("o"),
432  BAD_CAST("urn:schemas-microsoft-com:office:office"));
433  xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("w10"),
434  BAD_CAST("urn:schemas-microsoft-com:office:word"));
435  xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("p"),
436  BAD_CAST("http://schemas.openxmlformats.org/presentationml/2006/main"));
437  xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("p14"),
438  BAD_CAST("http://schemas.microsoft.com/office/powerpoint/2010/main"));
439  xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("dgm"),
440  BAD_CAST("http://schemas.openxmlformats.org/drawingml/2006/diagram"));
441  xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("c15"),
442  BAD_CAST("http://schemas.microsoft.com/office/drawing/2012/chart"));
443 }
444 
445 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static xmlDocUniquePtr dumpAndParse(MetafileXmlDump &rDumper, const GDIMetaFile &rGDIMetaFile)
void dump(const GDIMetaFile &rMetaFile, SvStream &rStream)
static void registerODFNamespaces(xmlXPathContextPtr &pXmlXpathCtx)
std::unique_ptr< xmlDoc, xmlDocDeleter > xmlDocUniquePtr
Definition: xmldocptr.hxx:18
virtual ~XmlTestTools()
sal_uInt64 Seek(sal_uInt64 nPos)
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 xmlDocUniquePtr parseXml(utl::TempFile const &aTempFile)
static xmlDocUniquePtr parseXmlStream(SvStream *pStream)
Return xmlDocPtr representation of the XML stream read from pStream.
sal_uInt64 remainingSize()
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. ...
OUString const & GetURL() const
#define STREAM_SEEK_TO_BEGIN
void assertXPathAttrs(const xmlDocUniquePtr &pXmlDoc, const OString &rXPath, const std::vector< std::pair< OString, OUString >> &aPairVector)
virtual void registerNamespaces(xmlXPathContextPtr &pXmlXpathCtx)
std::size_t ReadBytes(void *pData, std::size_t nSize)
convert
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...
void assertXPath(const xmlDocUniquePtr &pXmlDoc, const OString &rXPath)
Assert that rXPath exists, and returns exactly one node.
void assertXPathContent(const xmlDocUniquePtr &pXmlDoc, const OString &rXPath, const OUString &rContent)
Assert that rXPath exists, and its content equals rContent.
unsigned char sal_uInt8
#define SAL_INFO(area, stream)
xmlXPathObjectPtr getXPathNode(const xmlDocUniquePtr &pXmlDoc, const OString &rXPath)
static void registerOOXMLNamespaces(xmlXPathContextPtr &pXmlXpathCtx)
OUString getXPath(const xmlDocUniquePtr &pXmlDoc, const OString &rXPath, const OString &rAttribute)
Same as the assertXPath(), but don't assert: return the string instead.
OUString getXPathContent(const xmlDocUniquePtr &pXmlDoc, const OString &rXPath)
Same as the assertXPathContent(), but don't assert: return the string instead.
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo