diff options
author | Caolán McNamara <caolanm@redhat.com> | 2012-04-13 11:13:19 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2012-04-13 13:15:25 +0100 |
commit | 8d7e8a0a3b9a4a4f7b805e91674b79a4cca7cf72 (patch) | |
tree | bb736d3ccaeb1732b552ae1f537c5f3ef0c41c0b /unotest | |
parent | 452af5f4522e750627d0c0ac9fbc794aeb1f1f8f (diff) |
setup/teardown default component context once before/after all tests
avoids the problems of dangling uno singletons invalidated after the first
dispose and the chain of other singletons that don't expect to need to
re-initialize, etc.
reenable editeng cppunit test
inherit i18npool cppunit test from unotest base
drop LibreOfficeProtector, do "throwable" work in setUp/tearDown not
in ctors/dtors
Diffstat (limited to 'unotest')
-rw-r--r-- | unotest/Library_unobootstrapprotector.mk | 53 | ||||
-rw-r--r-- | unotest/Module_unotest.mk | 1 | ||||
-rw-r--r-- | unotest/source/cpp/bootstrapfixturebase.cxx | 26 | ||||
-rw-r--r-- | unotest/source/cpp/unobootstrapprotector/unobootstrapprotector.cxx | 114 | ||||
-rw-r--r-- | unotest/source/cpp/unoexceptionprotector/unoexceptionprotector.cxx | 25 |
5 files changed, 178 insertions, 41 deletions
diff --git a/unotest/Library_unobootstrapprotector.mk b/unotest/Library_unobootstrapprotector.mk new file mode 100644 index 000000000000..26b7a2cbf732 --- /dev/null +++ b/unotest/Library_unobootstrapprotector.mk @@ -0,0 +1,53 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +# +# Version: MPL 1.1 / GPLv3+ / LGPLv3+ +# +# The contents of this file are subject to the Mozilla Public License Version +# 1.1 (the "License"); you may not use this file except in compliance with +# the License or as specified alternatively below. You may obtain a copy of +# the License at http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License +# for the specific language governing rights and limitations under the +# License. +# +# Major Contributor(s): +# Copyright (C) 2012 Matúš Kukan <matus.kukan@gmail.com> (initial developer) +# +# All Rights Reserved. +# +# For minor contributions see the git repository. +# +# Alternatively, the contents of this file may be used under the terms of +# either the GNU General Public License Version 3 or later (the "GPLv3+"), or +# the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"), +# in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable +# instead of those above. + +$(eval $(call gb_Library_Library,unobootstrapprotector)) + +$(eval $(call gb_Library_use_package,unobootstrapprotector,unotest_inc)) + +$(eval $(call gb_Library_use_api,unobootstrapprotector,\ + udkapi \ + offapi \ +)) + +$(eval $(call gb_Library_use_libraries,unobootstrapprotector,\ + comphelper \ + cppu \ + cppuhelper \ + sal \ + $(gb_STDLIBS) \ +)) + +$(eval $(call gb_Library_use_externals,unobootstrapprotector,\ + cppunit \ +)) + +$(eval $(call gb_Library_add_exception_objects,unobootstrapprotector,\ + unotest/source/cpp/unobootstrapprotector/unobootstrapprotector \ +)) + +# vim: set noet sw=4 ts=4: diff --git a/unotest/Module_unotest.mk b/unotest/Module_unotest.mk index fc9f18cc48f8..6980b6e70a82 100644 --- a/unotest/Module_unotest.mk +++ b/unotest/Module_unotest.mk @@ -28,6 +28,7 @@ $(eval $(call gb_Module_Module,unotest)) $(eval $(call gb_Module_add_targets,unotest,\ + Library_unobootstrapprotector \ Library_unoexceptionprotector \ Library_unotest \ Package_inc \ diff --git a/unotest/source/cpp/bootstrapfixturebase.cxx b/unotest/source/cpp/bootstrapfixturebase.cxx index 0c7c841f1d99..5ce1a0611604 100644 --- a/unotest/source/cpp/bootstrapfixturebase.cxx +++ b/unotest/source/cpp/bootstrapfixturebase.cxx @@ -44,7 +44,7 @@ using namespace ::com::sun::star; // heavy lifting is deferred until setUp. setUp and tearDown are interleaved // between the tests as you might expect. test::BootstrapFixtureBase::BootstrapFixtureBase() - : m_aSrcRootURL(RTL_CONSTASCII_USTRINGPARAM("file://")), m_aSolverRootURL( m_aSrcRootURL ) + : m_aSrcRootURL("file://"), m_aSolverRootURL( m_aSrcRootURL ) { #ifndef ANDROID const char* pSrcRoot = getenv( "SRC_ROOT" ); @@ -74,46 +74,38 @@ test::BootstrapFixtureBase::~BootstrapFixtureBase() ::rtl::OUString test::BootstrapFixtureBase::getURLFromSrc( const char *pPath ) { - return m_aSrcRootURL + rtl::OUString::createFromAscii( pPath ); + return m_aSrcRootURL + rtl::OUString::createFromAscii( pPath ); } ::rtl::OUString test::BootstrapFixtureBase::getPathFromSrc( const char *pPath ) { - return m_aSrcRootPath + rtl::OUString::createFromAscii( pPath ); + return m_aSrcRootPath + rtl::OUString::createFromAscii( pPath ); } ::rtl::OUString test::BootstrapFixtureBase::getURLFromSolver( const char *pPath ) { - return m_aSolverRootURL + rtl::OUString::createFromAscii( pPath ); + return m_aSolverRootURL + rtl::OUString::createFromAscii( pPath ); } ::rtl::OUString test::BootstrapFixtureBase::getPathFromSolver( const char *pPath ) { - return m_aSolverRootPath + rtl::OUString::createFromAscii( pPath ); + return m_aSolverRootPath + rtl::OUString::createFromAscii( pPath ); } void test::BootstrapFixtureBase::setUp() { // set UserInstallation to user profile dir in test/user-template rtl::Bootstrap aDefaultVars; - rtl::OUString sUserInstallURL = m_aSolverRootURL + rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/unittest" ) ); - aDefaultVars.set( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("UserInstallation") ), - sUserInstallURL); + rtl::OUString sUserInstallURL = m_aSolverRootURL + rtl::OUString("/unittest"); + aDefaultVars.set(rtl::OUString("UserInstallation"), sUserInstallURL); - m_xContext = cppu::defaultBootstrap_InitialComponentContext(); + m_xContext = comphelper::getProcessComponentContext(); m_xFactory = m_xContext->getServiceManager(); - m_xSFactory = uno::Reference<lang::XMultiServiceFactory> (m_xFactory, uno::UNO_QUERY_THROW); - - // Without this we're crashing because callees are using - // getProcessServiceFactory. In general those should be removed in favour - // of retaining references to the root ServiceFactory as its passed around - comphelper::setProcessServiceFactory(m_xSFactory); + m_xSFactory = uno::Reference<lang::XMultiServiceFactory>(m_xFactory, uno::UNO_QUERY_THROW); } void test::BootstrapFixtureBase::tearDown() { - // uno::Reference< lang::XComponent >(m_xContext, uno::UNO_QUERY_THROW)->dispose(); } - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/unotest/source/cpp/unobootstrapprotector/unobootstrapprotector.cxx b/unotest/source/cpp/unobootstrapprotector/unobootstrapprotector.cxx new file mode 100644 index 000000000000..cb0983a08b40 --- /dev/null +++ b/unotest/source/cpp/unobootstrapprotector/unobootstrapprotector.cxx @@ -0,0 +1,114 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* Copyright 2000, 2011 Oracle and/or its affiliates. +* +* OpenOffice.org - a multi-platform office productivity suite +* +* This file is part of OpenOffice.org. +* +* OpenOffice.org is free software: you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License version 3 +* only, as published by the Free Software Foundation. +* +* OpenOffice.org is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License version 3 for more details +* (a copy is included in the LICENSE file that accompanied this code). +* +* You should have received a copy of the GNU Lesser General Public License +* version 3 along with OpenOffice.org. If not, see +* <http://www.openoffice.org/license.html> +* for a copy of the LGPLv3 License. +************************************************************************/ + +#include "sal/config.h" +#include "sal/precppunit.hxx" + +#include <limits> +#include <string> +#include <iostream> + +#include "boost/noncopyable.hpp" +#include "com/sun/star/uno/Any.hxx" +#include "com/sun/star/uno/Exception.hpp" + +#include <cppuhelper/bootstrap.hxx> +#include <ucbhelper/contentbroker.hxx> +#include <comphelper/processfactory.hxx> + +#include <com/sun/star/lang/Locale.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> + +#include "cppuhelper/exc_hlp.hxx" +#include "cppunit/Message.h" +#include "osl/thread.h" +#include "rtl/string.hxx" +#include "rtl/ustring.h" +#include "rtl/ustring.hxx" +#include "sal/types.h" + +#include "protectorfactory.hxx" + +namespace { + +using namespace com::sun::star; + +//cppunit calls instantiates a new TextFixture for each test and calls setUp +//and tearDown on that for every test in a fixture +// +//We basically need to call dispose on our root component context context to +//shut down cleanly in the right order. +// +//But we can't setup and tear down the root component context for +//every test because all the uno singletons will be invalid after +//the first dispose. So lets setup the default context once before +//all tests are run, and tear it down once after all have finished + +class Prot : public CppUnit::Protector, private boost::noncopyable +{ +public: + Prot(); + + virtual ~Prot(); + + virtual bool protect( + CppUnit::Functor const & functor, + CppUnit::ProtectorContext const & context); +private: + uno::Reference<uno::XComponentContext> m_xContext; +}; + + +Prot::Prot() +{ + m_xContext = cppu::defaultBootstrap_InitialComponentContext(); + + uno::Reference<lang::XMultiComponentFactory> xFactory = m_xContext->getServiceManager(); + uno::Reference<lang::XMultiServiceFactory> xSFactory(xFactory, uno::UNO_QUERY_THROW); + + comphelper::setProcessServiceFactory(xSFactory); +} + +bool Prot::protect( + CppUnit::Functor const & functor, CppUnit::ProtectorContext const &) +{ + return functor(); +} + +Prot::~Prot() +{ + uno::Reference< lang::XComponent >(m_xContext, uno::UNO_QUERY_THROW)->dispose(); +} + +} + +extern "C" SAL_DLLPUBLIC_EXPORT CppUnit::Protector * SAL_CALL unobootstrapprotector() +{ + return new Prot; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/unotest/source/cpp/unoexceptionprotector/unoexceptionprotector.cxx b/unotest/source/cpp/unoexceptionprotector/unoexceptionprotector.cxx index 3829bd1b3b6e..6f1f6795edcf 100644 --- a/unotest/source/cpp/unoexceptionprotector/unoexceptionprotector.cxx +++ b/unotest/source/cpp/unoexceptionprotector/unoexceptionprotector.cxx @@ -59,7 +59,7 @@ std::string convert(rtl::OUString const & s16) { : static_cast< std::string::size_type >(s8.getLength()))); } -class Prot : public cppunittester::LibreOfficeProtector, private boost::noncopyable +class Prot : public CppUnit::Protector, private boost::noncopyable { public: Prot() {} @@ -69,8 +69,6 @@ public: virtual bool protect( CppUnit::Functor const & functor, CppUnit::ProtectorContext const & context); - - virtual bool protect(CppUnit::Functor const & functor); }; bool Prot::protect( @@ -93,27 +91,6 @@ bool Prot::protect( return false; } -bool Prot::protect(CppUnit::Functor const & functor) -{ - bool bRet = false; - try - { - bRet = functor(); - } catch (const css::uno::Exception &e) - { - css::uno::Any a(cppu::getCaughtException()); - std::cerr - << convert(rtl::OUString( - RTL_CONSTASCII_USTRINGPARAM( - "An uncaught exception of type ")) - + a.getValueTypeName()) - << std::endl << "Exception Message was: " << convert(e.Message) - << std::endl; - throw; - } - return bRet; -} - } extern "C" SAL_DLLPUBLIC_EXPORT CppUnit::Protector * SAL_CALL |