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

sd html: impress html export test

Change-Id: I710868b4cb19cec2820c3cf699dd5d855e3da7e2
üst 87c3fdee
# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
#*************************************************************************
#
# 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/.
#
#*************************************************************************
$(eval $(call gb_CppunitTest_CppunitTest,sd_html_export_tests))
$(eval $(call gb_CppunitTest_use_externals,sd_html_export_tests,\
boost_headers \
libxml2 \
))
$(eval $(call gb_CppunitTest_add_exception_objects,sd_html_export_tests, \
sd/qa/unit/HtmlExportTest \
))
$(eval $(call gb_CppunitTest_use_libraries,sd_html_export_tests, \
avmedia \
basegfx \
comphelper \
cppu \
cppuhelper \
drawinglayer \
editeng \
for \
forui \
i18nlangtag \
msfilter \
oox \
sal \
salhelper \
sax \
sd \
sfx \
sot \
svl \
svt \
svx \
svxcore \
test \
tl \
tk \
ucbhelper \
unotest \
utl \
vcl \
xo \
$(gb_UWINAPI) \
))
$(eval $(call gb_CppunitTest_set_include,sd_html_export_tests,\
-I$(SRCDIR)/sd/source/ui/inc \
-I$(SRCDIR)/sd/inc \
$$(INCLUDE) \
))
$(eval $(call gb_CppunitTest_use_api,sd_html_export_tests,\
offapi \
udkapi \
))
$(eval $(call gb_CppunitTest_use_ure,sd_html_export_tests))
$(eval $(call gb_CppunitTest_use_components,sd_html_export_tests,\
animations/source/animcore/animcore \
basic/util/sb \
chart2/source/chartcore \
chart2/source/controller/chartcontroller \
comphelper/util/comphelp \
configmgr/source/configmgr \
dbaccess/util/dba \
desktop/source/deployment/deployment \
embeddedobj/util/embobj \
filter/source/config/cache/filterconfig1 \
filter/source/svg/svgfilter \
forms/util/frm \
framework/util/fwk \
i18npool/util/i18npool \
linguistic/source/lng \
oox/util/oox \
package/source/xstor/xstor \
package/util/package2 \
sax/source/expatwrap/expwrap \
sd/util/sd \
sd/util/sdfilt \
sd/util/sdd \
sfx2/util/sfx \
sot/util/sot \
svl/source/fsstor/fsstorage \
svtools/util/svt \
svx/util/svxcore \
toolkit/util/tk \
ucb/source/core/ucb1 \
ucb/source/ucp/expand/ucpexpand1 \
ucb/source/ucp/file/ucpfile1 \
ucb/source/ucp/package/ucppkg1 \
ucb/source/ucp/tdoc/ucptdoc1 \
unotools/util/utl \
unoxml/source/rdf/unordf \
unoxml/source/service/unoxml \
xmloff/util/xo \
xmlsecurity/util/xsec_fw \
xmlsecurity/util/xmlsecurity \
))
$(eval $(call gb_CppunitTest_use_configuration,sd_html_export_tests))
$(eval $(call gb_CppunitTest_use_unittest_configuration,sd_html_export_tests))
$(call gb_CppunitTest_get_target,sd_html_export_tests) : $(call gb_AllLangResTarget_get_target,sd)
# vim: set noet sw=4 ts=4:
......@@ -30,6 +30,7 @@ $(eval $(call gb_Module_add_check_targets,sd,\
CppunitTest_sd_uimpress \
CppunitTest_sd_import_tests \
CppunitTest_sd_filters_test \
CppunitTest_sd_html_export_tests \
))
endif
......
/* -*- 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: */
......@@ -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.
......
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