summaryrefslogtreecommitdiff
path: root/writerperfect
diff options
context:
space:
mode:
authorDavid Tardon <dtardon@redhat.com>2017-02-13 22:51:31 +0100
committerDavid Tardon <dtardon@redhat.com>2017-02-13 22:56:52 +0100
commit1f7441211a5aa3c6ef379ae10b192a162ea6bdc8 (patch)
tree9aa18581912ca7a3f8ad0c823f29fdb80a6ca315 /writerperfect
parentd9b6edc0981c3f064d580df53e35dec11809afc5 (diff)
test result of text document import
Change-Id: I6830da0c6692f0be212e0d45597fa563917b5fb2
Diffstat (limited to 'writerperfect')
-rw-r--r--writerperfect/CppunitTest_writerperfect_wpftimport.mk52
-rw-r--r--writerperfect/Module_writerperfect.mk1
-rw-r--r--writerperfect/qa/unit/TextImportTest.cxx142
-rw-r--r--writerperfect/qa/unit/WpftLoader.cxx40
-rw-r--r--writerperfect/qa/unit/WpftLoader.hxx12
-rw-r--r--writerperfect/qa/unit/wpftimport.cxx28
-rw-r--r--writerperfect/qa/unit/wpftimport.hxx33
7 files changed, 301 insertions, 7 deletions
diff --git a/writerperfect/CppunitTest_writerperfect_wpftimport.mk b/writerperfect/CppunitTest_writerperfect_wpftimport.mk
new file mode 100644
index 000000000000..529f9535b428
--- /dev/null
+++ b/writerperfect/CppunitTest_writerperfect_wpftimport.mk
@@ -0,0 +1,52 @@
+# -*- 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_wpftimport))
+
+$(eval $(call gb_CppunitTest_set_include,writerperfect_wpftimport,\
+ -I$(SRCDIR)/writerperfect/inc \
+ -I$(SRCDIR)/writerperfect/source/writer \
+ $$(INCLUDE) \
+))
+
+$(eval $(call gb_CppunitTest_use_externals,writerperfect_wpftimport,\
+ odfgen \
+ revenge \
+))
+
+$(eval $(call gb_CppunitTest_use_sdk_api,writerperfect_wpftimport))
+
+$(eval $(call gb_CppunitTest_use_libraries,writerperfect_wpftimport,\
+ comphelper \
+ cppu \
+ cppuhelper \
+ sal \
+ test \
+ unotest \
+ utl \
+ wpftqahelper \
+ writerperfect \
+ $(gb_UWINAPI) \
+))
+
+$(eval $(call gb_CppunitTest_use_ure,writerperfect_wpftimport))
+$(eval $(call gb_CppunitTest_use_vcl,writerperfect_wpftimport))
+
+$(eval $(call gb_CppunitTest_use_rdbs,writerperfect_wpftimport,\
+ services \
+))
+
+$(eval $(call gb_CppunitTest_use_configuration,writerperfect_wpftimport))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,writerperfect_wpftimport,\
+ writerperfect/qa/unit/TextImportTest \
+ writerperfect/qa/unit/wpftimport \
+))
+
+# vim: set noet sw=4 ts=4:
diff --git a/writerperfect/Module_writerperfect.mk b/writerperfect/Module_writerperfect.mk
index 3c6168e3651e..0b862086f5a9 100644
--- a/writerperfect/Module_writerperfect.mk
+++ b/writerperfect/Module_writerperfect.mk
@@ -34,6 +34,7 @@ $(eval $(call gb_Module_add_l10n_targets,writerperfect,\
$(eval $(call gb_Module_add_check_targets,writerperfect,\
CppunitTest_writerperfect_stream \
+ CppunitTest_writerperfect_wpftimport \
))
$(eval $(call gb_Module_add_slowcheck_targets,writerperfect,\
diff --git a/writerperfect/qa/unit/TextImportTest.cxx b/writerperfect/qa/unit/TextImportTest.cxx
new file mode 100644
index 000000000000..fdd17c1572f9
--- /dev/null
+++ b/writerperfect/qa/unit/TextImportTest.cxx
@@ -0,0 +1,142 @@
+/* -*- 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/XPropertySet.hpp>
+#include <com/sun/star/container/XEnumeration.hpp>
+#include <com/sun/star/container/XEnumerationAccess.hpp>
+#include <com/sun/star/text/XTextDocument.hpp>
+#include <com/sun/star/uno/XComponentContext.hpp>
+
+#include <cppuhelper/supportsservice.hxx>
+
+#include <rtl/ref.hxx>
+
+#include "DocumentHandlerForOdt.hxx"
+#include "ImportFilter.hxx"
+#include "WpftFilterFixture.hxx"
+#include "WpftLoader.hxx"
+#include "wpftimport.hxx"
+
+namespace
+{
+
+namespace uno = css::uno;
+
+class TextImportFilter : public writerperfect::ImportFilter<OdtGenerator>
+{
+public:
+ explicit TextImportFilter(const uno::Reference< uno::XComponentContext > &rxContext)
+ : writerperfect::ImportFilter<OdtGenerator>(rxContext) {}
+
+ // XServiceInfo
+ virtual rtl::OUString SAL_CALL getImplementationName() override;
+ virtual sal_Bool SAL_CALL supportsService(const rtl::OUString &ServiceName) override;
+ virtual uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames() override;
+
+private:
+ virtual bool doDetectFormat(librevenge::RVNGInputStream &rInput, rtl::OUString &rTypeName) override;
+ virtual bool doImportDocument(librevenge::RVNGInputStream &rInput, OdtGenerator &rGenerator, utl::MediaDescriptor &rDescriptor) override;
+
+ void generate(librevenge::RVNGTextInterface &rDocument) const;
+};
+
+bool TextImportFilter::doImportDocument(librevenge::RVNGInputStream &, OdtGenerator &rGenerator, utl::MediaDescriptor &)
+{
+ generate(rGenerator);
+ return true;
+}
+
+bool TextImportFilter::doDetectFormat(librevenge::RVNGInputStream &, rtl::OUString &rTypeName)
+{
+ rTypeName = "WpftDummyText";
+ return true;
+}
+
+// XServiceInfo
+rtl::OUString SAL_CALL TextImportFilter::getImplementationName()
+{
+ return "org.libreoffice.comp.Wpft.QA.TextImportFilter";
+}
+
+sal_Bool SAL_CALL TextImportFilter::supportsService(const rtl::OUString &rServiceName)
+{
+ return cppu::supportsService(this, rServiceName);
+}
+
+uno::Sequence< rtl::OUString > SAL_CALL TextImportFilter::getSupportedServiceNames()
+{
+ return {"com.sun.star.document.ImportFilter", "com.sun.star.document.ExtendedTypeDetection"};
+}
+
+void TextImportFilter::generate(librevenge::RVNGTextInterface &rDocument) const
+{
+ using namespace librevenge;
+
+ rDocument.startDocument(RVNGPropertyList());
+ rDocument.openPageSpan(RVNGPropertyList());
+ rDocument.openParagraph(RVNGPropertyList());
+ rDocument.openSpan(RVNGPropertyList());
+ rDocument.insertText("My hovercraft is full of eels.");
+ rDocument.closeSpan();
+ rDocument.closeParagraph();
+ rDocument.closePageSpan();
+ rDocument.endDocument();
+}
+
+}
+
+namespace
+{
+
+class TextImportTest : public writerperfect::test::WpftFilterFixture
+{
+public:
+ void test();
+
+ CPPUNIT_TEST_SUITE(TextImportTest);
+ CPPUNIT_TEST(test);
+ CPPUNIT_TEST_SUITE_END();
+};
+
+void TextImportTest::test()
+{
+ using namespace css;
+
+ rtl::Reference<TextImportFilter> xFilter{new TextImportFilter(m_xContext)};
+ writerperfect::test::WpftLoader aLoader(createDummyInput(), xFilter.get(), "private:factory/swriter", m_xDesktop, m_xContext);
+
+ uno::Reference<text::XTextDocument> xDoc(aLoader.getDocument(), uno::UNO_QUERY);
+ CPPUNIT_ASSERT(xDoc.is());
+ uno::Reference<container::XEnumerationAccess> xParaAccess(xDoc->getText(), uno::UNO_QUERY);
+ CPPUNIT_ASSERT(xParaAccess.is());
+ uno::Reference<container::XEnumeration> xParas = xParaAccess->createEnumeration();
+ CPPUNIT_ASSERT(xParas.is());
+ CPPUNIT_ASSERT(xParas->hasMoreElements());
+ uno::Reference<container::XEnumerationAccess> xPortionsAccess(xParas->nextElement(), uno::UNO_QUERY);
+ CPPUNIT_ASSERT(xPortionsAccess.is());
+ uno::Reference<container::XEnumeration> xPortions = xPortionsAccess->createEnumeration();
+ CPPUNIT_ASSERT(xPortions.is());
+ CPPUNIT_ASSERT(xPortions->hasMoreElements());
+ uno::Reference<beans::XPropertySet> xPortionProps(xPortions->nextElement(), uno::UNO_QUERY);
+ CPPUNIT_ASSERT(xPortionProps.is());
+ rtl::OUString aPortionType;
+ CPPUNIT_ASSERT(xPortionProps->getPropertyValue("TextPortionType") >>= aPortionType);
+ CPPUNIT_ASSERT_EQUAL(rtl::OUString("Text"), aPortionType);
+ uno::Reference<text::XTextRange> xPortion(xPortionProps, uno::UNO_QUERY);
+ CPPUNIT_ASSERT(xPortion.is());
+ CPPUNIT_ASSERT_EQUAL(rtl::OUString("My hovercraft is full of eels."), xPortion->getString());
+ CPPUNIT_ASSERT(!xPortions->hasMoreElements());
+ CPPUNIT_ASSERT(!xParas->hasMoreElements());
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(TextImportTest);
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerperfect/qa/unit/WpftLoader.cxx b/writerperfect/qa/unit/WpftLoader.cxx
index 5299a27d9cc0..aa206adff80e 100644
--- a/writerperfect/qa/unit/WpftLoader.cxx
+++ b/writerperfect/qa/unit/WpftLoader.cxx
@@ -20,6 +20,7 @@
#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/io/XInputStream.hpp>
#include <com/sun/star/lang/IllegalArgumentException.hpp>
#include <com/sun/star/lang/XComponent.hpp>
#include <com/sun/star/ucb/XCommandEnvironment.hpp>
@@ -62,6 +63,23 @@ WpftLoader::WpftLoader(
impl_dispose();
}
+WpftLoader::WpftLoader(
+ const css::uno::Reference<css::io::XInputStream> &rxInputStream,
+ 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::uno::XComponentContext> &rxContext
+)
+ : m_xInputStream(rxInputStream)
+ , m_aFactoryURL(rFactoryURL)
+ , m_xFilter(rxFilter)
+ , m_xDesktop(rxDesktop)
+ , m_xContext(rxContext)
+{
+ if (!impl_load())
+ impl_dispose();
+}
+
WpftLoader::~WpftLoader()
{
try
@@ -117,14 +135,21 @@ bool WpftLoader::impl_load()
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();
+ if (m_xInputStream.is())
+ {
+ aDescriptor[1].Name = "InputStream";
+ aDescriptor[1].Value <<= m_xInputStream;
+ }
+ else
+ {
+ ucbhelper::Content aContent(m_aURL, uno::Reference<ucb::XCommandEnvironment>(), m_xContext);
+ 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);
@@ -132,7 +157,8 @@ bool WpftLoader::impl_load()
if (aTypeName.isEmpty())
throw lang::IllegalArgumentException();
- impl_detectFilterName(aDescriptor, aTypeName);
+ if (m_xTypeMap.is())
+ impl_detectFilterName(aDescriptor, aTypeName);
xModel->lockControllers();
const bool bLoaded = m_xFilter->filter(aDescriptor);
diff --git a/writerperfect/qa/unit/WpftLoader.hxx b/writerperfect/qa/unit/WpftLoader.hxx
index 92a1ff008e31..0283b6a6fcda 100644
--- a/writerperfect/qa/unit/WpftLoader.hxx
+++ b/writerperfect/qa/unit/WpftLoader.hxx
@@ -40,6 +40,10 @@ namespace frame
class XDesktop2;
class XFrame;
}
+namespace io
+{
+class XInputStream;
+}
namespace lang
{
class XComponent;
@@ -68,6 +72,13 @@ public:
const css::uno::Reference<css::container::XNameAccess> &rxTypeMap,
const css::uno::Reference<css::uno::XComponentContext> &rxContext
);
+ WpftLoader(
+ const css::uno::Reference<css::io::XInputStream> &rxInputStream,
+ 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::uno::XComponentContext> &rxContext
+ );
~WpftLoader();
const css::uno::Reference<css::lang::XComponent> &getDocument() const;
@@ -80,6 +91,7 @@ private:
private:
const rtl::OUString m_aURL;
+ const css::uno::Reference<css::io::XInputStream> m_xInputStream;
const rtl::OUString m_aFactoryURL;
const css::uno::Reference<css::document::XFilter> m_xFilter;
const css::uno::Reference<css::frame::XDesktop2> m_xDesktop;
diff --git a/writerperfect/qa/unit/wpftimport.cxx b/writerperfect/qa/unit/wpftimport.cxx
new file mode 100644
index 000000000000..27b566c37df2
--- /dev/null
+++ b/writerperfect/qa/unit/wpftimport.cxx
@@ -0,0 +1,28 @@
+/* -*- 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 "wpftimport.hxx"
+
+#include <cppunit/plugin/TestPlugIn.h>
+
+#include <comphelper/seqstream.hxx>
+
+#include <rtl/ref.hxx>
+
+#include <sal/types.h>
+
+css::uno::Reference<css::io::XInputStream> createDummyInput()
+{
+ rtl::Reference<comphelper::SequenceInputStream> xDummyInput{new comphelper::SequenceInputStream({})};
+ return xDummyInput.get();
+}
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerperfect/qa/unit/wpftimport.hxx b/writerperfect/qa/unit/wpftimport.hxx
new file mode 100644
index 000000000000..136c24d6c65e
--- /dev/null
+++ b/writerperfect/qa/unit/wpftimport.hxx
@@ -0,0 +1,33 @@
+/* -*- 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_WPFTIMPORT_HXX
+#define INCLUDED_WRITERPERFECT_QA_UNIT_WPFTIMPORT_HXX
+
+#include <com/sun/star/uno/Reference.hxx>
+
+namespace com
+{
+namespace sun
+{
+namespace star
+{
+namespace io
+{
+class XInputStream;
+}
+}
+}
+}
+
+css::uno::Reference<css::io::XInputStream> createDummyInput();
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */