diff options
author | David Tardon <dtardon@redhat.com> | 2016-12-02 15:01:17 +0100 |
---|---|---|
committer | David Tardon <dtardon@redhat.com> | 2016-12-05 10:41:54 +0100 |
commit | e60a60f570ec04eb1c0f94fe43675400f71c786f (patch) | |
tree | 7d8f2f74e0d400c3dfcb1bdd012477e04626b1a4 /writerperfect | |
parent | 675a74d5e57af8f6f3a30b69122cbd5faf392a86 (diff) |
refactor
Change-Id: I0cc034e7521de7911a9f5dfe8bc405971d175754
Diffstat (limited to 'writerperfect')
-rw-r--r-- | writerperfect/StaticLibrary_writerperfect_filtertestbase.mk | 2 | ||||
-rw-r--r-- | writerperfect/qa/unit/WpftFilterFixture.cxx | 47 | ||||
-rw-r--r-- | writerperfect/qa/unit/WpftFilterFixture.hxx | 82 | ||||
-rw-r--r-- | writerperfect/qa/unit/WpftFilterTestBase.cxx | 175 | ||||
-rw-r--r-- | writerperfect/qa/unit/WpftFilterTestBase.hxx | 51 | ||||
-rw-r--r-- | writerperfect/qa/unit/WpftLoader.cxx | 194 | ||||
-rw-r--r-- | writerperfect/qa/unit/WpftLoader.hxx | 97 |
7 files changed, 430 insertions, 218 deletions
diff --git a/writerperfect/StaticLibrary_writerperfect_filtertestbase.mk b/writerperfect/StaticLibrary_writerperfect_filtertestbase.mk index 379964caad8f..8dec6fcfb734 100644 --- a/writerperfect/StaticLibrary_writerperfect_filtertestbase.mk +++ b/writerperfect/StaticLibrary_writerperfect_filtertestbase.mk @@ -29,7 +29,9 @@ $(eval $(call gb_StaticLibrary_use_libraries,writerperfect_filtertestbase,\ )) $(eval $(call gb_StaticLibrary_add_exception_objects,writerperfect_filtertestbase,\ + writerperfect/qa/unit/WpftFilterFixture \ writerperfect/qa/unit/WpftFilterTestBase \ + writerperfect/qa/unit/WpftLoader \ )) # vim: set noet sw=4 ts=4: diff --git a/writerperfect/qa/unit/WpftFilterFixture.cxx b/writerperfect/qa/unit/WpftFilterFixture.cxx new file mode 100644 index 000000000000..6ceb579cf439 --- /dev/null +++ b/writerperfect/qa/unit/WpftFilterFixture.cxx @@ -0,0 +1,47 @@ +/* -*- 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 "WpftFilterFixture.hxx" + +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/document/XTypeDetection.hpp> +#include <com/sun/star/frame/theDesktop.hpp> + +namespace document = com::sun::star::document; +namespace frame = com::sun::star::frame; +namespace uno = com::sun::star::uno; + +namespace writerperfect +{ +namespace test +{ + +void WpftFilterFixture::setUp() +{ + ::test::BootstrapFixture::setUp(); + + m_xDesktop = frame::theDesktop::get(m_xContext); + + const uno::Reference<document::XTypeDetection> xTypeDetection( + m_xFactory->createInstanceWithContext("com.sun.star.document.TypeDetection", m_xContext), + uno::UNO_QUERY_THROW); + m_xTypeMap.set(xTypeDetection, uno::UNO_QUERY_THROW); +} + +void WpftFilterFixture::tearDown() +{ + m_xDesktop->terminate(); + + ::test::BootstrapFixture::tearDown(); +} + +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/qa/unit/WpftFilterFixture.hxx b/writerperfect/qa/unit/WpftFilterFixture.hxx new file mode 100644 index 000000000000..4e45a3845220 --- /dev/null +++ b/writerperfect/qa/unit/WpftFilterFixture.hxx @@ -0,0 +1,82 @@ +/* -*- 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_WPFTFILTERFIXTURE_HXX +#define INCLUDED_WRITERPERFECT_QA_UNIT_WPFTFILTERFIXTURE_HXX + +#include "config_writerperfect.h" + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> + +#include <rtl/ustring.hxx> + +#include <test/bootstrapfixture.hxx> + +#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 container +{ +class XNameAccess; +} +namespace frame +{ +class XDesktop2; +} +} +} +} + +namespace writerperfect +{ +namespace test +{ + +class WpftFilterFixture : public ::test::BootstrapFixture +{ +public: + virtual void setUp() override; + virtual void tearDown() override; + +protected: + css::uno::Reference<css::frame::XDesktop2> m_xDesktop; + css::uno::Reference<css::container::XNameAccess> m_xTypeMap; +}; + +} +} + +#endif // INCLUDED_WRITERPERFECT_QA_UNIT_WPFTFILTERFIXTURE_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/qa/unit/WpftFilterTestBase.cxx b/writerperfect/qa/unit/WpftFilterTestBase.cxx index c5b0eb698136..a0243349c990 100644 --- a/writerperfect/qa/unit/WpftFilterTestBase.cxx +++ b/writerperfect/qa/unit/WpftFilterTestBase.cxx @@ -7,38 +7,13 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include <com/sun/star/beans/PropertyValue.hpp> -#include <com/sun/star/container/NoSuchElementException.hpp> -#include <com/sun/star/container/XNameAccess.hpp> -#include <com/sun/star/document/XExtendedFilterDetection.hpp> -#include <com/sun/star/document/XFilter.hpp> -#include <com/sun/star/document/XImporter.hpp> -#include <com/sun/star/document/XTypeDetection.hpp> -#include <com/sun/star/frame/theDesktop.hpp> -#include <com/sun/star/frame/XController.hpp> -#include <com/sun/star/frame/XFrame.hpp> -#include <com/sun/star/frame/XModel.hpp> -#include <com/sun/star/io/XInputStream.hpp> -#include <com/sun/star/lang/IllegalArgumentException.hpp> -#include <com/sun/star/lang/XComponent.hpp> -#include <com/sun/star/ucb/XContent.hpp> -#include <com/sun/star/util/XCloseable.hpp> - -#include <tools/urlobj.hxx> +#include "WpftFilterTestBase.hxx" -#include <ucbhelper/content.hxx> +#include <com/sun/star/document/XFilter.hpp> -#include "WpftFilterTestBase.hxx" +#include "WpftLoader.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 { @@ -47,126 +22,17 @@ namespace test WpftFilterTestBase::WpftFilterTestBase(const rtl::OUString &rFactoryURL) : ::test::FiltersTest() - , ::test::BootstrapFixture() + , WpftFilterFixture() , 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<document::XTypeDetection> 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<lang::XComponent> xDoc( - m_xDesktop->loadComponentFromURL(m_aFactoryURL, "_blank", 0, uno::Sequence<beans::PropertyValue>()), - uno::UNO_QUERY_THROW); - - // Find the model and frame. We need them later. - uno::Reference<frame::XFrame> xFrame(xDoc, uno::UNO_QUERY); - uno::Reference<frame::XModel> xModel(xDoc, uno::UNO_QUERY); - uno::Reference<frame::XController> 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<document::XImporter> xImporter(m_xFilter, uno::UNO_QUERY_THROW); - - xImporter->setTargetDocument(xDoc); - - uno::Sequence<beans::PropertyValue> aDescriptor(3); - ucbhelper::Content aContent(rURL, uno::Reference<ucb::XCommandEnvironment>(), 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<document::XExtendedFilterDetection> 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<util::XCloseable> xCloseable(xFrame, uno::UNO_QUERY); - if (xCloseable.is()) - xCloseable->close(true); - else - xDoc->dispose(); - } - catch (const uno::Exception &) - { - // ignore - } - - return result; + const WpftLoader aLoader(rURL, m_xFilter, m_aFactoryURL, m_xDesktop, m_xTypeMap, m_xContext); + return aLoader.getDocument().is(); } void WpftFilterTestBase::doTest(const rtl::OUString &rFilter, const rtl::OUString &rPath) @@ -183,35 +49,6 @@ void WpftFilterTestBase::doTest(const rtl::OUString &rFilter, const rtl::OUStrin m_pOptionalMap = nullptr; } -void WpftFilterTestBase::impl_detectFilterName(uno::Sequence<beans::PropertyValue> &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<beans::PropertyValue> 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(); -} - } } diff --git a/writerperfect/qa/unit/WpftFilterTestBase.hxx b/writerperfect/qa/unit/WpftFilterTestBase.hxx index c6eb9c315c77..7042daaadf47 100644 --- a/writerperfect/qa/unit/WpftFilterTestBase.hxx +++ b/writerperfect/qa/unit/WpftFilterTestBase.hxx @@ -10,39 +10,15 @@ #ifndef INCLUDED_WRITERPERFECT_QA_UNIT_WPFTFILTERTESTBASE_HXX #define INCLUDED_WRITERPERFECT_QA_UNIT_WPFTFILTERTESTBASE_HXX -#include "config_writerperfect.h" - #include <unordered_map> #include <com/sun/star/uno/Reference.hxx> -#include <com/sun/star/uno/Sequence.hxx> #include <rtl/ustring.hxx> -#include <test/bootstrapfixture.hxx> - #include <unotest/filters-test.hxx> -#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) +#include "WpftFilterFixture.hxx" namespace com { @@ -50,26 +26,10 @@ namespace sun { namespace star { -namespace beans -{ -struct PropertyValue; -} -namespace container -{ -class XNameAccess; -} namespace document { class XFilter; } -namespace frame -{ -class XDesktop2; -} -namespace ucb -{ -class XSimpleFileAccess; -} } } } @@ -83,14 +43,11 @@ typedef std::unordered_map<rtl::OUString, bool, rtl::OUStringHash> WpftOptionalM class WpftFilterTestBase : public ::test::FiltersTest - , public ::test::BootstrapFixture + , public WpftFilterFixture { 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); @@ -99,13 +56,9 @@ private: virtual bool load(const OUString &, const OUString &rURL, const OUString &, SfxFilterFlags, SotClipboardFormatId, unsigned int) override; - void impl_detectFilterName(css::uno::Sequence<css::beans::PropertyValue> &rDescriptor, const rtl::OUString &rTypeName); - private: const rtl::OUString m_aFactoryURL; - css::uno::Reference<css::frame::XDesktop2> m_xDesktop; css::uno::Reference<css::document::XFilter> m_xFilter; - css::uno::Reference<css::container::XNameAccess> m_xTypeMap; const WpftOptionalMap_t *m_pOptionalMap; }; diff --git a/writerperfect/qa/unit/WpftLoader.cxx b/writerperfect/qa/unit/WpftLoader.cxx new file mode 100644 index 000000000000..5299a27d9cc0 --- /dev/null +++ b/writerperfect/qa/unit/WpftLoader.cxx @@ -0,0 +1,194 @@ +/* -*- 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 "WpftLoader.hxx" + +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/container/NoSuchElementException.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/document/XExtendedFilterDetection.hpp> +#include <com/sun/star/document/XFilter.hpp> +#include <com/sun/star/document/XImporter.hpp> +#include <com/sun/star/document/XTypeDetection.hpp> +#include <com/sun/star/frame/XController.hpp> +#include <com/sun/star/frame/XDesktop2.hpp> +#include <com/sun/star/frame/XFrame.hpp> +#include <com/sun/star/frame/XModel.hpp> +#include <com/sun/star/lang/IllegalArgumentException.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/ucb/XCommandEnvironment.hpp> +#include <com/sun/star/ucb/XContent.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/util/XCloseable.hpp> + +#include <ucbhelper/content.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 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 +{ + +WpftLoader::WpftLoader( + const rtl::OUString &rURL, + const css::uno::Reference<css::document::XFilter> &rxFilter, + const rtl::OUString &rFactoryURL, + const css::uno::Reference<css::frame::XDesktop2> &rxDesktop, + const css::uno::Reference<css::container::XNameAccess> &rxTypeMap, + const css::uno::Reference<css::uno::XComponentContext> &rxContext +) + : m_aURL(rURL) + , m_aFactoryURL(rFactoryURL) + , m_xFilter(rxFilter) + , m_xDesktop(rxDesktop) + , m_xTypeMap(rxTypeMap) + , m_xContext(rxContext) +{ + if (!impl_load()) + impl_dispose(); +} + +WpftLoader::~WpftLoader() +{ + try + { + impl_dispose(); + } + catch (...) + { + } +} + +const css::uno::Reference<css::lang::XComponent> &WpftLoader::getDocument() const +{ + return m_xDoc; +} + +bool WpftLoader::impl_load() +{ + // create an empty frame + m_xDoc.set( + m_xDesktop->loadComponentFromURL(m_aFactoryURL, "_blank", 0, uno::Sequence<beans::PropertyValue>()), + uno::UNO_QUERY_THROW); + + // Find the model and frame. We need them later. + m_xFrame.set(m_xDoc, uno::UNO_QUERY); + uno::Reference<frame::XModel> xModel(m_xDoc, uno::UNO_QUERY); + uno::Reference<frame::XController> xController(m_xDoc, uno::UNO_QUERY); + + if (m_xFrame.is()) + { + xController = m_xFrame->getController(); + xModel = xController->getModel(); + } + else if (xModel.is()) + { + xController = xModel->getCurrentController(); + m_xFrame = xController->getFrame(); + } + else if (xController.is()) + { + m_xFrame = xController->getFrame(); + xModel = xController->getModel(); + } + + if (!m_xFrame.is() || !xModel.is()) + throw uno::RuntimeException(); + + // try to import the document (and load it into the prepared frame) + try + { + const uno::Reference<document::XImporter> xImporter(m_xFilter, uno::UNO_QUERY_THROW); + + xImporter->setTargetDocument(m_xDoc); + + uno::Sequence<beans::PropertyValue> aDescriptor(3); + ucbhelper::Content aContent(m_aURL, uno::Reference<ucb::XCommandEnvironment>(), m_xContext); + + aDescriptor[0].Name = "URL"; + aDescriptor[0].Value <<= m_aURL; + aDescriptor[1].Name = "InputStream"; + aDescriptor[1].Value <<= aContent.openStream(); + aDescriptor[2].Name = "UCBContent"; + aDescriptor[2].Value <<= aContent.get(); + + const uno::Reference<document::XExtendedFilterDetection> 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(); + const bool bLoaded = m_xFilter->filter(aDescriptor); + xModel->unlockControllers(); + return bLoaded; + } + catch (const uno::Exception &) + { + // ignore + } + + return false; +} + +void WpftLoader::impl_dispose() +{ + // close the opened document + uno::Reference<util::XCloseable> xCloseable(m_xFrame, uno::UNO_QUERY); + if (xCloseable.is()) + xCloseable->close(true); + else if (m_xDoc.is()) + m_xDoc->dispose(); + m_xDoc.clear(); + m_xFrame.clear(); +} + +void WpftLoader::impl_detectFilterName(uno::Sequence<beans::PropertyValue> &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<beans::PropertyValue> 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/WpftLoader.hxx b/writerperfect/qa/unit/WpftLoader.hxx new file mode 100644 index 000000000000..a854a531d5db --- /dev/null +++ b/writerperfect/qa/unit/WpftLoader.hxx @@ -0,0 +1,97 @@ +/* -*- 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_WPFTLOADER_HXX +#define INCLUDED_WRITERPERFECT_QA_UNIT_WPFTLOADER_HXX + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> + +#include <rtl/ustring.hxx> + +namespace com +{ +namespace sun +{ +namespace star +{ +namespace beans +{ +struct PropertyValue; +} +namespace container +{ +class XNameAccess; +} +namespace document +{ +class XFilter; +} +namespace frame +{ +class XDesktop2; +class XFrame; +} +namespace lang +{ +class XComponent; +} +namespace uno +{ +class XComponentContext; +} +} +} +} + +namespace writerperfect +{ +namespace test +{ + +class WpftLoader +{ +public: + WpftLoader( + const rtl::OUString &rURL, + const css::uno::Reference<css::document::XFilter> &rxFilter, + const rtl::OUString &rFactoryURL, + const css::uno::Reference<css::frame::XDesktop2> &rxDesktop, + const css::uno::Reference<css::container::XNameAccess> &rxTypeMap, + const css::uno::Reference<css::uno::XComponentContext> &rxContext + ); + WpftLoader(const WpftLoader &) = delete; + WpftLoader &operator=(const WpftLoader &) = delete; + ~WpftLoader(); + + const css::uno::Reference<css::lang::XComponent> &getDocument() const; + +private: + bool impl_load(); + void impl_dispose(); + + void impl_detectFilterName(css::uno::Sequence<css::beans::PropertyValue> &rDescriptor, const rtl::OUString &rTypeName); + +private: + const rtl::OUString m_aURL; + const rtl::OUString m_aFactoryURL; + const css::uno::Reference<css::document::XFilter> m_xFilter; + const css::uno::Reference<css::frame::XDesktop2> m_xDesktop; + const css::uno::Reference<css::container::XNameAccess> m_xTypeMap; + const css::uno::Reference<css::uno::XComponentContext> m_xContext; + css::uno::Reference<css::lang::XComponent> m_xDoc; + css::uno::Reference<css::frame::XFrame> m_xFrame; +}; + +} +} + +#endif // INCLUDED_WRITERPERFECT_QA_UNIT_WPFTLOADER_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |