Branch libreoffice-5-0-4
[LibreOffice.git] / include / test / xmltesttools.hxx
bloba4cf8cc1a6f8156babddecbf032995586025c3e9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
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
30 public:
31 /// Return xmlDocPtr representation of the XML stream read from pStream.
32 static xmlDocPtr parseXmlStream(SvStream* pStream);
34 protected:
35 XmlTestTools();
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);
44 /**
45 * Same as the assertXPath(), but don't assert: return the string instead.
47 OUString getXPath(xmlDocPtr pXmlDoc, const OString& rXPath, const OString& rAttribute);
48 /**
49 * Same as the assertXPathContent(), but don't assert: return the string instead.
51 OUString getXPathContent(xmlDocPtr pXmlDoc, const OString& rXPath);
52 /**
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);
57 /**
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());
65 /**
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);
70 /**
71 * Assert that rXPath exists, and its content equals rContent.
73 void assertXPathContent(xmlDocPtr pXmlDoc, const OString& rXPath, const OUString& rContent);
74 /**
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);
79 /**
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);
86 #endif
88 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */