diff options
author | David Tardon <dtardon@redhat.com> | 2014-03-30 16:16:46 +0200 |
---|---|---|
committer | David Tardon <dtardon@redhat.com> | 2014-03-30 19:06:28 +0200 |
commit | 4af1bcf0bda75a0b9e8db8a2080e65d8f134b34a (patch) | |
tree | 5378ef237ef170624742a22ed265945c7d253463 /writerperfect | |
parent | 7485d76164589652359f7da840b01c0f64bbe7c6 (diff) |
reduce the amount of copypasta
Change-Id: I19b75b29da91ba1057f7da786da18fb246d97598
Diffstat (limited to 'writerperfect')
-rw-r--r-- | writerperfect/CppunitTest_writerperfect_draw.mk | 4 | ||||
-rw-r--r-- | writerperfect/CppunitTest_writerperfect_impress.mk | 4 | ||||
-rw-r--r-- | writerperfect/CppunitTest_writerperfect_writer.mk | 4 | ||||
-rw-r--r-- | writerperfect/Module_writerperfect.mk | 1 | ||||
-rw-r--r-- | writerperfect/StaticLibrary_writerperfect_importtestbase.mk | 35 | ||||
-rw-r--r-- | writerperfect/qa/unit/WpftImportTestBase.cxx | 151 | ||||
-rw-r--r-- | writerperfect/qa/unit/WpftImportTestBase.hxx | 67 | ||||
-rw-r--r-- | writerperfect/qa/unit/wpftdraw.cxx | 96 | ||||
-rw-r--r-- | writerperfect/qa/unit/wpftimpress.cxx | 96 | ||||
-rw-r--r-- | writerperfect/qa/unit/wpftwriter.cxx | 146 |
10 files changed, 281 insertions, 323 deletions
diff --git a/writerperfect/CppunitTest_writerperfect_draw.mk b/writerperfect/CppunitTest_writerperfect_draw.mk index d724a5839577..70edb12ba5c2 100644 --- a/writerperfect/CppunitTest_writerperfect_draw.mk +++ b/writerperfect/CppunitTest_writerperfect_draw.mk @@ -29,6 +29,10 @@ $(eval $(call gb_CppunitTest_use_libraries,writerperfect_draw,\ $(gb_UWINAPI) \ )) +$(eval $(call gb_CppunitTest_use_static_libraries,writerperfect_draw,\ + writerperfect_importtestbase \ +)) + $(eval $(call gb_CppunitTest_use_ure,writerperfect_draw)) $(eval $(call gb_CppunitTest_use_rdb,writerperfect_draw,services)) diff --git a/writerperfect/CppunitTest_writerperfect_impress.mk b/writerperfect/CppunitTest_writerperfect_impress.mk index 250535379221..57f9ceeeb84a 100644 --- a/writerperfect/CppunitTest_writerperfect_impress.mk +++ b/writerperfect/CppunitTest_writerperfect_impress.mk @@ -29,6 +29,10 @@ $(eval $(call gb_CppunitTest_use_libraries,writerperfect_impress,\ $(gb_UWINAPI) \ )) +$(eval $(call gb_CppunitTest_use_static_libraries,writerperfect_impress,\ + writerperfect_importtestbase \ +)) + $(eval $(call gb_CppunitTest_use_ure,writerperfect_impress)) $(eval $(call gb_CppunitTest_use_rdb,writerperfect_impress,services)) diff --git a/writerperfect/CppunitTest_writerperfect_writer.mk b/writerperfect/CppunitTest_writerperfect_writer.mk index 143b41c46567..b3bdaf57c251 100644 --- a/writerperfect/CppunitTest_writerperfect_writer.mk +++ b/writerperfect/CppunitTest_writerperfect_writer.mk @@ -29,6 +29,10 @@ $(eval $(call gb_CppunitTest_use_libraries,writerperfect_writer,\ $(gb_UWINAPI) \ )) +$(eval $(call gb_CppunitTest_use_static_libraries,writerperfect_writer,\ + writerperfect_importtestbase \ +)) + $(eval $(call gb_CppunitTest_use_ure,writerperfect_writer)) $(eval $(call gb_CppunitTest_use_rdb,writerperfect_writer,services)) diff --git a/writerperfect/Module_writerperfect.mk b/writerperfect/Module_writerperfect.mk index 2995e8c2aa3a..423329d098b7 100644 --- a/writerperfect/Module_writerperfect.mk +++ b/writerperfect/Module_writerperfect.mk @@ -34,6 +34,7 @@ $(eval $(call gb_Module_add_slowcheck_targets,writerperfect,\ CppunitTest_writerperfect_draw \ CppunitTest_writerperfect_impress \ CppunitTest_writerperfect_writer \ + StaticLibrary_writerperfect_importtestbase \ )) # vim: set noet sw=4 ts=4: diff --git a/writerperfect/StaticLibrary_writerperfect_importtestbase.mk b/writerperfect/StaticLibrary_writerperfect_importtestbase.mk new file mode 100644 index 000000000000..172ca40c5dec --- /dev/null +++ b/writerperfect/StaticLibrary_writerperfect_importtestbase.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_importtestbase)) + +$(eval $(call gb_StaticLibrary_set_include,writerperfect_importtestbase,\ + -I$(SRCDIR)/writerperfect/qa/unit \ + $$(INCLUDE) \ +)) + +$(eval $(call gb_StatiLibrary_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/WpftImportTestBase.cxx b/writerperfect/qa/unit/WpftImportTestBase.cxx new file mode 100644 index 000000000000..53e41ab7d5e2 --- /dev/null +++ b/writerperfect/qa/unit/WpftImportTestBase.cxx @@ -0,0 +1,151 @@ +/* -*- 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 <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/io/XInputStream.hpp> +#include <com/sun/star/lang/IllegalArgumentException.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/ucb/SimpleFileAccess.hpp> + +#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 writerperfect +{ +namespace test +{ + +WpftImportTestBase::WpftImportTestBase(const rtl::OUString &rFactoryURL) + : ::test::FiltersTest() + , ::test::BootstrapFixture() + , m_aFactoryURL(rFactoryURL) + , m_xDesktop() + , m_xFileAccess() + , m_xFilter() + , m_xTypeMap() +{ +} + +void WpftImportTestBase::setUp() +{ + ::test::BootstrapFixture::setUp(); + + m_xDesktop = frame::theDesktop::get(m_xContext); + m_xFileAccess = ucb::SimpleFileAccess::create(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 WpftImportTestBase::tearDown() +{ + m_xDesktop->terminate(); + + ::test::BootstrapFixture::tearDown(); +} + +bool WpftImportTestBase::load(const OUString &, const OUString &rURL, const OUString &, + unsigned int, unsigned int, unsigned int) +{ + const uno::Reference<lang::XComponent> xDoc( + m_xDesktop->loadComponentFromURL(m_aFactoryURL, "_blank", 0, uno::Sequence<beans::PropertyValue>()), + uno::UNO_QUERY_THROW); + + bool result = false; + + try + { + const uno::Reference<document::XImporter> xImporter(m_xFilter, uno::UNO_QUERY_THROW); + + xImporter->setTargetDocument(xDoc); + + uno::Sequence<beans::PropertyValue> aDescriptor(2); + aDescriptor[0].Name = "URL"; + aDescriptor[0].Value <<= rURL; + + const uno::Reference<io::XInputStream> xInputStream(m_xFileAccess->openFileRead(rURL), uno::UNO_QUERY_THROW); + aDescriptor[1].Name = "InputStream"; + aDescriptor[1].Value <<= xInputStream; + + 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); + + result = m_xFilter->filter(aDescriptor); + } + catch (const uno::Exception &) + { + // ignore + } + + xDoc->dispose(); + + 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(), getURLFromSrc(rPath), OUString()); +} + +void WpftImportTestBase::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/WpftImportTestBase.hxx b/writerperfect/qa/unit/WpftImportTestBase.hxx new file mode 100644 index 000000000000..2024e8f483cb --- /dev/null +++ b/writerperfect/qa/unit/WpftImportTestBase.hxx @@ -0,0 +1,67 @@ +/* -*- 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 <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> + +namespace com { namespace sun { namespace star { + namespace beans { class PropertyValue; } + namespace container { class XNameAccess; } + namespace document { class XFilter; } + namespace frame { class XDesktop2; } + namespace ucb { class XSimpleFileAccess; } +} } } + +namespace writerperfect +{ +namespace test +{ + +class WpftImportTestBase + : public ::test::FiltersTest + , public ::test::BootstrapFixture +{ +public: + explicit WpftImportTestBase(const rtl::OUString &rFactoryURL); + + virtual void setUp() SAL_OVERRIDE; + virtual void tearDown() SAL_OVERRIDE; + +protected: + void doTest(const rtl::OUString &rFilter, const rtl::OUString &rPath); + +private: + virtual bool load(const OUString &, const OUString &rURL, const OUString &, + unsigned int, unsigned int, unsigned int) SAL_OVERRIDE; + + void impl_detectFilterName(com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue> &rDescriptor, const rtl::OUString &rTypeName); + +private: + const rtl::OUString m_aFactoryURL; + com::sun::star::uno::Reference<com::sun::star::frame::XDesktop2> m_xDesktop; + com::sun::star::uno::Reference<com::sun::star::ucb::XSimpleFileAccess> m_xFileAccess; + com::sun::star::uno::Reference<com::sun::star::document::XFilter> m_xFilter; + com::sun::star::uno::Reference<com::sun::star::container::XNameAccess> m_xTypeMap; +}; + +} +} + +#endif // INCLUDED_WRITERPERFECT_QA_UNIT_WPFTIMPORTTESTBASE_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/qa/unit/wpftdraw.cxx b/writerperfect/qa/unit/wpftdraw.cxx index b1711b6bb071..5118ff756462 100644 --- a/writerperfect/qa/unit/wpftdraw.cxx +++ b/writerperfect/qa/unit/wpftdraw.cxx @@ -7,70 +7,26 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include <com/sun/star/beans/PropertyValue.hpp> -#include <com/sun/star/document/XFilter.hpp> -#include <com/sun/star/document/XImporter.hpp> -#include <com/sun/star/frame/theDesktop.hpp> -#include <com/sun/star/io/XInputStream.hpp> -#include <com/sun/star/lang/XComponent.hpp> -#include <com/sun/star/ucb/SimpleFileAccess.hpp> -#include <com/sun/star/uno/Reference.hxx> -#include <com/sun/star/uno/Sequence.hxx> - -#include <test/bootstrapfixture.hxx> - -#include <unotest/filters-test.hxx> - -namespace beans = com::sun::star::beans; -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; +#include "WpftImportTestBase.hxx" namespace { -class WpftDrawFilterTest - : public test::FiltersTest - , public test::BootstrapFixture +class WpftDrawFilterTest : public writerperfect::test::WpftImportTestBase { public: - virtual void setUp(); - virtual void tearDown(); + WpftDrawFilterTest(); void test(); CPPUNIT_TEST_SUITE(WpftDrawFilterTest); CPPUNIT_TEST(test); CPPUNIT_TEST_SUITE_END(); - -private: - virtual bool load(const OUString &, const OUString &rURL, const OUString &, - unsigned int, unsigned int, unsigned int); - - void doTest(const rtl::OUString &rFilter, const rtl::OUString &rPath); - -private: - uno::Reference<frame::XDesktop2> m_xDesktop; - uno::Reference<ucb::XSimpleFileAccess> m_xFileAccess; - uno::Reference<document::XFilter> m_xFilter; }; -void WpftDrawFilterTest::setUp() +WpftDrawFilterTest::WpftDrawFilterTest() + : writerperfect::test::WpftImportTestBase("private:factory/sdraw") { - test::BootstrapFixture::setUp(); - - m_xDesktop = frame::theDesktop::get(m_xContext); - m_xFileAccess = ucb::SimpleFileAccess::create(m_xContext); -} - -void WpftDrawFilterTest::tearDown() -{ - test::BootstrapFixture::tearDown(); - - m_xDesktop->terminate(); } void WpftDrawFilterTest::test() @@ -83,48 +39,6 @@ void WpftDrawFilterTest::test() doTest("com.sun.star.comp.Draw.WPGImportFilter", "/writerperfect/qa/unit/data/libwpg/"); } -bool WpftDrawFilterTest::load(const OUString &, const OUString &rURL, const OUString &, - unsigned int, unsigned int, unsigned int) -{ - const uno::Reference<lang::XComponent> xDoc( - m_xDesktop->loadComponentFromURL("private:factory/simpress", "_blank", 0, uno::Sequence<beans::PropertyValue>()), - uno::UNO_QUERY_THROW); - - bool result = false; - - try - { - const uno::Reference<document::XImporter> xImporter(m_xFilter, uno::UNO_QUERY_THROW); - - xImporter->setTargetDocument(xDoc); - - uno::Sequence<beans::PropertyValue> aDescriptor(2); - aDescriptor[0].Name = "URL"; - aDescriptor[0].Value <<= rURL; - - const uno::Reference<io::XInputStream> xInputStream(m_xFileAccess->openFileRead(rURL), uno::UNO_QUERY_THROW); - aDescriptor[1].Name = "InputStream"; - aDescriptor[1].Value <<= xInputStream; - - result = m_xFilter->filter(aDescriptor); - } - catch (const uno::Exception &) - { - xDoc->dispose(); - throw; - } - - xDoc->dispose(); - - return result; -} - -void WpftDrawFilterTest::doTest(const rtl::OUString &rFilter, const rtl::OUString &rPath) -{ - m_xFilter.set(m_xFactory->createInstanceWithContext(rFilter, m_xContext), uno::UNO_QUERY_THROW); - testDir(OUString(), getURLFromSrc(rPath), OUString()); -} - CPPUNIT_TEST_SUITE_REGISTRATION(WpftDrawFilterTest); } diff --git a/writerperfect/qa/unit/wpftimpress.cxx b/writerperfect/qa/unit/wpftimpress.cxx index 376b3a5e0715..2f349fa8134b 100644 --- a/writerperfect/qa/unit/wpftimpress.cxx +++ b/writerperfect/qa/unit/wpftimpress.cxx @@ -7,70 +7,26 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include <com/sun/star/beans/PropertyValue.hpp> -#include <com/sun/star/document/XFilter.hpp> -#include <com/sun/star/document/XImporter.hpp> -#include <com/sun/star/frame/theDesktop.hpp> -#include <com/sun/star/io/XInputStream.hpp> -#include <com/sun/star/lang/XComponent.hpp> -#include <com/sun/star/ucb/SimpleFileAccess.hpp> -#include <com/sun/star/uno/Reference.hxx> -#include <com/sun/star/uno/Sequence.hxx> - -#include <test/bootstrapfixture.hxx> - -#include <unotest/filters-test.hxx> - -namespace beans = com::sun::star::beans; -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; +#include "WpftImportTestBase.hxx" namespace { -class WpftImpressFilterTest - : public test::FiltersTest - , public test::BootstrapFixture +class WpftImpressFilterTest : public writerperfect::test::WpftImportTestBase { public: - virtual void setUp() SAL_OVERRIDE; - virtual void tearDown() SAL_OVERRIDE; + WpftImpressFilterTest(); void test(); CPPUNIT_TEST_SUITE(WpftImpressFilterTest); CPPUNIT_TEST(test); CPPUNIT_TEST_SUITE_END(); - -private: - virtual bool load(const OUString &, const OUString &rURL, const OUString &, - unsigned int, unsigned int, unsigned int) SAL_OVERRIDE; - - void doTest(const rtl::OUString &rFilter, const rtl::OUString &rPath); - -private: - uno::Reference<frame::XDesktop2> m_xDesktop; - uno::Reference<ucb::XSimpleFileAccess> m_xFileAccess; - uno::Reference<document::XFilter> m_xFilter; }; -void WpftImpressFilterTest::setUp() +WpftImpressFilterTest::WpftImpressFilterTest() + : writerperfect::test::WpftImportTestBase("private:factory/simpress") { - test::BootstrapFixture::setUp(); - - m_xDesktop = frame::theDesktop::get(m_xContext); - m_xFileAccess = ucb::SimpleFileAccess::create(m_xContext); -} - -void WpftImpressFilterTest::tearDown() -{ - test::BootstrapFixture::tearDown(); - - m_xDesktop->terminate(); } void WpftImpressFilterTest::test() @@ -78,48 +34,6 @@ void WpftImpressFilterTest::test() doTest("org.libreoffice.comp.Impress.KeynoteImportFilter", "/writerperfect/qa/unit/data/libetonyek/"); } -bool WpftImpressFilterTest::load(const OUString &, const OUString &rURL, const OUString &, - unsigned int, unsigned int, unsigned int) -{ - const uno::Reference<lang::XComponent> xDoc( - m_xDesktop->loadComponentFromURL("private:factory/simpress", "_blank", 0, uno::Sequence<beans::PropertyValue>()), - uno::UNO_QUERY_THROW); - - bool result = false; - - try - { - const uno::Reference<document::XImporter> xImporter(m_xFilter, uno::UNO_QUERY_THROW); - - xImporter->setTargetDocument(xDoc); - - uno::Sequence<beans::PropertyValue> aDescriptor(2); - aDescriptor[0].Name = "URL"; - aDescriptor[0].Value <<= rURL; - - const uno::Reference<io::XInputStream> xInputStream(m_xFileAccess->openFileRead(rURL), uno::UNO_QUERY_THROW); - aDescriptor[1].Name = "InputStream"; - aDescriptor[1].Value <<= xInputStream; - - result = m_xFilter->filter(aDescriptor); - } - catch (const uno::Exception &) - { - xDoc->dispose(); - throw; - } - - xDoc->dispose(); - - return result; -} - -void WpftImpressFilterTest::doTest(const rtl::OUString &rFilter, const rtl::OUString &rPath) -{ - m_xFilter.set(m_xFactory->createInstanceWithContext(rFilter, m_xContext), uno::UNO_QUERY_THROW); - testDir(OUString(), getURLFromSrc(rPath), OUString()); -} - CPPUNIT_TEST_SUITE_REGISTRATION(WpftImpressFilterTest); } diff --git a/writerperfect/qa/unit/wpftwriter.cxx b/writerperfect/qa/unit/wpftwriter.cxx index e700dab16b33..284c5f5578a1 100644 --- a/writerperfect/qa/unit/wpftwriter.cxx +++ b/writerperfect/qa/unit/wpftwriter.cxx @@ -7,84 +7,26 @@ * 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/io/XInputStream.hpp> -#include <com/sun/star/lang/IllegalArgumentException.hpp> -#include <com/sun/star/lang/XComponent.hpp> -#include <com/sun/star/ucb/SimpleFileAccess.hpp> -#include <com/sun/star/uno/Reference.hxx> -#include <com/sun/star/uno/Sequence.hxx> - -#include <test/bootstrapfixture.hxx> - -#include <unotest/filters-test.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; +#include "WpftImportTestBase.hxx" namespace { -class WpftWriterFilterTest - : public test::FiltersTest - , public test::BootstrapFixture +class WpftWriterFilterTest : public writerperfect::test::WpftImportTestBase { public: - virtual void setUp(); - virtual void tearDown(); + WpftWriterFilterTest(); void test(); CPPUNIT_TEST_SUITE(WpftWriterFilterTest); CPPUNIT_TEST(test); CPPUNIT_TEST_SUITE_END(); - -private: - virtual bool load(const OUString &, const OUString &rURL, const OUString &, - unsigned int, unsigned int, unsigned int); - - void doTest(const rtl::OUString &rFilter, const rtl::OUString &rPath); - - void impl_detectFilterName(uno::Sequence<beans::PropertyValue> &rDescriptor, const rtl::OUString &rTypeName); - -private: - uno::Reference<frame::XDesktop2> m_xDesktop; - uno::Reference<ucb::XSimpleFileAccess> m_xFileAccess; - uno::Reference<document::XFilter> m_xFilter; - uno::Reference<container::XNameAccess> m_xTypeMap; }; -void WpftWriterFilterTest::setUp() -{ - test::BootstrapFixture::setUp(); - - m_xDesktop = frame::theDesktop::get(m_xContext); - m_xFileAccess = ucb::SimpleFileAccess::create(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 WpftWriterFilterTest::tearDown() +WpftWriterFilterTest::WpftWriterFilterTest() + : writerperfect::test::WpftImportTestBase("private:factory/swriter") { - test::BootstrapFixture::tearDown(); - - m_xDesktop->terminate(); } void WpftWriterFilterTest::test() @@ -96,84 +38,6 @@ void WpftWriterFilterTest::test() doTest("com.sun.star.comp.Writer.WordPerfectImportFilter", "/writerperfect/qa/unit/data/libwpd/"); } -bool WpftWriterFilterTest::load(const OUString &, const OUString &rURL, const OUString &, - unsigned int, unsigned int, unsigned int) -{ - const uno::Reference<lang::XComponent> xDoc( - m_xDesktop->loadComponentFromURL("private:factory/swriter", "_blank", 0, uno::Sequence<beans::PropertyValue>()), - uno::UNO_QUERY_THROW); - - bool result = false; - - try - { - const uno::Reference<document::XImporter> xImporter(m_xFilter, uno::UNO_QUERY_THROW); - - xImporter->setTargetDocument(xDoc); - - uno::Sequence<beans::PropertyValue> aDescriptor(2); - aDescriptor[0].Name = "URL"; - aDescriptor[0].Value <<= rURL; - - const uno::Reference<io::XInputStream> xInputStream(m_xFileAccess->openFileRead(rURL), uno::UNO_QUERY_THROW); - aDescriptor[1].Name = "InputStream"; - aDescriptor[1].Value <<= xInputStream; - - 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); - - result = m_xFilter->filter(aDescriptor); - } - catch (const uno::Exception &) - { - // ignore - } - - xDoc->dispose(); - - return result; -} - -void WpftWriterFilterTest::doTest(const rtl::OUString &rFilter, const rtl::OUString &rPath) -{ - m_xFilter.set(m_xFactory->createInstanceWithContext(rFilter, m_xContext), uno::UNO_QUERY_THROW); - testDir(OUString(), getURLFromSrc(rPath), OUString()); -} - -void WpftWriterFilterTest::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(); -} - CPPUNIT_TEST_SUITE_REGISTRATION(WpftWriterFilterTest); } |