summaryrefslogtreecommitdiff
path: root/sd/qa/unit
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.com>2014-04-13 22:13:56 +0200
committerTomaž Vajngerl <tomaz.vajngerl@collabora.com>2014-04-13 23:13:57 +0200
commite679c101ac6c995aa26c9e1490ddb8233e668438 (patch)
tree30eb7fd0ff65ebe819e4b98a425db9daf6ec9df9 /sd/qa/unit
parent87c3fdeed8a1e9129966323c1100e1cd1aa31a9f (diff)
sd html: impress html export test
Change-Id: I710868b4cb19cec2820c3cf699dd5d855e3da7e2
Diffstat (limited to 'sd/qa/unit')
-rw-r--r--sd/qa/unit/HtmlExportTest.cxx110
-rw-r--r--sd/qa/unit/data/HtmlExportTestDocument.odpbin0 -> 25480 bytes
-rw-r--r--sd/qa/unit/sdmodeltestbase.hxx76
3 files changed, 164 insertions, 22 deletions
diff --git a/sd/qa/unit/HtmlExportTest.cxx b/sd/qa/unit/HtmlExportTest.cxx
new file mode 100644
index 000000000000..8779f9f1b7d5
--- /dev/null
+++ b/sd/qa/unit/HtmlExportTest.cxx
@@ -0,0 +1,110 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * 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/.
+ */
+
+#include "sdmodeltestbase.hxx"
+
+#include <libxml/xmlwriter.h>
+#include <libxml/xpath.h>
+#include <libxml/xpathInternals.h>
+#include <libxml/parserInternals.h>
+#include <libxml/HTMLparser.h>
+#include <libxml/HTMLtree.h>
+
+#include <rtl/byteseq.hxx>
+#include <boost/scoped_array.hpp>
+
+using namespace css;
+using namespace rtl;
+
+class SdHTMLFilterTest : public SdModelTestBase
+{
+ htmlDocPtr parseHtml(utl::TempFile& aTempFile)
+ {
+ SvFileStream aFileStream(aTempFile.GetURL(), STREAM_READ);
+ sal_Size nSize = aFileStream.remainingSize();
+
+ boost::scoped_array<sal_uInt8> pBuffer(new sal_uInt8[nSize + 1]);
+
+ aFileStream.Read(pBuffer.get(), nSize);
+
+ pBuffer[nSize] = 0;
+ printf("Content: %s\n", reinterpret_cast<char*>(pBuffer.get()));
+ return htmlParseDoc(reinterpret_cast<xmlChar*>(pBuffer.get()), NULL);
+ }
+
+ xmlNodeSetPtr getXPathNode(xmlDocPtr pXmlDoc, const OString& rXPath)
+ {
+ xmlXPathContextPtr pXmlXpathCtx = xmlXPathNewContext(pXmlDoc);
+ xmlXPathObjectPtr pXmlXpathObj = xmlXPathEvalExpression(BAD_CAST(rXPath.getStr()), pXmlXpathCtx);
+ return pXmlXpathObj->nodesetval;
+ }
+
+ OUString getXPath(xmlDocPtr pXmlDoc, const OString& rXPath, const OString& rAttribute)
+ {
+ xmlNodeSetPtr pXmlNodes = getXPathNode(pXmlDoc, rXPath);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(OString("XPath '" + rXPath + "' number of nodes is incorrect").getStr(),
+ 1, xmlXPathNodeSetGetLength(pXmlNodes));
+ if (rAttribute.isEmpty())
+ return OUString();
+ xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0];
+ return OUString::createFromAscii((const char*)xmlGetProp(pXmlNode, BAD_CAST(rAttribute.getStr())));
+ }
+
+ void assertXPath(xmlDocPtr pXmlDoc, const OString& rXPath, const OString& rAttribute = OString(), const OUString& rExpectedValue = OUString())
+ {
+ OUString aValue = getXPath(pXmlDoc, rXPath, rAttribute);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(OString("Attribute '" + rAttribute + "' of '" + rXPath + "' incorrect value.").getStr(),
+ rExpectedValue, aValue);
+ }
+
+ void assertXPath(xmlDocPtr pXmlDoc, const OString& rXPath, int nNumberOfNodes)
+ {
+ xmlNodeSetPtr pXmlNodes = getXPathNode(pXmlDoc, rXPath);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(OString("XPath '" + rXPath + "' number of nodes is incorrect").getStr(),
+ nNumberOfNodes, xmlXPathNodeSetGetLength(pXmlNodes));
+ }
+
+ htmlDocPtr exportAndparseHtml(sd::DrawDocShellRef& xDocShRef)
+ {
+ FileFormat* pFormat = getFormat(HTML);
+ OUString aExt = OUString( "." ) + OUString::createFromAscii(pFormat->pName);
+ utl::TempFile aTempFile(OUString(), &aExt);
+ aTempFile.EnableKillingFile();
+ exportTo(xDocShRef, pFormat, aTempFile);
+ return parseHtml(aTempFile);
+ }
+
+public:
+
+ void testHTMLExport()
+ {
+ sd::DrawDocShellRef xDocShRef = loadURL(getURLFromSrc("/sd/qa/unit/data/HtmlExportTestDocument.odp"));
+ htmlDocPtr htmlDoc = exportAndparseHtml(xDocShRef);
+
+ assertXPath(htmlDoc, "/html", 1);
+ assertXPath(htmlDoc, "/html/body", 1);
+ assertXPath(htmlDoc, "/html/body/h1", 4);
+ assertXPath(htmlDoc, "/html/body/table", 1);
+ assertXPath(htmlDoc, "/html/body/table/tr", 5);
+ assertXPath(htmlDoc, "/html/body/ul", 1);
+ assertXPath(htmlDoc, "/html/body/ul/li", 2);
+ }
+
+ CPPUNIT_TEST_SUITE(SdHTMLFilterTest);
+ CPPUNIT_TEST(testHTMLExport);
+ CPPUNIT_TEST_SUITE_END();
+};
+
+
+
+CPPUNIT_TEST_SUITE_REGISTRATION(SdHTMLFilterTest);
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sd/qa/unit/data/HtmlExportTestDocument.odp b/sd/qa/unit/data/HtmlExportTestDocument.odp
new file mode 100644
index 000000000000..3c1661471300
--- /dev/null
+++ b/sd/qa/unit/data/HtmlExportTestDocument.odp
Binary files differ
diff --git a/sd/qa/unit/sdmodeltestbase.hxx b/sd/qa/unit/sdmodeltestbase.hxx
index eec32313a2d1..bc63fa1666bc 100644
--- a/sd/qa/unit/sdmodeltestbase.hxx
+++ b/sd/qa/unit/sdmodeltestbase.hxx
@@ -37,6 +37,7 @@ struct FileFormat {
#define ODP_FORMAT_TYPE ( SFX_FILTER_IMPORT | SFX_FILTER_EXPORT | SFX_FILTER_TEMPLATE | SFX_FILTER_OWN | SFX_FILTER_DEFAULT | SFX_FILTER_ENCRYPTION | SFX_FILTER_PREFERED )
#define PPT_FORMAT_TYPE ( SFX_FILTER_IMPORT | SFX_FILTER_EXPORT | SFX_FILTER_ALIEN )
#define PPTX_FORMAT_TYPE ( SFX_FILTER_IMPORT | SFX_FILTER_EXPORT | SFX_FILTER_ALIEN | SFX_FILTER_STARONEFILTER | SFX_FILTER_PREFERED )
+#define HTML_FORMAT_TYPE ( SFX_FILTER_EXPORT | SFX_FILTER_ALIEN )
/** List of file formats we support in Impress unit tests.
@@ -50,12 +51,14 @@ FileFormat aFileFormats[] = {
{ "odp", "impress8", "impress8", "", ODP_FORMAT_TYPE },
{ "ppt", "MS PowerPoint 97", "Microsoft PowerPoint 97/2000/XP/2003", "sdfilt", PPT_FORMAT_TYPE },
{ "pptx", "Impress MS PowerPoint 2007 XML", "MS PowerPoint 2007 XML", "", PPTX_FORMAT_TYPE },
+ { "html", "graphic_HTML", "graphic_HTML", "", HTML_FORMAT_TYPE },
{ 0, 0, 0, 0, 0 }
};
-#define ODP 0
-#define PPT 1
+#define ODP 0
+#define PPT 1
#define PPTX 2
+#define HTML 3
/// Base class for filter tests loading or roundtriping a document, and asserting the document model.
class SdModelTestBase : public test::BootstrapFixture, public unotest::MacrosTest
@@ -83,7 +86,7 @@ public:
protected:
/// Load the document.
- ::sd::DrawDocShellRef loadURL( const OUString &rURL )
+ sd::DrawDocShellRef loadURL( const OUString &rURL )
{
FileFormat *pFmt(0);
@@ -121,31 +124,60 @@ protected:
return xDocShRef;
}
- ::sd::DrawDocShellRef saveAndReload( ::sd::DrawDocShell *pShell, sal_Int32 nExportType )
+ FileFormat* getFormat(sal_Int32 nExportType)
{
- FileFormat *pFmt = &aFileFormats[0];
- if( ( (sal_uInt32) nExportType ) < SAL_N_ELEMENTS( aFileFormats ) )
- pFmt = &aFileFormats[ nExportType ];
- OUString aExt = OUString( "." ) + OUString::createFromAscii( pFmt->pName );
- utl::TempFile aTempFile( OUString(), &aExt );
- aTempFile.EnableKillingFile();
- SfxMedium aStoreMedium( aTempFile.GetURL(), STREAM_STD_WRITE );
+ FileFormat* pFormat = &aFileFormats[0];
+ if (((sal_uInt32) nExportType) < SAL_N_ELEMENTS(aFileFormats))
+ pFormat = &aFileFormats[nExportType];
+ return pFormat;
+ }
+
+ void exportTo(sd::DrawDocShell* pShell, FileFormat* pFormat, utl::TempFile& rTempFile)
+ {
+ SfxMedium aStoreMedium(rTempFile.GetURL(), STREAM_STD_WRITE);
+ sal_uInt32 nExportFormat = 0;
+ if (pFormat->nFormatType == ODP_FORMAT_TYPE)
+ nExportFormat = SFX_FILTER_EXPORT | SFX_FILTER_USESOPTIONS;
+ SfxFilter* pExportFilter = new SfxFilter(
+ OUString::createFromAscii(pFormat->pFilterName),
+ OUString(), pFormat->nFormatType, nExportFormat,
+ OUString::createFromAscii(pFormat->pTypeName),
+ 0, OUString(),
+ OUString::createFromAscii(pFormat->pUserData),
+ OUString("private:factory/simpress*") );
+ pExportFilter->SetVersion(SOFFICE_FILEFORMAT_CURRENT);
+ aStoreMedium.SetFilter(pExportFilter);
+ pShell->ConvertTo(aStoreMedium);
+ pShell->DoClose();
+ }
+
+ void save(sd::DrawDocShell* pShell, FileFormat* pFormat, utl::TempFile& rTempFile)
+ {
+ SfxMedium aStoreMedium(rTempFile.GetURL(), STREAM_STD_WRITE);
sal_uInt32 nExportFormat = 0;
- if( pFmt->nFormatType == ODP_FORMAT_TYPE )
+ if (pFormat->nFormatType == ODP_FORMAT_TYPE)
nExportFormat = SFX_FILTER_EXPORT | SFX_FILTER_USESOPTIONS;
SfxFilter* pExportFilter = new SfxFilter(
- OUString::createFromAscii( pFmt->pFilterName ),
- OUString(), pFmt->nFormatType, nExportFormat,
- OUString::createFromAscii( pFmt->pTypeName ),
- 0, OUString(),
- OUString::createFromAscii( pFmt->pUserData ),
- OUString("private:factory/simpress*") );
- pExportFilter->SetVersion( SOFFICE_FILEFORMAT_CURRENT );
- aStoreMedium.SetFilter( pExportFilter );
- pShell->DoSaveAs( aStoreMedium );
+ OUString::createFromAscii(pFormat->pFilterName),
+ OUString(), pFormat->nFormatType, nExportFormat,
+ OUString::createFromAscii(pFormat->pTypeName),
+ 0, OUString(),
+ OUString::createFromAscii(pFormat->pUserData),
+ OUString("private:factory/simpress*") );
+ pExportFilter->SetVersion(SOFFICE_FILEFORMAT_CURRENT);
+ aStoreMedium.SetFilter(pExportFilter);
+ pShell->DoSaveAs(aStoreMedium);
pShell->DoClose();
+ }
- return loadURL( aTempFile.GetURL() );
+ sd::DrawDocShellRef saveAndReload(sd::DrawDocShell *pShell, sal_Int32 nExportType)
+ {
+ FileFormat* pFormat = getFormat(nExportType);
+ OUString aExt = OUString( "." ) + OUString::createFromAscii(pFormat->pName);
+ utl::TempFile aTempFile(OUString(), &aExt);
+ aTempFile.EnableKillingFile();
+ save(pShell, pFormat, aTempFile);
+ return loadURL(aTempFile.GetURL());
}
/** Dump shapes in xDocShRef, and compare the dump against content of pShapesDumpFileNameBase<number>.xml.