writerperfect/CppunitTest_writerperfect_import.mk | 40 ++++++ writerperfect/Module_writerperfect.mk | 1 writerperfect/inc/DirectoryStream.hxx | 3 writerperfect/qa/unit/DirectoryStreamTest.cxx | 38 ------ writerperfect/qa/unit/ImportTest.cxx | 118 +++++++++++++++++++ writerperfect/qa/unit/WpftFilterFixture.cxx | 4 writerperfect/qa/unit/WpftFilterFixture.hxx | 5 writerperfect/qa/unit/WpftLoader.hxx | 2 writerperfect/qa/unit/data/import/SOLVE.FM3 |binary writerperfect/qa/unit/data/import/SOLVE.WK3 |binary writerperfect/source/common/DirectoryStream.cxx | 38 ++++++ writerperfect/source/impress/KeynoteImportFilter.cxx | 32 ++--- 12 files changed, 224 insertions(+), 57 deletions(-)
New commits: commit a48c22e1bfc2019a6c2a35caaa09d2319b783078 Author: David Tardon <[email protected]> Date: Thu Jan 12 21:03:21 2017 +0100 add test for handling .wk3 format file Change-Id: Id6fd1f979902e286009d16f9d8ea551df3940859 diff --git a/writerperfect/CppunitTest_writerperfect_import.mk b/writerperfect/CppunitTest_writerperfect_import.mk new file mode 100644 index 0000000..152d26f --- /dev/null +++ b/writerperfect/CppunitTest_writerperfect_import.mk @@ -0,0 +1,40 @@ +# -*- 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,writerperfect_import)) + +$(eval $(call gb_CppunitTest_add_defs,writerperfect_import,\ + -DTEST_DIR=\"writerperfect/qa/unit/data/import\" \ +)) + +$(eval $(call gb_CppunitTest_use_sdk_api,writerperfect_import)) + +$(eval $(call gb_CppunitTest_use_libraries,writerperfect_import,\ + comphelper \ + cppu \ + sal \ + test \ + unotest \ + utl \ + wpftqahelper \ + $(gb_UWINAPI) \ +)) + +$(eval $(call gb_CppunitTest_use_ure,writerperfect_import)) +$(eval $(call gb_CppunitTest_use_vcl,writerperfect_import)) + +$(eval $(call gb_CppunitTest_use_rdb,writerperfect_import,services)) + +$(eval $(call gb_CppunitTest_use_configuration,writerperfect_import)) + +$(eval $(call gb_CppunitTest_add_exception_objects,writerperfect_import,\ + writerperfect/qa/unit/ImportTest \ +)) + +# vim: set noet sw=4 ts=4: diff --git a/writerperfect/Module_writerperfect.mk b/writerperfect/Module_writerperfect.mk index eda54bb6..3c6168e 100644 --- a/writerperfect/Module_writerperfect.mk +++ b/writerperfect/Module_writerperfect.mk @@ -39,6 +39,7 @@ $(eval $(call gb_Module_add_check_targets,writerperfect,\ $(eval $(call gb_Module_add_slowcheck_targets,writerperfect,\ CppunitTest_writerperfect_calc \ CppunitTest_writerperfect_draw \ + CppunitTest_writerperfect_import \ CppunitTest_writerperfect_impress \ CppunitTest_writerperfect_writer \ Library_wpftqahelper \ diff --git a/writerperfect/qa/unit/ImportTest.cxx b/writerperfect/qa/unit/ImportTest.cxx new file mode 100644 index 0000000..9275c6c --- /dev/null +++ b/writerperfect/qa/unit/ImportTest.cxx @@ -0,0 +1,118 @@ +/* -*- 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/beans/XPropertySet.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/document/XFilter.hpp> +#include <com/sun/star/document/XTypeDetection.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/table/XCellRange.hpp> + +#include <unotools/mediadescriptor.hxx> + +#include "WpftFilterFixture.hxx" +#include "WpftLoader.hxx" + +namespace +{ + +namespace beans = css::beans; +namespace container = css::container; +namespace document = css::document; +namespace lang = css::lang; +namespace sheet = css::sheet; +namespace table = css::table; +namespace uno = css::uno; + +using uno::UNO_QUERY; + +using writerperfect::test::WpftLoader; + +class ImportTest : public writerperfect::test::WpftFilterFixture +{ +public: + virtual void setUp() override; + + void testWK3WithFM3(); + + CPPUNIT_TEST_SUITE(ImportTest); + CPPUNIT_TEST(testWK3WithFM3); + CPPUNIT_TEST_SUITE_END(); + +private: + WpftLoader createCalcLoader(const rtl::OUString &rFile) const; + + WpftLoader createLoader(const rtl::OUString &rUrl, const rtl::OUString &rFactoryUrl) const; + + rtl::OUString makeUrl(const rtl::OUString &rFile) const; + +private: + uno::Reference<lang::XMultiServiceFactory> m_xFilterFactory; +}; + +void ImportTest::setUp() +{ + writerperfect::test::WpftFilterFixture::setUp(); + + m_xFilterFactory.set( + m_xFactory->createInstanceWithContext("com.sun.star.document.FilterFactory", m_xContext), + UNO_QUERY); + assert(m_xFilterFactory.is()); +} + +void ImportTest::testWK3WithFM3() +{ + WpftLoader aLoader(createCalcLoader("SOLVE.WK3")); + uno::Reference<sheet::XSpreadsheetDocument> xDoc(aLoader.getDocument(), UNO_QUERY); + CPPUNIT_ASSERT(xDoc.is()); + uno::Reference<container::XIndexAccess> xSheets(xDoc->getSheets(), UNO_QUERY); + CPPUNIT_ASSERT(xSheets.is()); + uno::Reference<table::XCellRange> xSheet(xSheets->getByIndex(0), UNO_QUERY); + CPPUNIT_ASSERT(xSheet.is()); + uno::Reference<beans::XPropertySet> xCellProps(xSheet->getCellByPosition(1, 1), UNO_QUERY); + CPPUNIT_ASSERT(xCellProps.is()); + sal_Int32 nCharColor = 0; + CPPUNIT_ASSERT(xCellProps->getPropertyValue("CharColor") >>= nCharColor); +#if 0 // broken by commit 8154953add163554c00935486a1cf5677cef2609 + CPPUNIT_ASSERT_EQUAL(sal_Int32(0x0000ff), nCharColor); // blue text +#endif +} + +WpftLoader ImportTest::createCalcLoader(const rtl::OUString &rFile) const +{ + return createLoader(makeUrl(rFile), "private:factory/scalc"); +} + +WpftLoader ImportTest::createLoader(const rtl::OUString &rUrl, const rtl::OUString &rFactoryUrl) const +{ + utl::MediaDescriptor aDesc; + aDesc[utl::MediaDescriptor::PROP_URL()] <<= rUrl; + aDesc[utl::MediaDescriptor::PROP_READONLY()] <<= true; + uno::Sequence<beans::PropertyValue> lDesc(aDesc.getAsConstPropertyValueList()); + const rtl::OUString sType = m_xTypeDetection->queryTypeByDescriptor(lDesc, true); + CPPUNIT_ASSERT(!sType.isEmpty()); + const uno::Reference<document::XFilter> xFilter(m_xFilterFactory->createInstance(sType), UNO_QUERY); + CPPUNIT_ASSERT(xFilter.is()); + return WpftLoader(rUrl, xFilter, rFactoryUrl, m_xDesktop, m_xTypeMap, m_xContext); +} + +rtl::OUString ImportTest::makeUrl(const rtl::OUString &rFile) const +{ + return const_cast<ImportTest *>(this)->m_directories.getURLFromSrc("/" TEST_DIR "/" + rFile); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ImportTest); + +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/qa/unit/WpftFilterFixture.cxx b/writerperfect/qa/unit/WpftFilterFixture.cxx index 6ceb579..106b28e 100644 --- a/writerperfect/qa/unit/WpftFilterFixture.cxx +++ b/writerperfect/qa/unit/WpftFilterFixture.cxx @@ -28,10 +28,10 @@ void WpftFilterFixture::setUp() m_xDesktop = frame::theDesktop::get(m_xContext); - const uno::Reference<document::XTypeDetection> xTypeDetection( + m_xTypeDetection.set( m_xFactory->createInstanceWithContext("com.sun.star.document.TypeDetection", m_xContext), uno::UNO_QUERY_THROW); - m_xTypeMap.set(xTypeDetection, uno::UNO_QUERY_THROW); + m_xTypeMap.set(m_xTypeDetection, uno::UNO_QUERY_THROW); } void WpftFilterFixture::tearDown() diff --git a/writerperfect/qa/unit/WpftFilterFixture.hxx b/writerperfect/qa/unit/WpftFilterFixture.hxx index fe8acc2..fde79c2 100644 --- a/writerperfect/qa/unit/WpftFilterFixture.hxx +++ b/writerperfect/qa/unit/WpftFilterFixture.hxx @@ -52,6 +52,10 @@ namespace container { class XNameAccess; } +namespace document +{ +class XTypeDetection; +} namespace frame { class XDesktop2; @@ -73,6 +77,7 @@ public: protected: css::uno::Reference<css::frame::XDesktop2> m_xDesktop; + css::uno::Reference<css::document::XTypeDetection> m_xTypeDetection; css::uno::Reference<css::container::XNameAccess> m_xTypeMap; }; diff --git a/writerperfect/qa/unit/WpftLoader.hxx b/writerperfect/qa/unit/WpftLoader.hxx index 97f2987..92a1ff0 100644 --- a/writerperfect/qa/unit/WpftLoader.hxx +++ b/writerperfect/qa/unit/WpftLoader.hxx @@ -68,8 +68,6 @@ public: 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; diff --git a/writerperfect/qa/unit/data/import/SOLVE.FM3 b/writerperfect/qa/unit/data/import/SOLVE.FM3 new file mode 100644 index 0000000..8e4a2ed2 Binary files /dev/null and b/writerperfect/qa/unit/data/import/SOLVE.FM3 differ diff --git a/writerperfect/qa/unit/data/import/SOLVE.WK3 b/writerperfect/qa/unit/data/import/SOLVE.WK3 new file mode 100644 index 0000000..7b3d74c Binary files /dev/null and b/writerperfect/qa/unit/data/import/SOLVE.WK3 differ commit 69c03000038e96d120f57b8259763e27907b8470 Author: David Tardon <[email protected]> Date: Tue Jan 17 19:13:28 2017 +0100 eliminate some code duplicity Change-Id: I7792ddd691f81744971d45e1155e3192b24155dc diff --git a/writerperfect/inc/DirectoryStream.hxx b/writerperfect/inc/DirectoryStream.hxx index dce2a63..36b818d 100644 --- a/writerperfect/inc/DirectoryStream.hxx +++ b/writerperfect/inc/DirectoryStream.hxx @@ -41,6 +41,9 @@ public: virtual ~DirectoryStream() override; static bool isDirectory(const css::uno::Reference<css::ucb::XContent> &xContent); + static std::unique_ptr<DirectoryStream> createForParent(const css::uno::Reference<css::ucb::XContent> &xContent); + + const css::uno::Reference<css::ucb::XContent> getContent() const; virtual bool isStructured() override; virtual unsigned subStreamCount() override; diff --git a/writerperfect/qa/unit/DirectoryStreamTest.cxx b/writerperfect/qa/unit/DirectoryStreamTest.cxx index 0b347ac..730ce41 100644 --- a/writerperfect/qa/unit/DirectoryStreamTest.cxx +++ b/writerperfect/qa/unit/DirectoryStreamTest.cxx @@ -20,7 +20,6 @@ #include <test/bootstrapfixture.hxx> #include <DirectoryStream.hxx> -#include <com/sun/star/container/XChild.hpp> #include <com/sun/star/ucb/XContent.hpp> namespace ucb = com::sun::star::ucb; @@ -64,35 +63,6 @@ static const char g_aDirPath[] = "/writerperfect/qa/unit/data/stream/test.dir"; static const char g_aNondirPath[] = "/writerperfect/qa/unit/data/stream/test.dir/mimetype"; static const char g_aNonexistentPath[] = "/writerperfect/qa/unit/data/stream/foo/bar"; -std::unique_ptr<DirectoryStream> createForParent(const css::uno::Reference<css::ucb::XContent> &xContent) -{ - try - { - if (!xContent.is()) - return nullptr; - - unique_ptr<DirectoryStream> pDir; - - const uno::Reference<css::container::XChild> xChild(xContent, uno::UNO_QUERY); - if (xChild.is()) - { - const uno::Reference<ucb::XContent> xDirContent(xChild->getParent(), uno::UNO_QUERY); - if (xDirContent.is()) - { - pDir = o3tl::make_unique<DirectoryStream>(xDirContent); - if (!pDir->isStructured()) - pDir.reset(); - } - } - - return pDir; - } - catch (...) - { - return nullptr; - } -} - DirectoryStreamTest::DirectoryStreamTest() { const uno::Reference<ucb::XCommandEnvironment> xCmdEnv; @@ -107,17 +77,17 @@ DirectoryStreamTest::DirectoryStreamTest() void DirectoryStreamTest::testConstruction() { - const unique_ptr<DirectoryStream> pDir(createForParent(m_xFile)); + const unique_ptr<DirectoryStream> pDir(DirectoryStream::createForParent(m_xFile)); CPPUNIT_ASSERT(bool(pDir)); CPPUNIT_ASSERT(pDir->isStructured()); // this should work for dirs too - const unique_ptr<DirectoryStream> pDir2(createForParent(m_xDir)); + const unique_ptr<DirectoryStream> pDir2(DirectoryStream::createForParent(m_xDir)); CPPUNIT_ASSERT(bool(pDir2)); CPPUNIT_ASSERT(pDir2->isStructured()); // for nonexistent dirs nothing is created - const unique_ptr<DirectoryStream> pNondir(createForParent(m_xNonexistent)); + const unique_ptr<DirectoryStream> pNondir(DirectoryStream::createForParent(m_xNonexistent)); CPPUNIT_ASSERT(!pNondir); // even if we try harder, just an empty shell is created @@ -169,7 +139,7 @@ void DirectoryStreamTest::testStructuredOperations() DirectoryStream aDir(m_xDir); lcl_testStructuredOperations(aDir); - unique_ptr<DirectoryStream> pDir(createForParent(m_xFile)); + unique_ptr<DirectoryStream> pDir(DirectoryStream::createForParent(m_xFile)); CPPUNIT_ASSERT(bool(pDir)); lcl_testStructuredOperations(*pDir.get()); } diff --git a/writerperfect/source/common/DirectoryStream.cxx b/writerperfect/source/common/DirectoryStream.cxx index 3122844..dd4be4c 100644 --- a/writerperfect/source/common/DirectoryStream.cxx +++ b/writerperfect/source/common/DirectoryStream.cxx @@ -32,6 +32,8 @@ #include <comphelper/processfactory.hxx> +#include <o3tl/make_unique.hxx> + #include <rtl/ustring.hxx> #include <ucbhelper/content.hxx> @@ -128,6 +130,42 @@ bool DirectoryStream::isDirectory(const css::uno::Reference<css::ucb::XContent> } } +std::unique_ptr<DirectoryStream> DirectoryStream::createForParent(const css::uno::Reference<css::ucb::XContent> &xContent) +{ + try + { + if (!xContent.is()) + return nullptr; + + std::unique_ptr<DirectoryStream> pDir; + + const uno::Reference<css::container::XChild> xChild(xContent, uno::UNO_QUERY); + if (xChild.is()) + { + const uno::Reference<ucb::XContent> xDirContent(xChild->getParent(), uno::UNO_QUERY); + if (xDirContent.is()) + { + pDir = o3tl::make_unique<DirectoryStream>(xDirContent); + if (!pDir->isStructured()) + pDir.reset(); + } + } + + return pDir; + } + catch (...) + { + return nullptr; + } +} + +const css::uno::Reference<css::ucb::XContent> DirectoryStream::getContent() const +{ + if (!m_pImpl) + return css::uno::Reference<css::ucb::XContent>(); + return m_pImpl->xContent; +} + bool DirectoryStream::isStructured() { if (!m_pImpl) diff --git a/writerperfect/source/impress/KeynoteImportFilter.cxx b/writerperfect/source/impress/KeynoteImportFilter.cxx index 143131f..5aa2a6b 100644 --- a/writerperfect/source/impress/KeynoteImportFilter.cxx +++ b/writerperfect/source/impress/KeynoteImportFilter.cxx @@ -10,7 +10,6 @@ #include <memory> #include <com/sun/star/beans/NamedValue.hpp> #include <com/sun/star/beans/PropertyValue.hpp> -#include <com/sun/star/container/XChild.hpp> #include <com/sun/star/io/XInputStream.hpp> #include <com/sun/star/uno/Reference.h> #include <com/sun/star/ucb/XContent.hpp> @@ -48,7 +47,6 @@ using writerperfect::DocumentHandler; using writerperfect::WPXSvInputStream; namespace beans = com::sun::star::beans; -namespace container = com::sun::star::container; namespace ucb = com::sun::star::ucb; bool KeynoteImportFilter::doImportDocument(librevenge::RVNGInputStream &rInput, OdpGenerator &rGenerator, utl::MediaDescriptor &) @@ -159,25 +157,21 @@ OUString SAL_CALL KeynoteImportFilter::detect(css::uno::Sequence< css::beans::Pr if (bIsPackage) // we passed a directory stream, but the filter claims it's APXL file? return OUString(); - const Reference < container::XChild > xChild(xContent, UNO_QUERY); - if (xChild.is()) + const std::shared_ptr<writerperfect::DirectoryStream> pDir = writerperfect::DirectoryStream::createForParent(xContent); + input = pDir; + if (bool(input)) { - const Reference < ucb::XContent > xPackageContent(xChild->getParent(), UNO_QUERY); - if (xPackageContent.is()) + if (libetonyek::EtonyekDocument::CONFIDENCE_EXCELLENT == libetonyek::EtonyekDocument::isSupported(input.get())) { - input.reset(new writerperfect::DirectoryStream(xPackageContent)); - if (libetonyek::EtonyekDocument::CONFIDENCE_EXCELLENT == libetonyek::EtonyekDocument::isSupported(input.get())) - { - xContent = xPackageContent; - bUCBContentChanged = true; - bIsPackage = true; - } - else - { - // The passed stream has been detected as APXL file, but its parent dir is not a valid Keynote - // package? Something is wrong here... - return OUString(); - } + xContent = pDir->getContent(); + bUCBContentChanged = true; + bIsPackage = true; + } + else + { + // The passed stream has been detected as APXL file, but its parent dir is not a valid Keynote + // package? Something is wrong here... + return OUString(); } } } _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
