1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include <sal/config.h>
12 #include <com/sun/star/configuration/theDefaultProvider.hpp>
13 #include <com/sun/star/lang/XComponent.hpp>
14 #include <com/sun/star/util/XFlushable.hpp>
15 #include <comphelper/processfactory.hxx>
16 #include <i18nlangtag/lang.h>
17 #include <i18nlangtag/languagetag.hxx>
18 #include <i18nlangtag/mslangid.hxx>
19 #include <test/setupvcl.hxx>
20 #include <unotools/resmgr.hxx>
21 #include <unotools/configmgr.hxx>
22 #include <unotools/syslocaleoptions.hxx>
23 #include <vcl/svapp.hxx>
25 #include "isheadless.hxx"
29 struct Hook
{ // LINK only works as a member of a class...
30 DECL_STATIC_LINK(Hook
, deinitHook
, LinkParamNone
*, void);
33 // HACK so that defaultBootstrap_InitialComponentContext (in
34 // unobootstrapprotector) is called before InitVCL (below), but component
35 // context is disposed (redundantly again in unobootstrapprotector) from within
36 // DeInitVCL (cf. Desktop::DeInit, desktop/source/app/app.cxx):
37 IMPL_STATIC_LINK_NOARG(Hook
, deinitHook
, LinkParamNone
*, void) {
38 css::uno::Reference
<css::uno::XComponentContext
> context
;
40 context
= comphelper::getProcessComponentContext();
41 } catch (css::uno::RuntimeException
&) {}
43 css::uno::Reference
<css::lang::XMultiServiceFactory
> config
;
45 config
= css::configuration::theDefaultProvider::get(context
);
46 } catch (css::uno::DeploymentException
&) {}
48 utl::ConfigManager::storeConfigItems();
49 css::uno::Reference
<css::util::XFlushable
>(
50 config
, css::uno::UNO_QUERY_THROW
)->flush();
52 css::uno::Reference
<css::lang::XComponent
>(
53 context
, css::uno::UNO_QUERY_THROW
)->dispose();
54 comphelper::setProcessServiceFactory(nullptr);
60 void test::setUpVcl(bool const forceHeadless
) {
61 // Force locale (and resource files loaded):
63 if (getenv("LO_TEST_LOCALE") != nullptr)
64 locale
= OUString::fromUtf8(getenv("LO_TEST_LOCALE"));
68 SvtSysLocaleOptions localOptions
;
69 localOptions
.SetLocaleConfigString(locale
);
70 localOptions
.SetUILocaleConfigString(locale
);
71 LanguageTag
tag(locale
);
72 MsLangId::setConfiguredSystemUILanguage(tag
.getLanguageType(false));
73 LanguageTag::setConfiguredSystemLanguage(tag
.getLanguageType(false));
75 if (forceHeadless
|| isHeadless()) {
76 Application::EnableHeadlessMode(false);
78 Application::setDeInitHook(LINK(nullptr, Hook
, deinitHook
));
81 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */