summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sw/CppunitTest_sw_filters_test2.mk63
-rw-r--r--sw/Module_sw.mk1
-rw-r--r--sw/qa/core/filters-test.cxx4
-rw-r--r--sw/qa/core/filters-test2.cxx146
4 files changed, 210 insertions, 4 deletions
diff --git a/sw/CppunitTest_sw_filters_test2.mk b/sw/CppunitTest_sw_filters_test2.mk
new file mode 100644
index 000000000000..3b36f4ec2b79
--- /dev/null
+++ b/sw/CppunitTest_sw_filters_test2.mk
@@ -0,0 +1,63 @@
+# -*- 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,sw_filters_test2))
+
+$(eval $(call gb_CppunitTest_use_externals,sw_filters_test2,\
+ boost_headers \
+ libxml2 \
+))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,sw_filters_test2, \
+ sw/qa/core/filters-test2 \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,sw_filters_test2, \
+ sw \
+ sfx \
+ svl \
+ svt \
+ sot \
+ test \
+ tl \
+ ucbhelper \
+ unotest \
+ utl \
+ vcl \
+ i18nlangtag \
+ comphelper \
+ cppu \
+ cppuhelper \
+ sal \
+))
+
+$(eval $(call gb_CppunitTest_set_include,sw_filters_test2,\
+ -I$(SRCDIR)/sw/inc \
+ $$(INCLUDE) \
+))
+
+$(eval $(call gb_CppunitTest_use_api,sw_filters_test2,\
+ udkapi \
+ offapi \
+ oovbaapi \
+))
+
+$(eval $(call gb_CppunitTest_use_ure,sw_filters_test2))
+$(eval $(call gb_CppunitTest_use_vcl,sw_filters_test2))
+
+$(eval $(call gb_CppunitTest_use_rdb,sw_filters_test2,services))
+
+$(eval $(call gb_CppunitTest_use_configuration,sw_filters_test2))
+
+$(call gb_CppunitTest_get_target,sw_filters_test2): \
+ $(call gb_Package_get_target,extras_tplwizdesktop)
+
+# vim: set noet sw=4 ts=4:
diff --git a/sw/Module_sw.mk b/sw/Module_sw.mk
index fd47c9831a5c..549047d9e9ec 100644
--- a/sw/Module_sw.mk
+++ b/sw/Module_sw.mk
@@ -116,6 +116,7 @@ endif
ifneq ($(DISABLE_CVE_TESTS),TRUE)
$(eval $(call gb_Module_add_slowcheck_targets,sw,\
CppunitTest_sw_filters_test \
+ CppunitTest_sw_filters_test2 \
))
endif
diff --git a/sw/qa/core/filters-test.cxx b/sw/qa/core/filters-test.cxx
index 67db9346e52e..14aa0aa39c56 100644
--- a/sw/qa/core/filters-test.cxx
+++ b/sw/qa/core/filters-test.cxx
@@ -144,10 +144,6 @@ void SwFiltersTest::testCVEs()
m_directories.getURLFromSrc("/sw/qa/core/data/ww8/"),
FILTER_WW8);
- testDir("MS WinWord 6.0",
- m_directories.getURLFromSrc("/sw/qa/core/data/ww6/"),
- sWW6);
-
testDir("MS WinWord 5",
m_directories.getURLFromSrc("/sw/qa/core/data/ww5/"),
sWW5);
diff --git a/sw/qa/core/filters-test2.cxx b/sw/qa/core/filters-test2.cxx
new file mode 100644
index 000000000000..6ce9376f681c
--- /dev/null
+++ b/sw/qa/core/filters-test2.cxx
@@ -0,0 +1,146 @@
+/* -*- 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 <unotest/filters-test.hxx>
+#include <test/bootstrapfixture.hxx>
+
+#include <comphelper/fileformat.h>
+
+#include <sfx2/app.hxx>
+#include <sfx2/docfilt.hxx>
+#include <sfx2/docfile.hxx>
+#include <sfx2/sfxsids.hrc>
+#include <sfx2/fcontnr.hxx>
+
+#include <svl/stritem.hxx>
+#include <unotools/tempfile.hxx>
+
+#include <iodetect.hxx>
+#include <docsh.hxx>
+
+typedef tools::SvRef<SwDocShell> SwDocShellRef;
+
+using namespace ::com::sun::star;
+
+/* Implementation of Filters test */
+
+class SwFiltersTest2 : public test::FiltersTest, public test::BootstrapFixture
+{
+public:
+ virtual bool load(const OUString& rFilter, const OUString& rURL, const OUString& rUserData,
+ SfxFilterFlags nFilterFlags, SotClipboardFormatId nClipboardID,
+ unsigned int nFilterVersion) override;
+ virtual bool save(const OUString& rFilter, const OUString& rURL, const OUString& rUserData,
+ SfxFilterFlags nFilterFlags, SotClipboardFormatId nClipboardID,
+ unsigned int nFilterVersion) override;
+ virtual void setUp() override;
+
+ // Ensure CVEs remain unbroken
+ void testCVEs();
+
+ CPPUNIT_TEST_SUITE(SwFiltersTest2);
+ CPPUNIT_TEST(testCVEs);
+ CPPUNIT_TEST_SUITE_END();
+
+private:
+ bool filter(const OUString& rFilter, const OUString& rURL, const OUString& rUserData,
+ SfxFilterFlags nFilterFlags, SotClipboardFormatId nClipboardID,
+ unsigned int nFilterVersion, bool bExport);
+ uno::Reference<uno::XInterface> m_xWriterComponent;
+};
+
+bool SwFiltersTest2::load(const OUString& rFilter, const OUString& rURL, const OUString& rUserData,
+ SfxFilterFlags nFilterFlags, SotClipboardFormatId nClipboardID,
+ unsigned int nFilterVersion)
+{
+ return filter(rFilter, rURL, rUserData, nFilterFlags, nClipboardID, nFilterVersion, false);
+}
+
+bool SwFiltersTest2::save(const OUString& rFilter, const OUString& rURL, const OUString& rUserData,
+ SfxFilterFlags nFilterFlags, SotClipboardFormatId nClipboardID,
+ unsigned int nFilterVersion)
+{
+ return filter(rFilter, rURL, rUserData, nFilterFlags, nClipboardID, nFilterVersion, true);
+}
+
+bool SwFiltersTest2::filter(const OUString& rFilter, const OUString& rURL,
+ const OUString& rUserData, SfxFilterFlags nFilterFlags,
+ SotClipboardFormatId nClipboardID, unsigned int nFilterVersion,
+ bool bExport)
+{
+ std::shared_ptr<const SfxFilter> pFilter(new SfxFilter(rFilter, OUString(), nFilterFlags,
+ nClipboardID, OUString(), OUString(),
+ rUserData, OUString()));
+ const_cast<SfxFilter*>(pFilter.get())->SetVersion(nFilterVersion);
+
+ SwDocShellRef xDocShRef = new SwDocShell;
+ SfxMedium* pSrcMed = new SfxMedium(rURL, StreamMode::STD_READ);
+
+ std::shared_ptr<const SfxFilter> pImportFilter;
+ std::shared_ptr<const SfxFilter> pExportFilter;
+ if (bExport)
+ {
+ SfxGetpApp()->GetFilterMatcher().GuessFilter(*pSrcMed, pImportFilter,
+ SfxFilterFlags::IMPORT, SfxFilterFlags::NONE);
+ pExportFilter = pFilter;
+ }
+ else
+ pImportFilter = pFilter;
+
+ pSrcMed->SetFilter(pImportFilter);
+
+ if (rUserData == FILTER_TEXT_DLG)
+ {
+ pSrcMed->GetItemSet()->Put(
+ SfxStringItem(SID_FILE_FILTEROPTIONS, "UTF8,LF,Liberation Mono,en-US"));
+ }
+
+ bool bLoaded = xDocShRef->DoLoad(pSrcMed);
+ if (!bExport)
+ {
+ if (xDocShRef.is())
+ xDocShRef->DoClose();
+ return bLoaded;
+ }
+
+ // How come an error may be set, and still DoLoad() returns success? Strange...
+ if (bLoaded)
+ xDocShRef->ResetError();
+
+ utl::TempFile aTempFile;
+ aTempFile.EnableKillingFile();
+ SfxMedium aDstMed(aTempFile.GetURL(), StreamMode::STD_WRITE);
+ aDstMed.SetFilter(pExportFilter);
+ bool bSaved = xDocShRef->DoSaveAs(aDstMed);
+ if (xDocShRef.is())
+ xDocShRef->DoClose();
+ return bSaved;
+}
+
+void SwFiltersTest2::testCVEs()
+{
+ testDir("MS WinWord 6.0", m_directories.getURLFromSrc("/sw/qa/core/data/ww6/"), sWW6);
+}
+
+void SwFiltersTest2::setUp()
+{
+ test::BootstrapFixture::setUp();
+
+ //This is a bit of a fudge, we do this to ensure that SwGlobals::ensure,
+ //which is a private symbol to us, gets called
+ m_xWriterComponent
+ = getMultiServiceFactory()->createInstance("com.sun.star.comp.Writer.TextDocument");
+ CPPUNIT_ASSERT_MESSAGE("no writer component!", m_xWriterComponent.is());
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(SwFiltersTest2);
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */