From 940b4d1848e8c70ab7642901a68594e8016caffc Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 18:51:28 +0200 Subject: Adding upstream version 1:7.0.4. Signed-off-by: Daniel Baumann --- test/source/setupvcl.cxx | 79 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 test/source/setupvcl.cxx (limited to 'test/source/setupvcl.cxx') diff --git a/test/source/setupvcl.cxx b/test/source/setupvcl.cxx new file mode 100644 index 000000000..56c0a3b3c --- /dev/null +++ b/test/source/setupvcl.cxx @@ -0,0 +1,79 @@ +/* -*- 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 + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "isheadless.hxx" +#include "setupvcl.hxx" + +namespace { + +struct Hook { // LINK only works as a member of a class... + DECL_STATIC_LINK(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(Hook, deinitHook, LinkParamNone *, void) { + css::uno::Reference context; + try { + context = comphelper::getProcessComponentContext(); + } catch (css::uno::RuntimeException &) {} + if (context.is()) { + css::uno::Reference config; + try { + config = css::configuration::theDefaultProvider::get(context); + } catch (css::uno::DeploymentException &) {} + if (config.is()) { + utl::ConfigManager::storeConfigItems(); + css::uno::Reference( + config, css::uno::UNO_QUERY_THROW)->flush(); + } + css::uno::Reference( + context, css::uno::UNO_QUERY_THROW)->dispose(); + comphelper::setProcessServiceFactory(nullptr); + } +} + +} + +void test::setUpVcl(bool const forceHeadless) { + // Force locale (and resource files loaded): + OUString locale; + if (getenv("LO_TEST_LOCALE") != nullptr) + locale = OUString::fromUtf8(getenv("LO_TEST_LOCALE")); + else + locale = "en-US"; + + SvtSysLocaleOptions localOptions; + localOptions.SetLocaleConfigString(locale); + localOptions.SetUILocaleConfigString(locale); + LanguageTag tag(locale); + MsLangId::setConfiguredSystemUILanguage(tag.getLanguageType(false)); + LanguageTag::setConfiguredSystemLanguage(tag.getLanguageType(false)); + InitVCL(); + if (forceHeadless || isHeadless()) { + Application::EnableHeadlessMode(false); + } + Application::setDeInitHook(LINK(nullptr, Hook, deinitHook)); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ -- cgit v1.2.3