1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
10 #ifndef INCLUDED_TEST_XMLTESTTOOLS_HXX
11 #define INCLUDED_TEST_XMLTESTTOOLS_HXX
13 #include <sal/config.h>
14 #include <test/testdllapi.hxx>
16 #include <libxml/xmlwriter.h>
17 #include <libxml/tree.h>
18 #include <libxml/xpath.h>
19 #include <libxml/xpathInternals.h>
20 #include <libxml/parserInternals.h>
22 #include <rtl/string.hxx>
23 #include <rtl/ustring.hxx>
24 #include <unotools/tempfile.hxx>
25 #include <vcl/mtfxmldump.hxx>
26 #include <test/xmldocptr.hxx>
28 #include <cppunit/TestAssert.h>
30 #include <string_view>
33 class OOO_DLLPUBLIC_TEST XmlTestTools
36 /// Return xmlDocPtr representation of the XML stream read from pStream.
37 static xmlDocUniquePtr
parseXmlStream(SvStream
* pStream
);
39 static xmlDocUniquePtr
dumpAndParse(MetafileXmlDump
& rDumper
, const GDIMetaFile
& rGDIMetaFile
);
43 virtual ~XmlTestTools();
45 static xmlDocUniquePtr
parseXml(utl::TempFileNamed
const & aTempFile
);
47 virtual void registerNamespaces(xmlXPathContextPtr
& pXmlXpathCtx
);
49 // Caller must call xmlXPathFreeObject:
50 xmlXPathObjectPtr
getXPathNode(const xmlDocUniquePtr
& pXmlDoc
, const OString
& rXPath
);
52 * Same as the assertXPath(), but don't assert: return the string instead.
54 OUString
getXPath(const xmlDocUniquePtr
& pXmlDoc
, const OString
& rXPath
, const OString
& rAttribute
);
56 * Same as the assertXPathContent(), but don't assert: return the string instead.
58 OUString
getXPathContent(const xmlDocUniquePtr
& pXmlDoc
, const OString
& rXPath
);
60 * Get the position of the child named rName of the parent node specified by rXPath.
61 * Useful for checking relative order of elements.
63 int getXPathPosition(const xmlDocUniquePtr
& pXmlDoc
, const OString
& rXPath
, std::string_view rChildName
);
65 * Get the number of the nodes returned by the rXPath.
67 int countXPathNodes(const xmlDocUniquePtr
& pXmlDoc
, const OString
& rXPath
);
69 * Assert that rXPath exists, returns exactly one node, and the rXPath's attribute's value
70 * equals to the rExpected value.
72 void assertXPath(const xmlDocUniquePtr
& pXmlDoc
, const OString
& rXPath
, const OString
& rAttribute
,
73 const OUString
& rExpectedValue
);
74 void assertXPathAttrs(const xmlDocUniquePtr
& pXmlDoc
, const OString
& rXPath
,
75 const std::vector
<std::pair
<OString
, OUString
>>& aPairVector
);
77 * Assert that rXPath exists, and returns exactly nNumberOfNodes nodes (1 by default).
78 * Also useful for checking that we do _not_ export some node (nNumberOfNodes == 0).
80 void assertXPath(const xmlDocUniquePtr
& pXmlDoc
, const OString
& rXPath
, int nNumberOfNodes
= 1);
82 * Assert that rXPath exists, and its content equals rContent.
84 void assertXPathContent(const xmlDocUniquePtr
& pXmlDoc
, const OString
& rXPath
, const OUString
& rContent
);
86 * Assert that rXPath exists and it has an rNSPrefix=rNSHref namespace definition.
88 void assertXPathNSDef(const xmlDocUniquePtr
& pXmlDoc
, const OString
& rXPath
, std::u16string_view rNSPrefix
,
89 std::u16string_view rNSHref
);
91 * Assert that rXPath exists, and has exactly nNumberOfChildNodes child nodes.
92 * Useful for checking that we do have a no child nodes to a specific node (nNumberOfChildNodes == 0).
94 void assertXPathChildren(const xmlDocUniquePtr
& pXmlDoc
, const OString
& rXPath
, int nNumberOfChildNodes
);
96 * Assert that rXPath exists, has exactly 1 result set nodes and does *not* have an attribute named rAttribute.
98 void assertXPathNoAttribute(const xmlDocUniquePtr
& pXmlDoc
, const OString
& rXPath
, const OString
& rAttribute
);
100 static void registerODFNamespaces(xmlXPathContextPtr
& pXmlXpathCtx
);
101 static void registerOOXMLNamespaces(xmlXPathContextPtr
& pXmlXpathCtx
);
106 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */