1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <com/sun/star/uno/Exception.hpp>
22 #include <cppuhelper/bootstrap.hxx>
23 #include <comphelper/processfactory.hxx>
25 #include <com/sun/star/lang/XComponent.hpp>
26 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
27 #include <com/sun/star/uno/XComponentContext.hpp>
29 #include <sal/types.h>
31 #include <cppunit/Protector.h>
35 using namespace com::sun::star
;
37 //cppunit calls instantiates a new TextFixture for each test and calls setUp
38 //and tearDown on that for every test in a fixture
40 //We basically need to call dispose on our root component context to
41 //shut down cleanly in the right order.
43 //But we can't setup and tear down the root component context for
44 //every test because all the uno singletons will be invalid after
45 //the first dispose. So let's setup the default context once before
46 //all tests are run, and tear it down once after all have finished
48 class Prot
: public CppUnit::Protector
53 virtual ~Prot() override
;
55 Prot(const Prot
&) = delete;
56 Prot
& operator=(const Prot
&) = delete;
59 CppUnit::Functor
const & functor
,
60 CppUnit::ProtectorContext
const & context
) override
;
62 uno::Reference
<uno::XComponentContext
> m_xContext
;
67 : m_xContext(cppu::defaultBootstrap_InitialComponentContext())
69 uno::Reference
<lang::XMultiComponentFactory
> xFactory
= m_xContext
->getServiceManager();
70 uno::Reference
<lang::XMultiServiceFactory
> xSFactory(xFactory
, uno::UNO_QUERY_THROW
);
72 comphelper::setProcessServiceFactory(xSFactory
);
76 CppUnit::Functor
const & functor
, CppUnit::ProtectorContext
const &)
83 uno::Reference
< lang::XComponent
>(m_xContext
, uno::UNO_QUERY_THROW
)->dispose();
88 extern "C" SAL_DLLPUBLIC_EXPORT
CppUnit::Protector
* unobootstrapprotector()
93 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */