[Libreoffice-commits] core.git: include/test test/Library_test.mk test/Library_vclbootstrapprotector.mk test/source

Stephan Bergmann sbergman at redhat.com
Mon Aug 29 15:57:46 UTC 2016


 include/test/setupvcl.hxx             |   26 +++++++++++
 test/Library_test.mk                  |    1 
 test/Library_vclbootstrapprotector.mk |    1 
 test/source/bootstrapfixture.cxx      |   29 -------------
 test/source/isheadless.hxx            |    1 
 test/source/setupvcl.cxx              |   75 ++++++++++++++++++++++++++++++++++
 test/source/vclbootstrapprotector.cxx |   54 ------------------------
 7 files changed, 108 insertions(+), 79 deletions(-)

New commits:
commit 471408327978144dcc11f5f65f8208016867e03a
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Mon Aug 29 17:54:04 2016 +0200

    Remove duplication of "set up VCL" code
    
    The "this is called from pyuno" version in test/source/bootstrapfixture.cxx had
    had an empty deinitHook, but it appears to not hurt to give it the same
    deinitHook as the version in test/source/vclbootstrapprotector.cxx had had.
    
    Make test::setUpVcl accessible from outside module test for an upcoming use in
    <https://gerrit.libreoffice.org/#/c/28322/16> "tdf#99402: fix Metafile Font
    handling".
    
    Change-Id: I1d609445690b6ee5e331aa322cd4bf434a3de78e

diff --git a/include/test/setupvcl.hxx b/include/test/setupvcl.hxx
new file mode 100644
index 0000000..b2b3afa
--- /dev/null
+++ b/include/test/setupvcl.hxx
@@ -0,0 +1,26 @@
+/* -*- 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_TEST_SETUPVCL_HXX
+#define INCLUDED_TEST_SETUPVCL_HXX
+
+#include <sal/config.h>
+
+#include <test/testdllapi.hxx>
+
+namespace test {
+
+// Calls InitVCL etc.; needed from multiple places in the test infrastructure:
+OOO_DLLPUBLIC_TEST void setUpVcl();
+
+}
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/test/Library_test.mk b/test/Library_test.mk
index 2e34b21..c0f073b 100644
--- a/test/Library_test.mk
+++ b/test/Library_test.mk
@@ -48,6 +48,7 @@ $(eval $(call gb_Library_add_exception_objects,test,\
     test/source/xmlwriter \
     test/source/primitive2dxmldump \
     test/source/screenshot_test \
+    test/source/setupvcl \
 ))
 
 # vim: set noet sw=4 ts=4:
diff --git a/test/Library_vclbootstrapprotector.mk b/test/Library_vclbootstrapprotector.mk
index 0bb808a..d16145b 100644
--- a/test/Library_vclbootstrapprotector.mk
+++ b/test/Library_vclbootstrapprotector.mk
@@ -23,6 +23,7 @@ $(eval $(call gb_Library_use_libraries,vclbootstrapprotector, \
     cppu \
     i18nlangtag \
     sal \
+    test \
     tl \
     utl \
     vcl \
diff --git a/test/source/bootstrapfixture.cxx b/test/source/bootstrapfixture.cxx
index 27e1488..442216a 100644
--- a/test/source/bootstrapfixture.cxx
+++ b/test/source/bootstrapfixture.cxx
@@ -10,6 +10,7 @@
 #include <config_features.h>
 
 #include <test/bootstrapfixture.hxx>
+#include <test/setupvcl.hxx>
 #include <tools/errinf.hxx>
 #include <rtl/strbuf.hxx>
 #include <rtl/bootstrap.hxx>
@@ -84,39 +85,13 @@ void test_init_impl(bool bAssertOnDialog, bool bNeedUCB,
     }
 }
 
-struct InitHook {
-    DECL_STATIC_LINK_TYPED(InitHook, deinitHook, LinkParamNone*, void);
-};
-
-IMPL_STATIC_LINK_NOARG_TYPED(InitHook, deinitHook, LinkParamNone*, void) {
-    // nothing to do for now
-}
-
 // this is called from pyuno
 SAL_DLLPUBLIC_EXPORT void test_init(lang::XMultiServiceFactory *pFactory)
 {
     try
     {
         ::comphelper::setProcessServiceFactory(pFactory);
-
-        // force locale (and resource files loaded) to en-US
-        OUString aLangISO( "en-US" );
-        ResMgr::SetDefaultLocale( LanguageTag( aLangISO) );
-
-        SvtSysLocaleOptions aLocalOptions;
-        aLocalOptions.SetLocaleConfigString( aLangISO );
-        aLocalOptions.SetUILocaleConfigString( aLangISO );
-
-        MsLangId::setConfiguredSystemUILanguage(LANGUAGE_ENGLISH_US);
-        LanguageTag::setConfiguredSystemLanguage(LANGUAGE_ENGLISH_US);
-
-        InitVCL();
-        if (test::isHeadless())
-            Application::EnableHeadlessMode(true);
-
-        // avoid VCLXToolkit thinking that InitVCL hasn't been called
-        Application::setDeInitHook(LINK(nullptr, InitHook, deinitHook));
-
+        test::setUpVcl();
         test_init_impl(false, true, pFactory);
     }
     catch (...) { abort(); }
diff --git a/test/source/isheadless.hxx b/test/source/isheadless.hxx
index 79ff330..8a3e81e 100644
--- a/test/source/isheadless.hxx
+++ b/test/source/isheadless.hxx
@@ -13,6 +13,7 @@
 #include <sal/config.h>
 
 #include <rtl/process.h>
+#include <rtl/ustring.hxx>
 #include <sal/types.h>
 
 namespace test {
diff --git a/test/source/setupvcl.cxx b/test/source/setupvcl.cxx
new file mode 100644
index 0000000..c1703aa
--- /dev/null
+++ b/test/source/setupvcl.cxx
@@ -0,0 +1,75 @@
+/* -*- 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 <sal/config.h>
+
+#include <com/sun/star/configuration/theDefaultProvider.hpp>
+#include <com/sun/star/lang/XComponent.hpp>
+#include <com/sun/star/util/XFlushable.hpp>
+#include <comphelper/processfactory.hxx>
+#include <i18nlangtag/lang.h>
+#include <i18nlangtag/languagetag.hxx>
+#include <i18nlangtag/mslangid.hxx>
+#include <test/setupvcl.hxx>
+#include <tools/resmgr.hxx>
+#include <unotools/configmgr.hxx>
+#include <unotools/syslocaleoptions.hxx>
+#include <vcl/svapp.hxx>
+
+#include <isheadless.hxx>
+
+namespace {
+
+struct Hook { // LINK only works as a member of a class...
+    DECL_STATIC_LINK_TYPED(Hook, deinitHook, LinkParamNone *, void);
+};
+
+// HACK so that defaultBootstrap_InitialComponentContext (in
+// unobootstrapprotector) is called before InitVCL (below), but component
+// context is disposed (redundantly again in unobootstrapprotector) from within
+// DeInitVCL (cf. Desktop::DeInit, desktop/source/app/app.cxx):
+IMPL_STATIC_LINK_NOARG_TYPED(Hook, deinitHook, LinkParamNone *, void) {
+    css::uno::Reference<css::uno::XComponentContext> context;
+    try {
+        context = comphelper::getProcessComponentContext();
+    } catch (css::uno::RuntimeException &) {}
+    if (context.is()) {
+        css::uno::Reference<css::lang::XMultiServiceFactory> config;
+        try {
+            config = css::configuration::theDefaultProvider::get(context);
+        } catch (css::uno::DeploymentException &) {}
+        if (config.is()) {
+            utl::ConfigManager::storeConfigItems();
+            css::uno::Reference<css::util::XFlushable>(
+                config, css::uno::UNO_QUERY_THROW)->flush();
+        }
+        css::uno::Reference<css::lang::XComponent>(
+            context, css::uno::UNO_QUERY_THROW)->dispose();
+        comphelper::setProcessServiceFactory(nullptr);
+    }
+}
+
+}
+
+void test::setUpVcl() {
+    // Force locale (and resource files loaded) to en-US:
+    ResMgr::SetDefaultLocale(LanguageTag("en-US"));
+    SvtSysLocaleOptions localOptions;
+    localOptions.SetLocaleConfigString("en-US");
+    localOptions.SetUILocaleConfigString("en-US");
+    MsLangId::setConfiguredSystemUILanguage(LANGUAGE_ENGLISH_US);
+    LanguageTag::setConfiguredSystemLanguage(LANGUAGE_ENGLISH_US);
+    InitVCL();
+    if (isHeadless()) {
+        Application::EnableHeadlessMode(true);
+    }
+    Application::setDeInitHook(LINK(nullptr, Hook, deinitHook));
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/test/source/vclbootstrapprotector.cxx b/test/source/vclbootstrapprotector.cxx
index 2f193c6..fb8531d 100644
--- a/test/source/vclbootstrapprotector.cxx
+++ b/test/source/vclbootstrapprotector.cxx
@@ -9,19 +9,10 @@
 
 #include <sal/config.h>
 
-#include <com/sun/star/configuration/theDefaultProvider.hpp>
-#include <com/sun/star/lang/XComponent.hpp>
-#include <com/sun/star/util/XFlushable.hpp>
-#include <comphelper/processfactory.hxx>
 #include <cppunit/Protector.h>
 #include <cppunittester/protectorfactory.hxx>
-#include <i18nlangtag/lang.h>
-#include <i18nlangtag/languagetag.hxx>
-#include <i18nlangtag/mslangid.hxx>
 #include <sal/types.h>
-#include <tools/resmgr.hxx>
-#include <unotools/configmgr.hxx>
-#include <unotools/syslocaleoptions.hxx>
+#include <test/setupvcl.hxx>
 #include <vcl/svapp.hxx>
 
 #include <isheadless.hxx>
@@ -30,20 +21,7 @@ namespace {
 
 class Protector: public CppUnit::Protector {
 public:
-    Protector() {
-        // Force locale (and resource files loaded) to en-US:
-        ResMgr::SetDefaultLocale(LanguageTag("en-US"));
-        SvtSysLocaleOptions localOptions;
-        localOptions.SetLocaleConfigString("en-US");
-        localOptions.SetUILocaleConfigString("en-US");
-        MsLangId::setConfiguredSystemUILanguage(LANGUAGE_ENGLISH_US);
-        LanguageTag::setConfiguredSystemLanguage(LANGUAGE_ENGLISH_US);
-        InitVCL();
-        if (test::isHeadless()) {
-            Application::EnableHeadlessMode(true);
-        }
-        Application::setDeInitHook(LINK(this, Protector, deinitHook));
-    }
+    Protector() { test::setUpVcl(); }
     Protector(const Protector&) = delete;
     Protector& operator=(const Protector&) = delete;
 
@@ -56,36 +34,8 @@ private:
         CppUnit::Functor const & functor, CppUnit::ProtectorContext const &)
         override
     { return functor(); }
-
-    DECL_STATIC_LINK_TYPED(Protector, deinitHook, LinkParamNone*, void);
 };
 
-// HACK so that defaultBootstrap_InitialComponentContext (in
-// unobootstrapprotector) is called before InitVCL (above), but component
-// context is disposed (redundantly again in unobootstrapprotector) from within
-// DeInitVCL (cf. Desktop::DeInit, desktop/source/app/app.cxx):
-IMPL_STATIC_LINK_NOARG_TYPED(Protector, deinitHook, LinkParamNone*, void)
-{
-    css::uno::Reference<css::uno::XComponentContext> context;
-    try {
-        context = comphelper::getProcessComponentContext();
-    } catch (css::uno::RuntimeException &) {}
-    if (context.is()) {
-        css::uno::Reference<css::lang::XMultiServiceFactory> config;
-        try {
-            config = css::configuration::theDefaultProvider::get(context);
-        } catch (css::uno::DeploymentException &) {}
-        if (config.is()) {
-            utl::ConfigManager::storeConfigItems();
-            css::uno::Reference<css::util::XFlushable>(
-                config, css::uno::UNO_QUERY_THROW)->flush();
-        }
-        css::uno::Reference<css::lang::XComponent>(
-            context, css::uno::UNO_QUERY_THROW)->dispose();
-        comphelper::setProcessServiceFactory(nullptr);
-    }
-}
-
 }
 
 extern "C" SAL_DLLPUBLIC_EXPORT CppUnit::Protector * SAL_CALL


More information about the Libreoffice-commits mailing list