Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : */
9 :
10 : #include <sal/config.h>
11 :
12 : #include <boost/noncopyable.hpp>
13 : #include <com/sun/star/configuration/theDefaultProvider.hpp>
14 : #include <com/sun/star/lang/XComponent.hpp>
15 : #include <com/sun/star/util/XFlushable.hpp>
16 : #include <comphelper/processfactory.hxx>
17 : #include <cppunit/Protector.h>
18 : #include <cppunittester/protectorfactory.hxx>
19 : #include <i18nlangtag/lang.h>
20 : #include <i18nlangtag/languagetag.hxx>
21 : #include <i18nlangtag/mslangid.hxx>
22 : #include <sal/types.h>
23 : #include <tools/resmgr.hxx>
24 : #include <unotools/configmgr.hxx>
25 : #include <unotools/syslocaleoptions.hxx>
26 : #include <vcl/svapp.hxx>
27 :
28 : namespace {
29 :
30 : class Protector: public CppUnit::Protector, private boost::noncopyable {
31 : public:
32 196 : Protector() {
33 : // Force locale (and resource files loaded) to en-US:
34 196 : ResMgr::SetDefaultLocale(LanguageTag("en-US"));
35 196 : SvtSysLocaleOptions localOptions;
36 196 : localOptions.SetLocaleConfigString("en-US");
37 196 : localOptions.SetUILocaleConfigString("en-US");
38 196 : MsLangId::setConfiguredSystemUILanguage(LANGUAGE_ENGLISH_US);
39 196 : LanguageTag::setConfiguredSystemLanguage(LANGUAGE_ENGLISH_US);
40 196 : InitVCL();
41 196 : if (Application::IsHeadlessModeRequested()) {
42 196 : Application::EnableHeadlessMode(true);
43 : }
44 196 : Application::setDeInitHook(STATIC_LINK(this, Protector, deinitHook));
45 196 : }
46 :
47 : private:
48 588 : virtual ~Protector() {
49 196 : DeInitVCL();
50 392 : }
51 :
52 13932 : virtual bool protect(
53 : CppUnit::Functor const & functor, CppUnit::ProtectorContext const &)
54 : SAL_OVERRIDE
55 13932 : { return functor(); }
56 :
57 : DECL_STATIC_LINK(Protector, deinitHook, void *);
58 : };
59 :
60 : // HACK so that defaultBootstrap_InitialComponentContext (in
61 : // unobootstrapprotector) is called before InitVCL (above), but component
62 : // context is disposed (redundantly again in unobootstrapprotector) from within
63 : // DeInitVCL (cf. Desktop::DeInit, desktop/source/app/app.cxx):
64 392 : IMPL_STATIC_LINK_NOINSTANCE(Protector, deinitHook, void *, EMPTYARG) {
65 196 : css::uno::Reference<css::uno::XComponentContext> context;
66 : try {
67 196 : context = comphelper::getProcessComponentContext();
68 0 : } catch (css::uno::RuntimeException &) {}
69 196 : if (context.is()) {
70 196 : css::uno::Reference<css::lang::XMultiServiceFactory> config;
71 : try {
72 196 : config = css::configuration::theDefaultProvider::get(context);
73 0 : } catch (css::uno::DeploymentException &) {}
74 196 : if (config.is()) {
75 196 : utl::ConfigManager::storeConfigItems();
76 : css::uno::Reference<css::util::XFlushable>(
77 196 : config, css::uno::UNO_QUERY_THROW)->flush();
78 : }
79 : css::uno::Reference<css::lang::XComponent>(
80 196 : context, css::uno::UNO_QUERY_THROW)->dispose();
81 196 : comphelper::setProcessServiceFactory(0);
82 : }
83 196 : return 0;
84 : }
85 :
86 : }
87 :
88 : extern "C" SAL_DLLPUBLIC_EXPORT CppUnit::Protector * SAL_CALL
89 196 : vclbootstrapprotector() {
90 196 : return new Protector;
91 588 : }
92 :
93 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|