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 <com/sun/star/frame/Desktop.hpp>
16 #include <comphelper/processfactory.hxx>
17 #include <i18nlangtag/languagetag.hxx>
18 #include <i18nlangtag/mslangid.hxx>
19 #include <unotools/configmgr.hxx>
20 #include <unotools/syslocaleoptions.hxx>
21 #include <vcl/svapp.hxx>
23 #include "isheadless.hxx"
24 #include "setupvcl.hxx"
28 struct Hook
{ // LINK only works as a member of a class...
29 DECL_STATIC_LINK(Hook
, deinitHook
, LinkParamNone
*, void);
32 // HACK so that defaultBootstrap_InitialComponentContext (in
33 // unobootstrapprotector) is called before InitVCL (below), but component
34 // context is disposed (redundantly again in unobootstrapprotector) from within
35 // DeInitVCL (cf. Desktop::DeInit, desktop/source/app/app.cxx):
36 IMPL_STATIC_LINK_NOARG(Hook
, deinitHook
, LinkParamNone
*, void) {
37 css::uno::Reference
<css::uno::XComponentContext
> context
;
39 context
= comphelper::getProcessComponentContext();
40 } catch (css::uno::RuntimeException
&) {}
45 css::uno::Reference
<css::lang::XMultiServiceFactory
> config
;
47 config
= css::configuration::theDefaultProvider::get(context
);
48 } catch (css::uno::DeploymentException
&) {}
50 utl::ConfigManager::storeConfigItems();
51 css::uno::Reference
<css::util::XFlushable
>(
52 config
, css::uno::UNO_QUERY_THROW
)->flush();
55 // the desktop has to be terminate() before it can be dispose()
56 css::uno::Reference
<css::frame::XDesktop
> xDesktop
;
58 xDesktop
= css::frame::Desktop::create(comphelper::getProcessComponentContext());
59 } catch (css::uno::DeploymentException
&) {}
62 xDesktop
->terminate();
63 } catch (css::uno::DeploymentException
&) {}
65 css::uno::Reference
<css::lang::XComponent
>(
66 context
, css::uno::UNO_QUERY_THROW
)->dispose();
68 comphelper::setProcessServiceFactory(nullptr);
73 void test::setUpVcl(bool const forceHeadless
) {
74 // Force locale (and resource files loaded):
76 if (getenv("LO_TEST_LOCALE") != nullptr)
77 locale
= OUString::fromUtf8(getenv("LO_TEST_LOCALE"));
81 SvtSysLocaleOptions localOptions
;
82 localOptions
.SetLocaleConfigString(locale
);
83 localOptions
.SetUILocaleConfigString(locale
);
84 LanguageTag
tag(locale
);
85 MsLangId::setConfiguredSystemUILanguage(tag
.getLanguageType(false));
86 LanguageTag::setConfiguredSystemLanguage(tag
.getLanguageType(false));
88 if (forceHeadless
|| isHeadless()) {
89 Application::EnableHeadlessMode(false);
91 Application::setDeInitHook(LINK(nullptr, Hook
, deinitHook
));
94 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */