Kaydet (Commit) 780cedb2 authored tarafından Tomaž Vajngerl's avatar Tomaž Vajngerl

test: parseXmlStream & parseHtmlStream added to test tools

Change-Id: Iff8af5e9ffefb4c3cecf387b16473d45e8b4a65a
üst 7da0a6e5
...@@ -17,12 +17,12 @@ ...@@ -17,12 +17,12 @@
#include <libxml/HTMLtree.h> #include <libxml/HTMLtree.h>
#include <unotools/tempfile.hxx> #include <unotools/tempfile.hxx>
#include <boost/scoped_array.hpp>
class OOO_DLLPUBLIC_TEST HtmlTestTools class OOO_DLLPUBLIC_TEST HtmlTestTools
{ {
protected: protected:
htmlDocPtr parseHtml(utl::TempFile& aTempFile); htmlDocPtr parseHtml(utl::TempFile& aTempFile);
htmlDocPtr parseHtmlStream(SvStream* pStream);
}; };
#endif #endif
......
...@@ -14,12 +14,15 @@ ...@@ -14,12 +14,15 @@
#include <test/testdllapi.hxx> #include <test/testdllapi.hxx>
#include <libxml/xmlwriter.h> #include <libxml/xmlwriter.h>
#include <libxml/tree.h>
#include <libxml/xpath.h> #include <libxml/xpath.h>
#include <libxml/xpathInternals.h> #include <libxml/xpathInternals.h>
#include <libxml/parserInternals.h> #include <libxml/parserInternals.h>
#include <rtl/string.hxx> #include <rtl/string.hxx>
#include <rtl/ustring.hxx> #include <rtl/ustring.hxx>
#include <unotools/tempfile.hxx>
#include <cppunit/TestAssert.h> #include <cppunit/TestAssert.h>
class OOO_DLLPUBLIC_TEST XmlTestTools class OOO_DLLPUBLIC_TEST XmlTestTools
...@@ -28,6 +31,9 @@ protected: ...@@ -28,6 +31,9 @@ protected:
XmlTestTools(); XmlTestTools();
virtual ~XmlTestTools(); virtual ~XmlTestTools();
htmlDocPtr parseXml(utl::TempFile& aTempFile);
htmlDocPtr parseXmlStream(SvStream* pStream);
virtual void registerNamespaces(xmlXPathContextPtr& pXmlXpathCtx); virtual void registerNamespaces(xmlXPathContextPtr& pXmlXpathCtx);
xmlNodeSetPtr getXPathNode(xmlDocPtr pXmlDoc, const OString& rXPath); xmlNodeSetPtr getXPathNode(xmlDocPtr pXmlDoc, const OString& rXPath);
......
...@@ -9,17 +9,20 @@ ...@@ -9,17 +9,20 @@
#include <test/htmltesttools.hxx> #include <test/htmltesttools.hxx>
#include <boost/scoped_array.hpp>
htmlDocPtr HtmlTestTools::parseHtml(utl::TempFile& aTempFile) htmlDocPtr HtmlTestTools::parseHtml(utl::TempFile& aTempFile)
{ {
SvFileStream aFileStream(aTempFile.GetURL(), STREAM_READ); SvFileStream aFileStream(aTempFile.GetURL(), STREAM_READ);
sal_Size nSize = aFileStream.remainingSize(); return parseHtmlStream(&aFileStream);
}
htmlDocPtr HtmlTestTools::parseHtmlStream(SvStream* pStream)
{
sal_Size nSize = pStream->remainingSize();
boost::scoped_array<sal_uInt8> pBuffer(new sal_uInt8[nSize + 1]); boost::scoped_array<sal_uInt8> pBuffer(new sal_uInt8[nSize + 1]);
pStream->Read(pBuffer.get(), nSize);
aFileStream.Read(pBuffer.get(), nSize);
pBuffer[nSize] = 0; pBuffer[nSize] = 0;
return htmlParseDoc(reinterpret_cast<xmlChar*>(pBuffer.get()), NULL); return htmlParseDoc(reinterpret_cast<xmlChar*>(pBuffer.get()), NULL);
} }
......
...@@ -9,12 +9,29 @@ ...@@ -9,12 +9,29 @@
#include <test/xmltesttools.hxx> #include <test/xmltesttools.hxx>
#include <boost/scoped_array.hpp>
XmlTestTools::XmlTestTools() XmlTestTools::XmlTestTools()
{} {}
XmlTestTools::~XmlTestTools() XmlTestTools::~XmlTestTools()
{} {}
htmlDocPtr XmlTestTools::parseXml(utl::TempFile& aTempFile)
{
SvFileStream aFileStream(aTempFile.GetURL(), STREAM_READ);
return parseXmlStream(&aFileStream);
}
xmlDocPtr XmlTestTools::parseXmlStream(SvStream* pStream)
{
sal_Size nSize = pStream->remainingSize();
boost::scoped_array<sal_uInt8> pBuffer(new sal_uInt8[nSize + 1]);
pStream->Read(pBuffer.get(), nSize);
pBuffer[nSize] = 0;
return xmlParseDoc(reinterpret_cast<xmlChar*>(pBuffer.get()));
}
xmlNodeSetPtr XmlTestTools::getXPathNode(xmlDocPtr pXmlDoc, const OString& rXPath) xmlNodeSetPtr XmlTestTools::getXPathNode(xmlDocPtr pXmlDoc, const OString& rXPath)
{ {
xmlXPathContextPtr pXmlXpathCtx = xmlXPathNewContext(pXmlDoc); xmlXPathContextPtr pXmlXpathCtx = xmlXPathNewContext(pXmlDoc);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment