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 .
24 #include "boost/noncopyable.hpp"
25 #include "com/sun/star/uno/Any.hxx"
26 #include "com/sun/star/uno/Exception.hpp"
28 #include <cppuhelper/bootstrap.hxx>
29 #include <comphelper/processfactory.hxx>
31 #include <com/sun/star/lang/Locale.hpp>
32 #include <com/sun/star/lang/XComponent.hpp>
33 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
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"
43 #include "cppunittester/protectorfactory.hxx"
47 using namespace com::sun::star
;
49 //cppunit calls instantiates a new TextFixture for each test and calls setUp
50 //and tearDown on that for every test in a fixture
52 //We basically need to call dispose on our root component context context to
53 //shut down cleanly in the right order.
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
60 class Prot
: public CppUnit::Protector
, private boost::noncopyable
68 CppUnit::Functor
const & functor
,
69 CppUnit::ProtectorContext
const & context
) SAL_OVERRIDE
;
71 uno::Reference
<uno::XComponentContext
> m_xContext
;
77 m_xContext
= cppu::defaultBootstrap_InitialComponentContext();
79 uno::Reference
<lang::XMultiComponentFactory
> xFactory
= m_xContext
->getServiceManager();
80 uno::Reference
<lang::XMultiServiceFactory
> xSFactory(xFactory
, uno::UNO_QUERY_THROW
);
82 comphelper::setProcessServiceFactory(xSFactory
);
86 CppUnit::Functor
const & functor
, CppUnit::ProtectorContext
const &)
93 uno::Reference
< lang::XComponent
>(m_xContext
, uno::UNO_QUERY_THROW
)->dispose();
98 extern "C" SAL_DLLPUBLIC_EXPORT
CppUnit::Protector
* SAL_CALL
unobootstrapprotector()
103 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */