LCOV - code coverage report
Current view: top level - unotest/source/cpp/unobootstrapprotector - unobootstrapprotector.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 14 14 100.0 %
Date: 2014-11-03 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             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <limits>
      21             : #include <string>
      22             : #include <iostream>
      23             : 
      24             : #include "boost/noncopyable.hpp"
      25             : #include "com/sun/star/uno/Any.hxx"
      26             : #include "com/sun/star/uno/Exception.hpp"
      27             : 
      28             : #include <cppuhelper/bootstrap.hxx>
      29             : #include <comphelper/processfactory.hxx>
      30             : 
      31             : #include <com/sun/star/lang/Locale.hpp>
      32             : #include <com/sun/star/lang/XComponent.hpp>
      33             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      34             : 
      35             : #include "cppuhelper/exc_hlp.hxx"
      36             : #include "cppunit/Message.h"
      37             : #include "osl/thread.h"
      38             : #include "rtl/string.hxx"
      39             : #include "rtl/ustring.h"
      40             : #include "rtl/ustring.hxx"
      41             : #include "sal/types.h"
      42             : 
      43             : #include "cppunittester/protectorfactory.hxx"
      44             : 
      45             : namespace {
      46             : 
      47             : using namespace com::sun::star;
      48             : 
      49             : //cppunit calls instantiates a new TextFixture for each test and calls setUp
      50             : //and tearDown on that for every test in a fixture
      51             : 
      52             : //We basically need to call dispose on our root component context context to
      53             : //shut down cleanly in the right order.
      54             : 
      55             : //But we can't setup and tear down the root component context for
      56             : //every test because all the uno singletons will be invalid after
      57             : //the first dispose. So lets setup the default context once before
      58             : //all tests are run, and tear it down once after all have finished
      59             : 
      60             : class Prot : public CppUnit::Protector, private boost::noncopyable
      61             : {
      62             : public:
      63             :     Prot();
      64             : 
      65             :     virtual ~Prot();
      66             : 
      67             :     virtual bool protect(
      68             :         CppUnit::Functor const & functor,
      69             :         CppUnit::ProtectorContext const & context) SAL_OVERRIDE;
      70             : private:
      71             :     uno::Reference<uno::XComponentContext> m_xContext;
      72             : };
      73             : 
      74             : 
      75         222 : Prot::Prot()
      76             : {
      77         222 :     m_xContext = cppu::defaultBootstrap_InitialComponentContext();
      78             : 
      79         222 :     uno::Reference<lang::XMultiComponentFactory> xFactory = m_xContext->getServiceManager();
      80         444 :     uno::Reference<lang::XMultiServiceFactory> xSFactory(xFactory, uno::UNO_QUERY_THROW);
      81             : 
      82         444 :     comphelper::setProcessServiceFactory(xSFactory);
      83         222 : }
      84             : 
      85       14190 : bool Prot::protect(
      86             :     CppUnit::Functor const & functor, CppUnit::ProtectorContext const &)
      87             : {
      88       14190 :     return functor();
      89             : }
      90             : 
      91         666 : Prot::~Prot()
      92             : {
      93         222 :     uno::Reference< lang::XComponent >(m_xContext, uno::UNO_QUERY_THROW)->dispose();
      94         444 : }
      95             : 
      96             : }
      97             : 
      98         222 : extern "C" SAL_DLLPUBLIC_EXPORT CppUnit::Protector * SAL_CALL unobootstrapprotector()
      99             : {
     100         222 :     return new Prot;
     101         666 : }
     102             : 
     103             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10