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>
26 #include <cppunit/TestAssert.h>
28 class OOO_DLLPUBLIC_TEST XmlTestTools
31 /// Return xmlDocPtr representation of the XML stream read from pStream.
32 static xmlDocPtr
parseXmlStream(SvStream
* pStream
);
36 virtual ~XmlTestTools();
38 static xmlDocPtr
parseXml(utl::TempFile
& aTempFile
);
40 virtual void registerNamespaces(xmlXPathContextPtr
& pXmlXpathCtx
);
42 // Caller must call xmlXPathFreeObject:
43 xmlXPathObjectPtr
getXPathNode(xmlDocPtr pXmlDoc
, const OString
& rXPath
);
45 * Same as the assertXPath(), but don't assert: return the string instead.
47 OUString
getXPath(xmlDocPtr pXmlDoc
, const OString
& rXPath
, const OString
& rAttribute
);
49 * Same as the assertXPathContent(), but don't assert: return the string instead.
51 OUString
getXPathContent(xmlDocPtr pXmlDoc
, const OString
& rXPath
);
53 * Get the position of the child named rName of the parent node specified by rXPath.
54 * Useful for checking relative order of elements.
56 int getXPathPosition(xmlDocPtr pXmlDoc
, const OString
& rXPath
, const OUString
& rChildName
);
58 * Assert that rXPath exists, and returns exactly one node.
59 * In case rAttribute is provided, the rXPath's attribute's value must
60 * equal to the rExpected value.
62 void assertXPath(xmlDocPtr pXmlDoc
, const OString
& rXPath
,
63 const OString
& rAttribute
= OString(),
64 const OUString
& rExpectedValue
= OUString());
66 * Assert that rXPath exists, and returns exactly nNumberOfNodes nodes.
67 * Useful for checking that we do _not_ export some node (nNumberOfNodes == 0).
69 void assertXPath(xmlDocPtr pXmlDoc
, const OString
& rXPath
, int nNumberOfNodes
);
71 * Assert that rXPath exists, and its content equals rContent.
73 void assertXPathContent(xmlDocPtr pXmlDoc
, const OString
& rXPath
, const OUString
& rContent
);
75 * Assert that rXPath exists, and has exactly nNumberOfChildNodes child nodes.
76 * Useful for checking that we do have a no child nodes to a specific node (nNumberOfChildNodes == 0).
78 void assertXPathChildren(xmlDocPtr pXmlDoc
, const OString
& rXPath
, int nNumberOfChildNodes
);
80 * Assert that rXPath exists, has exactly 1 child node and does *not* have an attribute named rAttribute.
82 void assertXPathNoAttribute(xmlDocPtr pXmlDoc
, const OString
& rXPath
, const OString
& rAttribute
);
88 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */