tdf#164434 Correct SvgSymbolNode SVG import
[LibreOffice.git] / unotest / source / cpp / unobootstrapprotector / unobootstrapprotector.cxx
blob98c5ea3cbe26bf5d67093892295722d56d897df0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
33 namespace {
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
50 public:
51 Prot();
53 virtual ~Prot() override;
55 Prot(const Prot&) = delete;
56 Prot& operator=(const Prot&) = delete;
58 virtual bool protect(
59 CppUnit::Functor const & functor,
60 CppUnit::ProtectorContext const & context) override;
61 private:
62 uno::Reference<uno::XComponentContext> m_xContext;
66 Prot::Prot()
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);
75 bool Prot::protect(
76 CppUnit::Functor const & functor, CppUnit::ProtectorContext const &)
78 return functor();
81 Prot::~Prot()
83 uno::Reference< lang::XComponent >(m_xContext, uno::UNO_QUERY_THROW)->dispose();
88 extern "C" SAL_DLLPUBLIC_EXPORT CppUnit::Protector * unobootstrapprotector()
90 return new Prot;
93 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */