LCOV - code coverage report
Current view: top level - test/source - vclbootstrapprotector.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 31 33 93.9 %
Date: 2015-06-13 12:38:46 Functions: 7 7 100.0 %
Legend: Lines: hit not hit

          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             : #include <isheadless.hxx>
      29             : 
      30             : namespace {
      31             : 
      32             : class Protector: public CppUnit::Protector, private boost::noncopyable {
      33             : public:
      34         115 :     Protector() {
      35             :         // Force locale (and resource files loaded) to en-US:
      36         115 :         ResMgr::SetDefaultLocale(LanguageTag("en-US"));
      37         115 :         SvtSysLocaleOptions localOptions;
      38         115 :         localOptions.SetLocaleConfigString("en-US");
      39         115 :         localOptions.SetUILocaleConfigString("en-US");
      40         115 :         MsLangId::setConfiguredSystemUILanguage(LANGUAGE_ENGLISH_US);
      41         115 :         LanguageTag::setConfiguredSystemLanguage(LANGUAGE_ENGLISH_US);
      42         115 :         InitVCL();
      43         115 :         if (test::isHeadless()) {
      44         114 :             Application::EnableHeadlessMode(true);
      45             :         }
      46         115 :         Application::setDeInitHook(LINK(this, Protector, deinitHook));
      47         115 :     }
      48             : 
      49             : private:
      50         345 :     virtual ~Protector() {
      51         115 :         DeInitVCL();
      52         230 :     }
      53             : 
      54        8241 :     virtual bool protect(
      55             :         CppUnit::Functor const & functor, CppUnit::ProtectorContext const &)
      56             :         SAL_OVERRIDE
      57        8241 :     { return functor(); }
      58             : 
      59             :     DECL_STATIC_LINK(Protector, deinitHook, void *);
      60             : };
      61             : 
      62             : // HACK so that defaultBootstrap_InitialComponentContext (in
      63             : // unobootstrapprotector) is called before InitVCL (above), but component
      64             : // context is disposed (redundantly again in unobootstrapprotector) from within
      65             : // DeInitVCL (cf. Desktop::DeInit, desktop/source/app/app.cxx):
      66         230 : IMPL_STATIC_LINK_NOARG(Protector, deinitHook) {
      67         115 :     css::uno::Reference<css::uno::XComponentContext> context;
      68             :     try {
      69         115 :         context = comphelper::getProcessComponentContext();
      70           0 :     } catch (css::uno::RuntimeException &) {}
      71         115 :     if (context.is()) {
      72         115 :         css::uno::Reference<css::lang::XMultiServiceFactory> config;
      73             :         try {
      74         115 :             config = css::configuration::theDefaultProvider::get(context);
      75           0 :         } catch (css::uno::DeploymentException &) {}
      76         115 :         if (config.is()) {
      77         115 :             utl::ConfigManager::storeConfigItems();
      78             :             css::uno::Reference<css::util::XFlushable>(
      79         115 :                 config, css::uno::UNO_QUERY_THROW)->flush();
      80             :         }
      81             :         css::uno::Reference<css::lang::XComponent>(
      82         115 :             context, css::uno::UNO_QUERY_THROW)->dispose();
      83         115 :         comphelper::setProcessServiceFactory(0);
      84             :     }
      85         115 :     return 0;
      86             : }
      87             : 
      88             : }
      89             : 
      90             : extern "C" SAL_DLLPUBLIC_EXPORT CppUnit::Protector * SAL_CALL
      91         115 : vclbootstrapprotector() {
      92         115 :     return new Protector;
      93             : }
      94             : 
      95             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11