summaryrefslogtreecommitdiff
path: root/unotest/source
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2012-04-13 11:13:19 +0100
committerCaolán McNamara <caolanm@redhat.com>2012-04-13 13:15:25 +0100
commit8d7e8a0a3b9a4a4f7b805e91674b79a4cca7cf72 (patch)
treebb736d3ccaeb1732b552ae1f537c5f3ef0c41c0b /unotest/source
parent452af5f4522e750627d0c0ac9fbc794aeb1f1f8f (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/source')
-rw-r--r--unotest/source/cpp/bootstrapfixturebase.cxx26
-rw-r--r--unotest/source/cpp/unobootstrapprotector/unobootstrapprotector.cxx114
-rw-r--r--unotest/source/cpp/unoexceptionprotector/unoexceptionprotector.cxx25
3 files changed, 124 insertions, 41 deletions
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