Kaydet (Commit) 47140832 authored tarafından Stephan Bergmann's avatar Stephan Bergmann

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
üst 66e2f20c
/* -*- 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: */
......@@ -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:
......@@ -23,6 +23,7 @@ $(eval $(call gb_Library_use_libraries,vclbootstrapprotector, \
cppu \
i18nlangtag \
sal \
test \
tl \
utl \
vcl \
......
......@@ -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(); }
......
......@@ -13,6 +13,7 @@
#include <sal/config.h>
#include <rtl/process.h>
#include <rtl/ustring.hxx>
#include <sal/types.h>
namespace test {
......
/* -*- 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: */
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment