From 675a74d5e57af8f6f3a30b69122cbd5faf392a86 Mon Sep 17 00:00:00 2001 From: David Tardon Date: Thu, 1 Dec 2016 16:18:37 +0100 Subject: rename to better match the purpose Change-Id: I7cd8e551c284045fbe782cc9756e283d466fd1bc --- writerperfect/CppunitTest_writerperfect_calc.mk | 2 +- writerperfect/CppunitTest_writerperfect_draw.mk | 2 +- writerperfect/CppunitTest_writerperfect_impress.mk | 2 +- writerperfect/CppunitTest_writerperfect_writer.mk | 2 +- writerperfect/Module_writerperfect.mk | 2 +- .../StaticLibrary_writerperfect_filtertestbase.mk | 35 ++++ .../StaticLibrary_writerperfect_importtestbase.mk | 35 ---- writerperfect/qa/unit/WpftCalcFilterTest.cxx | 6 +- writerperfect/qa/unit/WpftDrawFilterTest.cxx | 6 +- writerperfect/qa/unit/WpftFilterTestBase.cxx | 218 +++++++++++++++++++++ writerperfect/qa/unit/WpftFilterTestBase.hxx | 117 +++++++++++ writerperfect/qa/unit/WpftImportTestBase.cxx | 218 --------------------- writerperfect/qa/unit/WpftImportTestBase.hxx | 117 ----------- writerperfect/qa/unit/WpftImpressFilterTest.cxx | 6 +- writerperfect/qa/unit/WpftWriterFilterTest.cxx | 6 +- 15 files changed, 387 insertions(+), 387 deletions(-) create mode 100644 writerperfect/StaticLibrary_writerperfect_filtertestbase.mk delete mode 100644 writerperfect/StaticLibrary_writerperfect_importtestbase.mk create mode 100644 writerperfect/qa/unit/WpftFilterTestBase.cxx create mode 100644 writerperfect/qa/unit/WpftFilterTestBase.hxx delete mode 100644 writerperfect/qa/unit/WpftImportTestBase.cxx delete mode 100644 writerperfect/qa/unit/WpftImportTestBase.hxx (limited to 'writerperfect') diff --git a/writerperfect/CppunitTest_writerperfect_calc.mk b/writerperfect/CppunitTest_writerperfect_calc.mk index 04c8a2e54087..c7a8327c397a 100644 --- a/writerperfect/CppunitTest_writerperfect_calc.mk +++ b/writerperfect/CppunitTest_writerperfect_calc.mk @@ -28,7 +28,7 @@ $(eval $(call gb_CppunitTest_use_libraries,writerperfect_calc,\ )) $(eval $(call gb_CppunitTest_use_static_libraries,writerperfect_calc,\ - writerperfect_importtestbase \ + writerperfect_filtertestbase \ )) $(eval $(call gb_CppunitTest_use_ure,writerperfect_calc)) diff --git a/writerperfect/CppunitTest_writerperfect_draw.mk b/writerperfect/CppunitTest_writerperfect_draw.mk index 24f7ce40b88b..bd7a582d0d15 100644 --- a/writerperfect/CppunitTest_writerperfect_draw.mk +++ b/writerperfect/CppunitTest_writerperfect_draw.mk @@ -28,7 +28,7 @@ $(eval $(call gb_CppunitTest_use_libraries,writerperfect_draw,\ )) $(eval $(call gb_CppunitTest_use_static_libraries,writerperfect_draw,\ - writerperfect_importtestbase \ + writerperfect_filtertestbase \ )) $(eval $(call gb_CppunitTest_use_ure,writerperfect_draw)) diff --git a/writerperfect/CppunitTest_writerperfect_impress.mk b/writerperfect/CppunitTest_writerperfect_impress.mk index 9e8574790d1e..352da2bee3f6 100644 --- a/writerperfect/CppunitTest_writerperfect_impress.mk +++ b/writerperfect/CppunitTest_writerperfect_impress.mk @@ -28,7 +28,7 @@ $(eval $(call gb_CppunitTest_use_libraries,writerperfect_impress,\ )) $(eval $(call gb_CppunitTest_use_static_libraries,writerperfect_impress,\ - writerperfect_importtestbase \ + writerperfect_filtertestbase \ )) $(eval $(call gb_CppunitTest_use_ure,writerperfect_impress)) diff --git a/writerperfect/CppunitTest_writerperfect_writer.mk b/writerperfect/CppunitTest_writerperfect_writer.mk index e9337009111f..3d20725fa344 100644 --- a/writerperfect/CppunitTest_writerperfect_writer.mk +++ b/writerperfect/CppunitTest_writerperfect_writer.mk @@ -28,7 +28,7 @@ $(eval $(call gb_CppunitTest_use_libraries,writerperfect_writer,\ )) $(eval $(call gb_CppunitTest_use_static_libraries,writerperfect_writer,\ - writerperfect_importtestbase \ + writerperfect_filtertestbase \ )) $(eval $(call gb_CppunitTest_use_ure,writerperfect_writer)) diff --git a/writerperfect/Module_writerperfect.mk b/writerperfect/Module_writerperfect.mk index 860a213f9536..c6a3b042ec4d 100644 --- a/writerperfect/Module_writerperfect.mk +++ b/writerperfect/Module_writerperfect.mk @@ -41,7 +41,7 @@ $(eval $(call gb_Module_add_slowcheck_targets,writerperfect,\ CppunitTest_writerperfect_draw \ CppunitTest_writerperfect_impress \ CppunitTest_writerperfect_writer \ - StaticLibrary_writerperfect_importtestbase \ + StaticLibrary_writerperfect_filtertestbase \ )) # vim: set noet sw=4 ts=4: diff --git a/writerperfect/StaticLibrary_writerperfect_filtertestbase.mk b/writerperfect/StaticLibrary_writerperfect_filtertestbase.mk new file mode 100644 index 000000000000..379964caad8f --- /dev/null +++ b/writerperfect/StaticLibrary_writerperfect_filtertestbase.mk @@ -0,0 +1,35 @@ +# -*- 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_StaticLibrary_StaticLibrary,writerperfect_filtertestbase)) + +$(eval $(call gb_StaticLibrary_set_include,writerperfect_filtertestbase,\ + -I$(SRCDIR)/writerperfect/qa/unit \ + $$(INCLUDE) \ +)) + +$(eval $(call gb_StaticLibrary_use_externals,writerperfect_filtertestbase,\ + boost_headers \ + cppunit \ +)) + +$(eval $(call gb_StaticLibrary_use_sdk_api,writerperfect_filtertestbase)) + +$(eval $(call gb_StaticLibrary_use_libraries,writerperfect_filtertestbase,\ + cppu \ + sal \ + test \ + unotest \ +)) + +$(eval $(call gb_StaticLibrary_add_exception_objects,writerperfect_filtertestbase,\ + writerperfect/qa/unit/WpftFilterTestBase \ +)) + +# vim: set noet sw=4 ts=4: diff --git a/writerperfect/StaticLibrary_writerperfect_importtestbase.mk b/writerperfect/StaticLibrary_writerperfect_importtestbase.mk deleted file mode 100644 index bdd79708076a..000000000000 --- a/writerperfect/StaticLibrary_writerperfect_importtestbase.mk +++ /dev/null @@ -1,35 +0,0 @@ -# -*- 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_StaticLibrary_StaticLibrary,writerperfect_importtestbase)) - -$(eval $(call gb_StaticLibrary_set_include,writerperfect_importtestbase,\ - -I$(SRCDIR)/writerperfect/qa/unit \ - $$(INCLUDE) \ -)) - -$(eval $(call gb_StaticLibrary_use_externals,writerperfect_importtestbase,\ - boost_headers \ - cppunit \ -)) - -$(eval $(call gb_StaticLibrary_use_sdk_api,writerperfect_importtestbase)) - -$(eval $(call gb_StaticLibrary_use_libraries,writerperfect_importtestbase,\ - cppu \ - sal \ - test \ - unotest \ -)) - -$(eval $(call gb_StaticLibrary_add_exception_objects,writerperfect_importtestbase,\ - writerperfect/qa/unit/WpftImportTestBase \ -)) - -# vim: set noet sw=4 ts=4: diff --git a/writerperfect/qa/unit/WpftCalcFilterTest.cxx b/writerperfect/qa/unit/WpftCalcFilterTest.cxx index 98c43024a821..ce799956b3d0 100644 --- a/writerperfect/qa/unit/WpftCalcFilterTest.cxx +++ b/writerperfect/qa/unit/WpftCalcFilterTest.cxx @@ -7,12 +7,12 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "WpftImportTestBase.hxx" +#include "WpftFilterTestBase.hxx" namespace { -class WpftCalcFilterTest : public writerperfect::test::WpftImportTestBase +class WpftCalcFilterTest : public writerperfect::test::WpftFilterTestBase { public: WpftCalcFilterTest(); @@ -25,7 +25,7 @@ public: }; WpftCalcFilterTest::WpftCalcFilterTest() - : writerperfect::test::WpftImportTestBase("private:factory/scalc") + : writerperfect::test::WpftFilterTestBase("private:factory/scalc") { } diff --git a/writerperfect/qa/unit/WpftDrawFilterTest.cxx b/writerperfect/qa/unit/WpftDrawFilterTest.cxx index b2c9bb823b6d..95a85c4ef52b 100644 --- a/writerperfect/qa/unit/WpftDrawFilterTest.cxx +++ b/writerperfect/qa/unit/WpftDrawFilterTest.cxx @@ -7,12 +7,12 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "WpftImportTestBase.hxx" +#include "WpftFilterTestBase.hxx" namespace { -class WpftDrawFilterTest : public writerperfect::test::WpftImportTestBase +class WpftDrawFilterTest : public writerperfect::test::WpftFilterTestBase { public: WpftDrawFilterTest(); @@ -25,7 +25,7 @@ public: }; WpftDrawFilterTest::WpftDrawFilterTest() - : writerperfect::test::WpftImportTestBase("private:factory/sdraw") + : writerperfect::test::WpftFilterTestBase("private:factory/sdraw") { } diff --git a/writerperfect/qa/unit/WpftFilterTestBase.cxx b/writerperfect/qa/unit/WpftFilterTestBase.cxx new file mode 100644 index 000000000000..c5b0eb698136 --- /dev/null +++ b/writerperfect/qa/unit/WpftFilterTestBase.cxx @@ -0,0 +1,218 @@ +/* -*- 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 + +#include + +#include + +#include "WpftFilterTestBase.hxx" + +namespace beans = com::sun::star::beans; +namespace container = com::sun::star::container; +namespace document = com::sun::star::document; +namespace frame = com::sun::star::frame; +namespace io = com::sun::star::io; +namespace lang = com::sun::star::lang; +namespace ucb = com::sun::star::ucb; +namespace uno = com::sun::star::uno; +namespace util = com::sun::star::util; + +namespace writerperfect +{ +namespace test +{ + +WpftFilterTestBase::WpftFilterTestBase(const rtl::OUString &rFactoryURL) + : ::test::FiltersTest() + , ::test::BootstrapFixture() + , m_aFactoryURL(rFactoryURL) + , m_xDesktop() + , m_xFilter() + , m_xTypeMap() + , m_pOptionalMap(nullptr) +{ +} + +void WpftFilterTestBase::setUp() +{ + ::test::BootstrapFixture::setUp(); + + m_xDesktop = frame::theDesktop::get(m_xContext); + + const uno::Reference xTypeDetection( + m_xFactory->createInstanceWithContext("com.sun.star.document.TypeDetection", m_xContext), + uno::UNO_QUERY_THROW); + m_xTypeMap.set(xTypeDetection, uno::UNO_QUERY_THROW); +} + +void WpftFilterTestBase::tearDown() +{ + m_xDesktop->terminate(); + + ::test::BootstrapFixture::tearDown(); +} + +bool WpftFilterTestBase::load(const OUString &, const OUString &rURL, const OUString &, + SfxFilterFlags, SotClipboardFormatId, unsigned int) +{ + if (m_pOptionalMap) + { + // first check if this test file is supported by the used version of the library + const INetURLObject aUrl(rURL); + const WpftOptionalMap_t::const_iterator it(m_pOptionalMap->find(aUrl.getName())); + if ((it != m_pOptionalMap->end()) && !it->second) + return true; // skip the file + } + + // create an empty frame + const uno::Reference xDoc( + m_xDesktop->loadComponentFromURL(m_aFactoryURL, "_blank", 0, uno::Sequence()), + uno::UNO_QUERY_THROW); + + // Find the model and frame. We need them later. + uno::Reference xFrame(xDoc, uno::UNO_QUERY); + uno::Reference xModel(xDoc, uno::UNO_QUERY); + uno::Reference xController(xDoc, uno::UNO_QUERY); + + if (xFrame.is()) + { + xController = xFrame->getController(); + xModel = xController->getModel(); + } + else if (xModel.is()) + { + xController = xModel->getCurrentController(); + xFrame = xController->getFrame(); + } + else if (xController.is()) + { + xFrame = xController->getFrame(); + xModel = xController->getModel(); + } + + if (!xFrame.is() || !xModel.is()) + throw uno::RuntimeException(); + + bool result = false; + + // try to import the document (and load it into the prepared frame) + try + { + const uno::Reference xImporter(m_xFilter, uno::UNO_QUERY_THROW); + + xImporter->setTargetDocument(xDoc); + + uno::Sequence aDescriptor(3); + ucbhelper::Content aContent(rURL, uno::Reference(), m_xContext); + + aDescriptor[0].Name = "URL"; + aDescriptor[0].Value <<= rURL; + aDescriptor[1].Name = "InputStream"; + aDescriptor[1].Value <<= aContent.openStream(); + aDescriptor[2].Name = "UCBContent"; + aDescriptor[2].Value <<= aContent.get(); + + const uno::Reference xDetector(m_xFilter, uno::UNO_QUERY_THROW); + + const rtl::OUString aTypeName(xDetector->detect(aDescriptor)); + if (aTypeName.isEmpty()) + throw lang::IllegalArgumentException(); + + impl_detectFilterName(aDescriptor, aTypeName); + + xModel->lockControllers(); + result = m_xFilter->filter(aDescriptor); + xModel->unlockControllers(); + } + catch (const uno::Exception &) + { + // ignore + } + + // close the opened document + try + { + uno::Reference xCloseable(xFrame, uno::UNO_QUERY); + if (xCloseable.is()) + xCloseable->close(true); + else + xDoc->dispose(); + } + catch (const uno::Exception &) + { + // ignore + } + + return result; +} + +void WpftFilterTestBase::doTest(const rtl::OUString &rFilter, const rtl::OUString &rPath) +{ + m_xFilter.set(m_xFactory->createInstanceWithContext(rFilter, m_xContext), uno::UNO_QUERY_THROW); + testDir(OUString(), m_directories.getURLFromSrc(rPath)); +} + +void WpftFilterTestBase::doTest(const rtl::OUString &rFilter, const rtl::OUString &rPath, const WpftOptionalMap_t &rOptionalMap) +{ + m_xFilter.set(m_xFactory->createInstanceWithContext(rFilter, m_xContext), uno::UNO_QUERY_THROW); + m_pOptionalMap = &rOptionalMap; + testDir(OUString(), m_directories.getURLFromSrc(rPath)); + m_pOptionalMap = nullptr; +} + +void WpftFilterTestBase::impl_detectFilterName(uno::Sequence &rDescriptor, const rtl::OUString &rTypeName) +{ + const sal_Int32 nDescriptorLen = rDescriptor.getLength(); + + for (sal_Int32 n = 0; nDescriptorLen != n; ++n) + { + if ("FilterName" == rDescriptor[n].Name) + return; + } + + uno::Sequence aTypes; + if (m_xTypeMap->getByName(rTypeName) >>= aTypes) + { + for (sal_Int32 n = 0; aTypes.getLength() != n; ++n) + { + rtl::OUString aFilterName; + if (("PreferredFilter" == aTypes[n].Name) && (aTypes[n].Value >>= aFilterName)) + { + rDescriptor.realloc(nDescriptorLen + 1); + rDescriptor[nDescriptorLen].Name = "FilterName"; + rDescriptor[nDescriptorLen].Value <<= aFilterName; + return; + } + } + } + + throw container::NoSuchElementException(); +} + +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/qa/unit/WpftFilterTestBase.hxx b/writerperfect/qa/unit/WpftFilterTestBase.hxx new file mode 100644 index 000000000000..c6eb9c315c77 --- /dev/null +++ b/writerperfect/qa/unit/WpftFilterTestBase.hxx @@ -0,0 +1,117 @@ +/* -*- 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/. + */ + +#ifndef INCLUDED_WRITERPERFECT_QA_UNIT_WPFTFILTERTESTBASE_HXX +#define INCLUDED_WRITERPERFECT_QA_UNIT_WPFTFILTERTESTBASE_HXX + +#include "config_writerperfect.h" + +#include + +#include +#include + +#include + +#include + +#include + +#define REQUIRE_VERSION(major, minor, micro, req_major, req_minor, req_micro) \ + (major) > (req_major) || \ + ((major) == (req_major) && \ + ((minor) > (req_minor) \ + || ((minor) == (req_minor) && ((micro) >= (req_micro))))) + +#define REQUIRE_EBOOK_VERSION(major, minor, micro) \ + REQUIRE_VERSION(EBOOK_VERSION_MAJOR, EBOOK_VERSION_MINOR, EBOOK_VERSION_MICRO, major, minor, micro) + +#define REQUIRE_ETONYEK_VERSION(major, minor, micro) \ + REQUIRE_VERSION(ETONYEK_VERSION_MAJOR, ETONYEK_VERSION_MINOR, ETONYEK_VERSION_MICRO, major, minor, micro) + +#define REQUIRE_MWAW_VERSION(major, minor, micro) \ + REQUIRE_VERSION(MWAW_VERSION_MAJOR, MWAW_VERSION_MINOR, MWAW_VERSION_MICRO, major, minor, micro) + +#define REQUIRE_STAROFFICE_VERSION(major, minor, micro) \ + REQUIRE_VERSION(STAROFFICE_VERSION_MAJOR, STAROFFICE_VERSION_MINOR, STAROFFICE_VERSION_MICRO, major, minor, micro) + +#define REQUIRE_WPS_VERSION(major, minor, micro) \ + REQUIRE_VERSION(WPS_VERSION_MAJOR, WPS_VERSION_MINOR, WPS_VERSION_MICRO, major, minor, micro) + +namespace com +{ +namespace sun +{ +namespace star +{ +namespace beans +{ +struct PropertyValue; +} +namespace container +{ +class XNameAccess; +} +namespace document +{ +class XFilter; +} +namespace frame +{ +class XDesktop2; +} +namespace ucb +{ +class XSimpleFileAccess; +} +} +} +} + +namespace writerperfect +{ +namespace test +{ + +typedef std::unordered_map WpftOptionalMap_t; + +class WpftFilterTestBase + : public ::test::FiltersTest + , public ::test::BootstrapFixture +{ +public: + explicit WpftFilterTestBase(const rtl::OUString &rFactoryURL); + + virtual void setUp() override; + virtual void tearDown() override; + +protected: + void doTest(const rtl::OUString &rFilter, const rtl::OUString &rPath); + void doTest(const rtl::OUString &rFilter, const rtl::OUString &rPath, const WpftOptionalMap_t &rOptionalMap); + +private: + virtual bool load(const OUString &, const OUString &rURL, const OUString &, + SfxFilterFlags, SotClipboardFormatId, unsigned int) override; + + void impl_detectFilterName(css::uno::Sequence &rDescriptor, const rtl::OUString &rTypeName); + +private: + const rtl::OUString m_aFactoryURL; + css::uno::Reference m_xDesktop; + css::uno::Reference m_xFilter; + css::uno::Reference m_xTypeMap; + const WpftOptionalMap_t *m_pOptionalMap; +}; + +} +} + +#endif // INCLUDED_WRITERPERFECT_QA_UNIT_WPFTFILTERTESTBASE_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/qa/unit/WpftImportTestBase.cxx b/writerperfect/qa/unit/WpftImportTestBase.cxx deleted file mode 100644 index 66bc021d992d..000000000000 --- a/writerperfect/qa/unit/WpftImportTestBase.cxx +++ /dev/null @@ -1,218 +0,0 @@ -/* -*- 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 - -#include - -#include - -#include "WpftImportTestBase.hxx" - -namespace beans = com::sun::star::beans; -namespace container = com::sun::star::container; -namespace document = com::sun::star::document; -namespace frame = com::sun::star::frame; -namespace io = com::sun::star::io; -namespace lang = com::sun::star::lang; -namespace ucb = com::sun::star::ucb; -namespace uno = com::sun::star::uno; -namespace util = com::sun::star::util; - -namespace writerperfect -{ -namespace test -{ - -WpftImportTestBase::WpftImportTestBase(const rtl::OUString &rFactoryURL) - : ::test::FiltersTest() - , ::test::BootstrapFixture() - , m_aFactoryURL(rFactoryURL) - , m_xDesktop() - , m_xFilter() - , m_xTypeMap() - , m_pOptionalMap(nullptr) -{ -} - -void WpftImportTestBase::setUp() -{ - ::test::BootstrapFixture::setUp(); - - m_xDesktop = frame::theDesktop::get(m_xContext); - - const uno::Reference xTypeDetection( - m_xFactory->createInstanceWithContext("com.sun.star.document.TypeDetection", m_xContext), - uno::UNO_QUERY_THROW); - m_xTypeMap.set(xTypeDetection, uno::UNO_QUERY_THROW); -} - -void WpftImportTestBase::tearDown() -{ - m_xDesktop->terminate(); - - ::test::BootstrapFixture::tearDown(); -} - -bool WpftImportTestBase::load(const OUString &, const OUString &rURL, const OUString &, - SfxFilterFlags, SotClipboardFormatId, unsigned int) -{ - if (m_pOptionalMap) - { - // first check if this test file is supported by the used version of the library - const INetURLObject aUrl(rURL); - const WpftOptionalMap_t::const_iterator it(m_pOptionalMap->find(aUrl.getName())); - if ((it != m_pOptionalMap->end()) && !it->second) - return true; // skip the file - } - - // create an empty frame - const uno::Reference xDoc( - m_xDesktop->loadComponentFromURL(m_aFactoryURL, "_blank", 0, uno::Sequence()), - uno::UNO_QUERY_THROW); - - // Find the model and frame. We need them later. - uno::Reference xFrame(xDoc, uno::UNO_QUERY); - uno::Reference xModel(xDoc, uno::UNO_QUERY); - uno::Reference xController(xDoc, uno::UNO_QUERY); - - if (xFrame.is()) - { - xController = xFrame->getController(); - xModel = xController->getModel(); - } - else if (xModel.is()) - { - xController = xModel->getCurrentController(); - xFrame = xController->getFrame(); - } - else if (xController.is()) - { - xFrame = xController->getFrame(); - xModel = xController->getModel(); - } - - if (!xFrame.is() || !xModel.is()) - throw uno::RuntimeException(); - - bool result = false; - - // try to import the document (and load it into the prepared frame) - try - { - const uno::Reference xImporter(m_xFilter, uno::UNO_QUERY_THROW); - - xImporter->setTargetDocument(xDoc); - - uno::Sequence aDescriptor(3); - ucbhelper::Content aContent(rURL, uno::Reference(), m_xContext); - - aDescriptor[0].Name = "URL"; - aDescriptor[0].Value <<= rURL; - aDescriptor[1].Name = "InputStream"; - aDescriptor[1].Value <<= aContent.openStream(); - aDescriptor[2].Name = "UCBContent"; - aDescriptor[2].Value <<= aContent.get(); - - const uno::Reference xDetector(m_xFilter, uno::UNO_QUERY_THROW); - - const rtl::OUString aTypeName(xDetector->detect(aDescriptor)); - if (aTypeName.isEmpty()) - throw lang::IllegalArgumentException(); - - impl_detectFilterName(aDescriptor, aTypeName); - - xModel->lockControllers(); - result = m_xFilter->filter(aDescriptor); - xModel->unlockControllers(); - } - catch (const uno::Exception &) - { - // ignore - } - - // close the opened document - try - { - uno::Reference xCloseable(xFrame, uno::UNO_QUERY); - if (xCloseable.is()) - xCloseable->close(true); - else - xDoc->dispose(); - } - catch (const uno::Exception &) - { - // ignore - } - - return result; -} - -void WpftImportTestBase::doTest(const rtl::OUString &rFilter, const rtl::OUString &rPath) -{ - m_xFilter.set(m_xFactory->createInstanceWithContext(rFilter, m_xContext), uno::UNO_QUERY_THROW); - testDir(OUString(), m_directories.getURLFromSrc(rPath)); -} - -void WpftImportTestBase::doTest(const rtl::OUString &rFilter, const rtl::OUString &rPath, const WpftOptionalMap_t &rOptionalMap) -{ - m_xFilter.set(m_xFactory->createInstanceWithContext(rFilter, m_xContext), uno::UNO_QUERY_THROW); - m_pOptionalMap = &rOptionalMap; - testDir(OUString(), m_directories.getURLFromSrc(rPath)); - m_pOptionalMap = nullptr; -} - -void WpftImportTestBase::impl_detectFilterName(uno::Sequence &rDescriptor, const rtl::OUString &rTypeName) -{ - const sal_Int32 nDescriptorLen = rDescriptor.getLength(); - - for (sal_Int32 n = 0; nDescriptorLen != n; ++n) - { - if ("FilterName" == rDescriptor[n].Name) - return; - } - - uno::Sequence aTypes; - if (m_xTypeMap->getByName(rTypeName) >>= aTypes) - { - for (sal_Int32 n = 0; aTypes.getLength() != n; ++n) - { - rtl::OUString aFilterName; - if (("PreferredFilter" == aTypes[n].Name) && (aTypes[n].Value >>= aFilterName)) - { - rDescriptor.realloc(nDescriptorLen + 1); - rDescriptor[nDescriptorLen].Name = "FilterName"; - rDescriptor[nDescriptorLen].Value <<= aFilterName; - return; - } - } - } - - throw container::NoSuchElementException(); -} - -} -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/qa/unit/WpftImportTestBase.hxx b/writerperfect/qa/unit/WpftImportTestBase.hxx deleted file mode 100644 index a3baec93a3e7..000000000000 --- a/writerperfect/qa/unit/WpftImportTestBase.hxx +++ /dev/null @@ -1,117 +0,0 @@ -/* -*- 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/. - */ - -#ifndef INCLUDED_WRITERPERFECT_QA_UNIT_WPFTIMPORTTESTBASE_HXX -#define INCLUDED_WRITERPERFECT_QA_UNIT_WPFTIMPORTTESTBASE_HXX - -#include "config_writerperfect.h" - -#include - -#include -#include - -#include - -#include - -#include - -#define REQUIRE_VERSION(major, minor, micro, req_major, req_minor, req_micro) \ - (major) > (req_major) || \ - ((major) == (req_major) && \ - ((minor) > (req_minor) \ - || ((minor) == (req_minor) && ((micro) >= (req_micro))))) - -#define REQUIRE_EBOOK_VERSION(major, minor, micro) \ - REQUIRE_VERSION(EBOOK_VERSION_MAJOR, EBOOK_VERSION_MINOR, EBOOK_VERSION_MICRO, major, minor, micro) - -#define REQUIRE_ETONYEK_VERSION(major, minor, micro) \ - REQUIRE_VERSION(ETONYEK_VERSION_MAJOR, ETONYEK_VERSION_MINOR, ETONYEK_VERSION_MICRO, major, minor, micro) - -#define REQUIRE_MWAW_VERSION(major, minor, micro) \ - REQUIRE_VERSION(MWAW_VERSION_MAJOR, MWAW_VERSION_MINOR, MWAW_VERSION_MICRO, major, minor, micro) - -#define REQUIRE_STAROFFICE_VERSION(major, minor, micro) \ - REQUIRE_VERSION(STAROFFICE_VERSION_MAJOR, STAROFFICE_VERSION_MINOR, STAROFFICE_VERSION_MICRO, major, minor, micro) - -#define REQUIRE_WPS_VERSION(major, minor, micro) \ - REQUIRE_VERSION(WPS_VERSION_MAJOR, WPS_VERSION_MINOR, WPS_VERSION_MICRO, major, minor, micro) - -namespace com -{ -namespace sun -{ -namespace star -{ -namespace beans -{ -struct PropertyValue; -} -namespace container -{ -class XNameAccess; -} -namespace document -{ -class XFilter; -} -namespace frame -{ -class XDesktop2; -} -namespace ucb -{ -class XSimpleFileAccess; -} -} -} -} - -namespace writerperfect -{ -namespace test -{ - -typedef std::unordered_map WpftOptionalMap_t; - -class WpftImportTestBase - : public ::test::FiltersTest - , public ::test::BootstrapFixture -{ -public: - explicit WpftImportTestBase(const rtl::OUString &rFactoryURL); - - virtual void setUp() override; - virtual void tearDown() override; - -protected: - void doTest(const rtl::OUString &rFilter, const rtl::OUString &rPath); - void doTest(const rtl::OUString &rFilter, const rtl::OUString &rPath, const WpftOptionalMap_t &rOptionalMap); - -private: - virtual bool load(const OUString &, const OUString &rURL, const OUString &, - SfxFilterFlags, SotClipboardFormatId, unsigned int) override; - - void impl_detectFilterName(css::uno::Sequence &rDescriptor, const rtl::OUString &rTypeName); - -private: - const rtl::OUString m_aFactoryURL; - css::uno::Reference m_xDesktop; - css::uno::Reference m_xFilter; - css::uno::Reference m_xTypeMap; - const WpftOptionalMap_t *m_pOptionalMap; -}; - -} -} - -#endif // INCLUDED_WRITERPERFECT_QA_UNIT_WPFTIMPORTTESTBASE_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/qa/unit/WpftImpressFilterTest.cxx b/writerperfect/qa/unit/WpftImpressFilterTest.cxx index ce69dcdc6a2f..5738c97de5a2 100644 --- a/writerperfect/qa/unit/WpftImpressFilterTest.cxx +++ b/writerperfect/qa/unit/WpftImpressFilterTest.cxx @@ -7,12 +7,12 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "WpftImportTestBase.hxx" +#include "WpftFilterTestBase.hxx" namespace { -class WpftImpressFilterTest : public writerperfect::test::WpftImportTestBase +class WpftImpressFilterTest : public writerperfect::test::WpftFilterTestBase { public: WpftImpressFilterTest(); @@ -25,7 +25,7 @@ public: }; WpftImpressFilterTest::WpftImpressFilterTest() - : writerperfect::test::WpftImportTestBase("private:factory/simpress") + : writerperfect::test::WpftFilterTestBase("private:factory/simpress") { } diff --git a/writerperfect/qa/unit/WpftWriterFilterTest.cxx b/writerperfect/qa/unit/WpftWriterFilterTest.cxx index 3e9c6bad9105..515a2b8a7e92 100644 --- a/writerperfect/qa/unit/WpftWriterFilterTest.cxx +++ b/writerperfect/qa/unit/WpftWriterFilterTest.cxx @@ -7,12 +7,12 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "WpftImportTestBase.hxx" +#include "WpftFilterTestBase.hxx" namespace { -class WpftWriterFilterTest : public writerperfect::test::WpftImportTestBase +class WpftWriterFilterTest : public writerperfect::test::WpftFilterTestBase { public: WpftWriterFilterTest(); @@ -25,7 +25,7 @@ public: }; WpftWriterFilterTest::WpftWriterFilterTest() - : writerperfect::test::WpftImportTestBase("private:factory/swriter") + : writerperfect::test::WpftFilterTestBase("private:factory/swriter") { } -- cgit