[Libreoffice-commits] core.git: sw/CppunitTest_sw_filters_test2.mk sw/Module_sw.mk sw/qa

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Wed Jul 17 13:18:24 UTC 2019


 sw/CppunitTest_sw_filters_test2.mk |   63 +++++++++++++++
 sw/Module_sw.mk                    |    1 
 sw/qa/core/filters-test.cxx        |    4 -
 sw/qa/core/filters-test2.cxx       |  146 +++++++++++++++++++++++++++++++++++++
 4 files changed, 210 insertions(+), 4 deletions(-)

New commits:
commit 1c2ea35b983c1159fe4633e449f8302ac9a7a024
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Wed Jul 17 11:25:05 2019 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Wed Jul 17 15:17:19 2019 +0200

    split sw_filters unit test
    
    so that a regular make takes less time, this unit test always seems to
    execute last and it takes a very long time
    
    Change-Id: If68bcfafad77c18676ee0ba2a915db142a1f4041
    Reviewed-on: https://gerrit.libreoffice.org/75763
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

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: */


More information about the Libreoffice-commits mailing list