Branch data 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 <ucbhelper/contentbroker.hxx>
30 : : #include <comphelper/processfactory.hxx>
31 : :
32 : : #include <com/sun/star/lang/Locale.hpp>
33 : : #include <com/sun/star/lang/XComponent.hpp>
34 : : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
35 : :
36 : : #include "cppuhelper/exc_hlp.hxx"
37 : : #include "cppunit/Message.h"
38 : : #include "osl/thread.h"
39 : : #include "rtl/string.hxx"
40 : : #include "rtl/ustring.h"
41 : : #include "rtl/ustring.hxx"
42 : : #include "sal/types.h"
43 : :
44 : : #include "protectorfactory.hxx"
45 : :
46 : : namespace {
47 : :
48 : : using namespace com::sun::star;
49 : :
50 : : //cppunit calls instantiates a new TextFixture for each test and calls setUp
51 : : //and tearDown on that for every test in a fixture
52 : : //
53 : : //We basically need to call dispose on our root component context context to
54 : : //shut down cleanly in the right order.
55 : : //
56 : : //But we can't setup and tear down the root component context for
57 : : //every test because all the uno singletons will be invalid after
58 : : //the first dispose. So lets setup the default context once before
59 : : //all tests are run, and tear it down once after all have finished
60 : :
61 : : class Prot : public CppUnit::Protector, private boost::noncopyable
62 : : {
63 : : public:
64 : : Prot();
65 : :
66 : : virtual ~Prot();
67 : :
68 : : virtual bool protect(
69 : : CppUnit::Functor const & functor,
70 : : CppUnit::ProtectorContext const & context);
71 : : private:
72 : : uno::Reference<uno::XComponentContext> m_xContext;
73 : : };
74 : :
75 : :
76 : 121 : Prot::Prot()
77 : : {
78 [ + - ][ + - ]: 121 : m_xContext = cppu::defaultBootstrap_InitialComponentContext();
79 : :
80 [ + - ][ + - ]: 121 : uno::Reference<lang::XMultiComponentFactory> xFactory = m_xContext->getServiceManager();
81 [ + - ]: 121 : uno::Reference<lang::XMultiServiceFactory> xSFactory(xFactory, uno::UNO_QUERY_THROW);
82 : :
83 [ + - ]: 121 : comphelper::setProcessServiceFactory(xSFactory);
84 : 121 : }
85 : :
86 : 3015 : bool Prot::protect(
87 : : CppUnit::Functor const & functor, CppUnit::ProtectorContext const &)
88 : : {
89 : 3015 : return functor();
90 : : }
91 : :
92 : 121 : Prot::~Prot()
93 : : {
94 [ + - ][ + - ]: 121 : uno::Reference< lang::XComponent >(m_xContext, uno::UNO_QUERY_THROW)->dispose();
[ + - ]
95 [ - + ]: 242 : }
96 : :
97 : : }
98 : :
99 : 121 : extern "C" SAL_DLLPUBLIC_EXPORT CppUnit::Protector * SAL_CALL unobootstrapprotector()
100 : : {
101 [ + - ]: 121 : return new Prot;
102 [ + - ][ + - ]: 363 : }
103 : :
104 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|