diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/drawinglayer/tools/primitive2dxmldump.hxx | 3 | ||||
-rw-r--r-- | include/test/htmltesttools.hxx | 7 | ||||
-rw-r--r-- | include/test/xmldocptr.hxx | 19 | ||||
-rw-r--r-- | include/test/xmltesttools.hxx | 31 |
4 files changed, 42 insertions, 18 deletions
diff --git a/include/drawinglayer/tools/primitive2dxmldump.hxx b/include/drawinglayer/tools/primitive2dxmldump.hxx index 3158f537262e..f8712db35fb2 100644 --- a/include/drawinglayer/tools/primitive2dxmldump.hxx +++ b/include/drawinglayer/tools/primitive2dxmldump.hxx @@ -14,6 +14,7 @@ #include <drawinglayer/drawinglayerdllapi.h> #include <libxml/tree.h> #include <drawinglayer/primitive2d/baseprimitive2d.hxx> +#include <test/xmldocptr.hxx> #include <vector> namespace tools { class XmlWriter; } @@ -38,7 +39,7 @@ public: * into a memory stream. * */ - xmlDocPtr dumpAndParse(const drawinglayer::primitive2d::Primitive2DContainer& aPrimitive2DSequence, const OUString& rStreamName = OUString()); + xmlDocUniquePtr dumpAndParse(const drawinglayer::primitive2d::Primitive2DContainer& aPrimitive2DSequence, const OUString& rStreamName = OUString()); /** Dumps the input primitive sequence to xml into a file. */ void dump(const drawinglayer::primitive2d::Primitive2DContainer& rPrimitive2DSequence, const OUString& rStreamName); diff --git a/include/test/htmltesttools.hxx b/include/test/htmltesttools.hxx index e7bb85305227..fa5722075f87 100644 --- a/include/test/htmltesttools.hxx +++ b/include/test/htmltesttools.hxx @@ -12,17 +12,20 @@ #include <sal/config.h> #include <test/testdllapi.hxx> +#include <test/xmltesttools.hxx> #include <libxml/HTMLparser.h> #include <libxml/HTMLtree.h> #include <unotools/tempfile.hxx> +using htmlDocUniquePtr = xmlDocUniquePtr; + class OOO_DLLPUBLIC_TEST HtmlTestTools { protected: - static htmlDocPtr parseHtml(utl::TempFile const & aTempFile); - static htmlDocPtr parseHtmlStream(SvStream* pStream); + static htmlDocUniquePtr parseHtml(utl::TempFile const & aTempFile); + static htmlDocUniquePtr parseHtmlStream(SvStream* pStream); }; #endif diff --git a/include/test/xmldocptr.hxx b/include/test/xmldocptr.hxx new file mode 100644 index 000000000000..abca72633c61 --- /dev/null +++ b/include/test/xmldocptr.hxx @@ -0,0 +1,19 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +#pragma once + +#include <memory> + +struct xmlDocDeleter +{ + void operator()(xmlDoc* p) { xmlFreeDoc(p); } +}; +using xmlDocUniquePtr = std::unique_ptr<xmlDoc, xmlDocDeleter>; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/include/test/xmltesttools.hxx b/include/test/xmltesttools.hxx index f8f10da387bd..a2c08d7dc0e8 100644 --- a/include/test/xmltesttools.hxx +++ b/include/test/xmltesttools.hxx @@ -23,6 +23,7 @@ #include <rtl/ustring.hxx> #include <unotools/tempfile.hxx> #include <vcl/mtfxmldump.hxx> +#include <test/xmldocptr.hxx> #include <cppunit/TestAssert.h> @@ -32,68 +33,68 @@ class OOO_DLLPUBLIC_TEST XmlTestTools { public: /// Return xmlDocPtr representation of the XML stream read from pStream. - static xmlDocPtr parseXmlStream(SvStream* pStream); + static xmlDocUniquePtr parseXmlStream(SvStream* pStream); - static xmlDocPtr dumpAndParse(MetafileXmlDump& rDumper, const GDIMetaFile& rGDIMetaFile); + static xmlDocUniquePtr dumpAndParse(MetafileXmlDump& rDumper, const GDIMetaFile& rGDIMetaFile); protected: XmlTestTools(); virtual ~XmlTestTools(); - static xmlDocPtr parseXml(utl::TempFile const & aTempFile); + static xmlDocUniquePtr parseXml(utl::TempFile const & aTempFile); virtual void registerNamespaces(xmlXPathContextPtr& pXmlXpathCtx); // Caller must call xmlXPathFreeObject: - xmlXPathObjectPtr getXPathNode(xmlDocPtr pXmlDoc, const OString& rXPath); + xmlXPathObjectPtr getXPathNode(const xmlDocUniquePtr& pXmlDoc, const OString& rXPath); /** * Same as the assertXPath(), but don't assert: return the string instead. */ - OUString getXPath(xmlDocPtr pXmlDoc, const OString& rXPath, const OString& rAttribute); + OUString getXPath(const xmlDocUniquePtr& pXmlDoc, const OString& rXPath, const OString& rAttribute); /** * Same as the assertXPathContent(), but don't assert: return the string instead. */ - OUString getXPathContent(xmlDocPtr pXmlDoc, const OString& rXPath); + OUString getXPathContent(const xmlDocUniquePtr& pXmlDoc, const OString& rXPath); /** * Get the position of the child named rName of the parent node specified by rXPath. * Useful for checking relative order of elements. */ - int getXPathPosition(xmlDocPtr pXmlDoc, const OString& rXPath, const OString& rChildName); + int getXPathPosition(const xmlDocUniquePtr& pXmlDoc, const OString& rXPath, const OString& rChildName); /** * Assert that rXPath exists, and returns exactly one node. */ - void assertXPath(xmlDocPtr pXmlDoc, const OString& rXPath); + void assertXPath(const xmlDocUniquePtr& pXmlDoc, const OString& rXPath); /** * Assert that rXPath exists, returns exactly one node, and the rXPath's attribute's value * equals to the rExpected value. */ - void assertXPath(xmlDocPtr pXmlDoc, const OString& rXPath, const OString& rAttribute, + void assertXPath(const xmlDocUniquePtr& pXmlDoc, const OString& rXPath, const OString& rAttribute, const OUString& rExpectedValue); - void assertXPathAttrs(xmlDocPtr pXmlDoc, const OString& rXPath, + void assertXPathAttrs(const xmlDocUniquePtr& pXmlDoc, const OString& rXPath, const std::vector<std::pair<OString, OUString>>& aPairVector); /** * Assert that rXPath exists, and returns exactly nNumberOfNodes nodes. * Useful for checking that we do _not_ export some node (nNumberOfNodes == 0). */ - void assertXPath(xmlDocPtr pXmlDoc, const OString& rXPath, int nNumberOfNodes); + void assertXPath(const xmlDocUniquePtr& pXmlDoc, const OString& rXPath, int nNumberOfNodes); /** * Assert that rXPath exists, and its content equals rContent. */ - void assertXPathContent(xmlDocPtr pXmlDoc, const OString& rXPath, const OUString& rContent); + void assertXPathContent(const xmlDocUniquePtr& pXmlDoc, const OString& rXPath, const OUString& rContent); /** * Assert that rXPath exists and it has an rNSPrefix=rNSHref namespace definition. */ - void assertXPathNSDef(xmlDocPtr pXmlDoc, const OString& rXPath, const OUString& rNSPrefix, + void assertXPathNSDef(const xmlDocUniquePtr& pXmlDoc, const OString& rXPath, const OUString& rNSPrefix, const OUString& rNSHref); /** * Assert that rXPath exists, and has exactly nNumberOfChildNodes child nodes. * Useful for checking that we do have a no child nodes to a specific node (nNumberOfChildNodes == 0). */ - void assertXPathChildren(xmlDocPtr pXmlDoc, const OString& rXPath, int nNumberOfChildNodes); + void assertXPathChildren(const xmlDocUniquePtr& pXmlDoc, const OString& rXPath, int nNumberOfChildNodes); /** * Assert that rXPath exists, has exactly 1 child node and does *not* have an attribute named rAttribute. */ - void assertXPathNoAttribute(xmlDocPtr pXmlDoc, const OString& rXPath, const OString& rAttribute); + void assertXPathNoAttribute(const xmlDocUniquePtr& pXmlDoc, const OString& rXPath, const OString& rAttribute); }; |