diff --git a/filter/CppunitTest_filter_xslt.mk b/filter/CppunitTest_filter_xslt.mk new file mode 100644 index 000000000000..430222895897 --- /dev/null +++ b/filter/CppunitTest_filter_xslt.mk @@ -0,0 +1,43 @@ +# -*- 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,filter_xslt)) + +$(eval $(call gb_CppunitTest_use_api,filter_xslt,\ + offapi \ + udkapi \ +)) + +$(eval $(call gb_CppunitTest_use_ure,filter_xslt)) + +$(eval $(call gb_CppunitTest_use_configuration,filter_xslt)) + +$(eval $(call gb_CppunitTest_use_libraries,filter_xslt, \ + comphelper \ + test \ + unotest \ + cppuhelper \ + cppu \ + sal \ + $(gb_UWINAPI) \ +)) + +$(eval $(call gb_CppunitTest_use_components,filter_xslt,\ + configmgr/source/configmgr \ + filter/source/xsltfilter/xsltfilter \ + i18npool/util/i18npool \ + ucb/source/core/ucb1 \ + ucb/source/ucp/file/ucpfile1 \ +)) + +$(eval $(call gb_CppunitTest_add_exception_objects,filter_xslt, \ + filter/qa/cppunit/xslt-test \ +)) + +# vim: set noet sw=4 ts=4: diff --git a/filter/Module_filter.mk b/filter/Module_filter.mk index 403184a93feb..e5d67e74ef85 100644 --- a/filter/Module_filter.mk +++ b/filter/Module_filter.mk @@ -77,6 +77,10 @@ $(eval $(call gb_Module_add_targets,filter,\ )) endif +$(eval $(call gb_Module_add_check_targets,filter,\ + CppunitTest_filter_xslt \ +)) + ifneq ($(DISABLE_CVE_TESTS),TRUE) $(eval $(call gb_Module_add_check_targets,filter,\ CppunitTest_filter_pict_test \ diff --git a/filter/qa/cppunit/data/xslt/copy.xslt b/filter/qa/cppunit/data/xslt/copy.xslt new file mode 100644 index 000000000000..d46172a418aa --- /dev/null +++ b/filter/qa/cppunit/data/xslt/copy.xslt @@ -0,0 +1,9 @@ + + + + + + + + diff --git a/filter/qa/cppunit/xslt-test.cxx b/filter/qa/cppunit/xslt-test.cxx new file mode 100644 index 000000000000..67efde9ba5cb --- /dev/null +++ b/filter/qa/cppunit/xslt-test.cxx @@ -0,0 +1,190 @@ +/* -*- 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 + +#include +#include +#include +#include + +#include + +#include + +#include +#include + +#include +#include +#include +#include +#include + +#include + +#include + + +using namespace std; +using namespace ::com::sun::star; + + +namespace { + +class XsltFilterTest + : public test::BootstrapFixture +{ +public: + void testXsltCopyOld(); + void testXsltCopyNew(); + + CPPUNIT_TEST_SUITE(XsltFilterTest); + CPPUNIT_TEST(testXsltCopyOld); + CPPUNIT_TEST(testXsltCopyNew); + CPPUNIT_TEST_SUITE_END(); +}; + +struct Listener : public ::cppu::WeakImplHelper1 +{ + bool m_bDone; + + Listener() : m_bDone(false) {} + + virtual void disposing(const lang::EventObject&) throw() SAL_OVERRIDE {} + virtual void SAL_CALL started() throw() SAL_OVERRIDE { m_bDone = false; } + virtual void SAL_CALL closed() throw() SAL_OVERRIDE { m_bDone = true; } + virtual void SAL_CALL terminated() throw() SAL_OVERRIDE { m_bDone = true; } + virtual void SAL_CALL error(const uno::Any& e) throw() SAL_OVERRIDE + { + SAL_WARN("filter.xslt", "exception " << e); + CPPUNIT_FAIL("exception while in XSLT"); + } +}; + +void XsltFilterTest::testXsltCopyNew() +{ + OUString tempDirURL; + osl_getTempDirURL(&tempDirURL.pData); + oslFileHandle tempFile; + OUString tempURL; + osl::File::RC rc = osl::File::createTempFile(0, &tempFile, &tempURL); + CPPUNIT_ASSERT(osl::FileBase::E_None == rc); + + OUString source( + getURLFromSrc("/filter/source/xsltfilter/xsltfilter.component")); + uno::Sequence args(7); + args[0] <<= beans::NamedValue("StylesheetURL", + uno::makeAny(getURLFromSrc("/filter/qa/cppunit/data/xslt/copy.xslt"))); + args[1] <<= beans::NamedValue("SourceURL", uno::makeAny(source)); + args[2] <<= beans::NamedValue("TargetURL", uno::makeAny(tempURL)); + args[3] <<= beans::NamedValue("SourceBaseURL", + uno::makeAny(getURLFromSrc("/filter/source/xsltfilter/"))); + args[4] <<= beans::NamedValue("TargetBaseURL", uno::makeAny(tempDirURL)); + args[5] <<= beans::NamedValue("SystemType", uno::makeAny(OUString())); + args[6] <<= beans::NamedValue("PublicType", uno::makeAny(OUString())); + + uno::Reference xSFA = + ucb::SimpleFileAccess::create(getComponentContext()); + + uno::Reference xIn = xSFA->openFileRead(source); + uno::Reference xOut = xSFA->openFileWrite(tempURL); + + rtl::Reference xListener = new Listener(); + + uno::Reference xXslt( + xml::xslt::XSLTTransformer::create(getComponentContext(), args)); + + xXslt->addListener(uno::Reference(xListener.get())); + xXslt->setInputStream(xIn); + xXslt->setOutputStream(xOut); + + xXslt->start(); + + TimeValue delay; + delay.Seconds = 0; + delay.Nanosec = 1000000; + while (!xListener->m_bDone) { osl_waitThread(&delay); } + + xIn->closeInput(); + xOut->closeOutput(); + + osl::File foo(tempURL); // apparently it's necessary to open it again? + foo.open(osl_File_OpenFlag_Read); + sal_uInt64 size(0); + foo.getSize(size); + CPPUNIT_ASSERT(size > 1000); // check that something happened +} + +void XsltFilterTest::testXsltCopyOld() +{ + OUString tempDirURL; + osl_getTempDirURL(&tempDirURL.pData); + oslFileHandle tempFile; + OUString tempURL; + osl::File::RC rc = osl::File::createTempFile(0, &tempFile, &tempURL); + CPPUNIT_ASSERT(osl::FileBase::E_None == rc); + + OUString source( + getURLFromSrc("/filter/source/xsltfilter/xsltfilter.component")); + uno::Sequence args(7); + args[0] <<= beans::NamedValue("StylesheetURL", + uno::makeAny(getURLFromSrc("/filter/qa/cppunit/data/xslt/copy.xslt"))); + args[1] <<= beans::NamedValue("SourceURL", uno::makeAny(source)); + args[2] <<= beans::NamedValue("TargetURL", uno::makeAny(tempURL)); + args[3] <<= beans::NamedValue("SourceBaseURL", + uno::makeAny(getURLFromSrc("/filter/source/xsltfilter/"))); + args[4] <<= beans::NamedValue("TargetBaseURL", uno::makeAny(tempDirURL)); + args[5] <<= beans::NamedValue("SystemType", uno::makeAny(OUString())); + args[6] <<= beans::NamedValue("PublicType", uno::makeAny(OUString())); + + + uno::Reference xSFA = + ucb::SimpleFileAccess::create(getComponentContext()); + + uno::Reference xIn = xSFA->openFileRead(source); + uno::Reference xOut = xSFA->openFileWrite(tempURL); + + rtl::Reference xListener = new Listener(); + + uno::Reference xXslt( + getMultiServiceFactory()->createInstance( + "com.sun.star.comp.documentconversion.LibXSLTTransformer"), + uno::UNO_QUERY_THROW); + + uno::Reference xInit(xXslt, uno::UNO_QUERY_THROW); + xInit->initialize(args); + xXslt->addListener(uno::Reference(xListener.get())); + xXslt->setInputStream(xIn); + xXslt->setOutputStream(xOut); + + xXslt->start(); + + TimeValue delay; + delay.Seconds = 0; + delay.Nanosec = 1000000; + while (!xListener->m_bDone) { osl_waitThread(&delay); } + + xIn->closeInput(); + xOut->closeOutput(); + + osl::File foo(tempURL); // apparently it's necessary to open it again? + foo.open(osl_File_OpenFlag_Read); + sal_uInt64 size(0); + foo.getSize(size); + CPPUNIT_ASSERT(size > 1000); // check that something happened +} + +CPPUNIT_TEST_SUITE_REGISTRATION(XsltFilterTest); + +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/filter/source/xsltfilter/LibXSLTTransformer.cxx b/filter/source/xsltfilter/LibXSLTTransformer.cxx index f02c916c4a83..949f383c1f47 100644 --- a/filter/source/xsltfilter/LibXSLTTransformer.cxx +++ b/filter/source/xsltfilter/LibXSLTTransformer.cxx @@ -478,7 +478,10 @@ namespace XSLT throw (RuntimeException, std::exception) { Sequence params; - args[0] >>= params; + if (!(args[0] >>= params)) + { // backward compatibility for old clients using createInstance + params = args; + } xmlSubstituteEntitiesDefault(0); m_parameters.clear(); for (int i = 0; i < params.getLength(); i++)