Kaydet (Commit) 8d7e8a0a authored tarafından Caolán McNamara's avatar Caolán McNamara

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
üst 452af5f4
......@@ -406,6 +406,7 @@ $(eval $(call gb_Helper_register_libraries,PLAINLIBS_OOO, \
ucpchelp1 \
ucphier1 \
ucppkg1 \
unobootstrapprotector \
unoexceptionprotector \
unopkgapp \
unotest \
......
......@@ -41,6 +41,7 @@ gb_Library_FILENAMES := $(patsubst purpenvhelper:libpurpen%,purpenvhelper:libuno
gb_Library_FILENAMES := $(patsubst salhelper:libsalhelper%,salhelper:libuno_salhelper%,$(gb_Library_FILENAMES))
gb_Library_FILENAMES := $(patsubst ucbhelper:libucbhelper%,ucbhelper:libucbhelper4%,$(gb_Library_FILENAMES))
ifneq ($(OS),ANDROID)
gb_Library_FILENAMES := $(patsubst unobootstrapprotector:libuno%,unobootstrapprotector:uno%,$(gb_Library_FILENAMES))
gb_Library_FILENAMES := $(patsubst unoexceptionprotector:libuno%,unoexceptionprotector:uno%,$(gb_Library_FILENAMES))
endif
gb_Library_FILENAMES := $(patsubst unsafe_uno:libunsafe_uno%,unsafe_uno:libunsafe_uno_uno%,$(gb_Library_FILENAMES))
......
......@@ -55,7 +55,7 @@ public:
void testConstruction();
CPPUNIT_TEST_SUITE(Test);
// CPPUNIT_TEST(testConstruction);
CPPUNIT_TEST(testConstruction);
CPPUNIT_TEST_SUITE_END();
private:
......
......@@ -37,6 +37,7 @@ $(eval $(call gb_CppunitTest_use_libraries,i18npool_test_breakiterator,\
cppu \
cppuhelper \
sal \
unotest \
$(gb_STDLIBS) \
))
......
......@@ -35,14 +35,11 @@
#include <cppuhelper/compbase1.hxx>
#include <cppuhelper/bootstrap.hxx>
#include <cppuhelper/basemutex.hxx>
#include "cppunit/TestAssert.h"
#include "cppunit/TestFixture.h"
#include "cppunit/extensions/HelperMacros.h"
#include "cppunit/plugin/TestPlugIn.h"
#include <com/sun/star/i18n/XBreakIterator.hpp>
#include <com/sun/star/i18n/CharacterIteratorMode.hpp>
#include <com/sun/star/i18n/ScriptType.hpp>
#include <com/sun/star/i18n/WordType.hpp>
#include <unotest/bootstrapfixturebase.hxx>
#include <rtl/strbuf.hxx>
......@@ -50,12 +47,9 @@
using namespace ::com::sun::star;
class TestBreakIterator : public CppUnit::TestFixture
class TestBreakIterator : public test::BootstrapFixtureBase
{
public:
TestBreakIterator();
~TestBreakIterator();
virtual void setUp();
virtual void tearDown();
......@@ -72,11 +66,7 @@ public:
CPPUNIT_TEST(testAsian);
CPPUNIT_TEST(testThai);
CPPUNIT_TEST_SUITE_END();
private:
uno::Reference<uno::XComponentContext> m_xContext;
uno::Reference<lang::XMultiComponentFactory> m_xFactory;
uno::Reference<lang::XMultiServiceFactory> m_xMSF;
uno::Reference<i18n::XBreakIterator> m_xBreak;
};
......@@ -327,27 +317,17 @@ void TestBreakIterator::testThai()
#endif
}
TestBreakIterator::TestBreakIterator()
{
m_xContext = cppu::defaultBootstrap_InitialComponentContext();
m_xFactory = m_xContext->getServiceManager();
m_xMSF = uno::Reference<lang::XMultiServiceFactory>(m_xFactory, uno::UNO_QUERY_THROW);
m_xBreak = uno::Reference< i18n::XBreakIterator >(m_xMSF->createInstance(
::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.i18n.BreakIterator"))),
uno::UNO_QUERY_THROW);
}
void TestBreakIterator::setUp()
{
}
TestBreakIterator::~TestBreakIterator()
{
uno::Reference< lang::XComponent >(m_xContext, uno::UNO_QUERY_THROW)->dispose();
BootstrapFixtureBase::setUp();
m_xBreak = uno::Reference< i18n::XBreakIterator >(m_xSFactory->createInstance(
"com.sun.star.i18n.BreakIterator"), uno::UNO_QUERY_THROW);
}
void TestBreakIterator::tearDown()
{
BootstrapFixtureBase::tearDown();
m_xBreak.clear();
}
CPPUNIT_TEST_SUITE_REGISTRATION(TestBreakIterator);
......
......@@ -180,7 +180,7 @@ SAL_IMPLEMENT_MAIN() {
#endif
boost::ptr_vector<osl::Module> modules;
cppunittester::LibreOfficeProtector *throw_protector = 0;
CppUnit::Protector *throw_protector = 0;
CppUnit::TestResult result;
std::string args;
std::string testlib;
......@@ -231,14 +231,8 @@ SAL_IMPLEMENT_MAIN() {
index+=3;
}
bool ok = false;
ProtectedFixtureFunctor tests(testlib, args, result);
//if the unoprotector was given on the command line, use it to catch
//and report the error message of exceptions
if (throw_protector)
ok = throw_protector->protect(tests);
else
ok = tests.run();
bool ok = tests.run();
return ok ? EXIT_SUCCESS : EXIT_FAILURE;
}
......
......@@ -38,16 +38,9 @@
namespace cppunittester
{
class LibreOfficeProtector : public CppUnit::Protector
{
public:
virtual bool protect(CppUnit::Functor const & functor) = 0;
using CppUnit::Protector::protect;
};
// The type of CppUnit::Protector factory functions that can be plugged into
// cppunittester:
extern "C" typedef LibreOfficeProtector * SAL_CALL ProtectorFactory();
extern "C" typedef CppUnit::Protector * SAL_CALL ProtectorFactory();
}
#ifdef DISABLE_DYNLOADING
......
......@@ -68,8 +68,9 @@ $(if $(URE),\
"-env:UNO_SERVICES=$(foreach item,$(UNO_SERVICES),$(call gb_Helper_make_url,$(item)))") \
$(foreach dir,URE_INTERNAL_LIB_DIR LO_LIB_DIR,\
-env:$(dir)=$(call gb_Helper_make_url,$(gb_CppunitTest_LIBDIR))) \
--protector unoexceptionprotector$(gb_Library_DLLEXT) unoexceptionprotector) \
$(ARGS)
--protector unoexceptionprotector$(gb_Library_DLLEXT) unoexceptionprotector \
--protector unobootstrapprotector$(gb_Library_DLLEXT) unobootstrapprotector \
) $(ARGS)
endef
.PHONY : $(call gb_CppunitTest_get_clean_target,%)
......
......@@ -62,6 +62,12 @@ test::BootstrapFixture::BootstrapFixture( bool bAssertOnDialog, bool bNeedUCB )
: m_bNeedUCB( bNeedUCB )
, m_bAssertOnDialog( bAssertOnDialog )
{
}
void test::BootstrapFixture::setUp()
{
test::BootstrapFixtureBase::setUp();
// force locale (and resource files loaded) to en-US
const LanguageType eLang=LANGUAGE_ENGLISH_US;
......@@ -69,11 +75,7 @@ test::BootstrapFixture::BootstrapFixture( bool bAssertOnDialog, bool bNeedUCB )
MsLangId::convertLanguageToIsoNames(eLang, aLang, aCountry);
lang::Locale aLocale(aLang, aCountry, rtl::OUString());
ResMgr::SetDefaultLocale( aLocale );
}
void test::BootstrapFixture::setUp()
{
test::BootstrapFixtureBase::setUp();
if (m_bNeedUCB)
{
// initialise UCB-Broker
......@@ -96,9 +98,8 @@ void test::BootstrapFixture::setUp()
aLocalOptions.SetUILocaleConfigString( aLangISO );
InitVCL(m_xSFactory);
if (Application::IsHeadlessModeRequested()) {
if (Application::IsHeadlessModeRequested())
Application::EnableHeadlessMode(true);
}
if( m_bAssertOnDialog )
ErrorHandler::RegisterDisplay( aBasicErrorFunc );
......
tl tools : cppu external offapi ZLIB:zlib EXPAT:expat basegfx comphelper i18npool unotest NULL
tl tools : cppu external offapi ZLIB:zlib EXPAT:expat basegfx comphelper i18npool NULL
tl tools\prj nmake - all tl_prj NULL
# tl tools\qa nmake - all tl_qa tl_utl NULL
# -*- 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:
......@@ -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 \
......
......@@ -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: */
/* -*- 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: */
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment