diff options
author | Michael Meeks <michael.meeks@suse.com> | 2011-10-05 16:00:44 +0100 |
---|---|---|
committer | Michael Meeks <michael.meeks@suse.com> | 2011-10-05 16:02:28 +0100 |
commit | 8a0d0457a79836fa9d8ea8d4c48ecbf7bac2e95b (patch) | |
tree | 242935d062542ef2993a4e0bc3aeb3f188bef1a4 /test | |
parent | 9767483eea7800aadd18b4489069ad633ce7a79c (diff) |
test fix: use setUp and tearDown not constructors to init LibreOffice
It turns out the constructors are all run back-to-back one per filter,
and we need to init and de-init in a sensible order to make multiple
tests that otherwise share the ContentBroker work properly.
Diffstat (limited to 'test')
-rw-r--r-- | test/inc/test/bootstrapfixture.hxx | 8 | ||||
-rw-r--r-- | test/inc/test/filters-test.hxx | 3 | ||||
-rw-r--r-- | test/source/bootstrapfixture.cxx | 48 |
3 files changed, 39 insertions, 20 deletions
diff --git a/test/inc/test/bootstrapfixture.hxx b/test/inc/test/bootstrapfixture.hxx index 53bb39dde0e3..3c7a91f4180e 100644 --- a/test/inc/test/bootstrapfixture.hxx +++ b/test/inc/test/bootstrapfixture.hxx @@ -48,8 +48,13 @@ namespace test { // bootstrapping for unit tests, such that we can use // almost an entire LibreOffice during compile - so // that we can get pieces of code alone to beat them up. + +// NB. this class is instantiated multiple times during a +// run of unit tests ... class OOO_DLLPUBLIC_TEST BootstrapFixture : public CppUnit::TestFixture { + bool m_bNeedUCB; + bool m_bAssertOnDialog; ::rtl::OUString m_aSrcRootURL; ::rtl::OUString m_aSrcRootPath; @@ -73,6 +78,9 @@ public: // return a URL to a given c-str path from the source directory ::rtl::OUString getURLFromSrc( const char *pPath ); + + virtual void setUp(); + virtual void tearDown(); }; } diff --git a/test/inc/test/filters-test.hxx b/test/inc/test/filters-test.hxx index ab83c55e8f10..0cc77c09f4f4 100644 --- a/test/inc/test/filters-test.hxx +++ b/test/inc/test/filters-test.hxx @@ -54,9 +54,6 @@ public: : BootstrapFixture(bAssertOnDialog, bNeedUCB) {} - virtual void setUp() {} - virtual void tearDown() {} - void testDir( //filter name const rtl::OUString &rFilter, diff --git a/test/source/bootstrapfixture.cxx b/test/source/bootstrapfixture.cxx index 4b2839fe6832..5f246979e8ec 100644 --- a/test/source/bootstrapfixture.cxx +++ b/test/source/bootstrapfixture.cxx @@ -54,8 +54,14 @@ static void aBasicErrorFunc( const String &rErr, const String &rAction ) CPPUNIT_ASSERT_MESSAGE( aErr.getStr(), false); } +// NB. this constructor is called before any tests are run, once for each +// test function in a rather non-intuitive way. This is why all the 'real' +// heavy lifting is deferred until setUp. setUp and tearDown are interleaved +// between the tests as you might expect. test::BootstrapFixture::BootstrapFixture( bool bAssertOnDialog, bool bNeedUCB ) - : m_aSrcRootURL(RTL_CONSTASCII_USTRINGPARAM("file://")) + : m_bNeedUCB( bNeedUCB ) + , m_bAssertOnDialog( bAssertOnDialog ) + , m_aSrcRootURL(RTL_CONSTASCII_USTRINGPARAM("file://")) { const char* pSrcRoot = getenv( "SRC_ROOT" ); CPPUNIT_ASSERT_MESSAGE("SRC_ROOT env variable not set", pSrcRoot != NULL && pSrcRoot[0] != 0); @@ -67,7 +73,18 @@ test::BootstrapFixture::BootstrapFixture( bool bAssertOnDialog, bool bNeedUCB ) m_aSrcRootPath = rtl::OUString::createFromAscii( pSrcRoot ); m_aSrcRootURL += m_aSrcRootPath; - //set UserInstallation to user profile dir in test/user-template + // force locale (and resource files loaded) to en-US + const LanguageType eLang=LANGUAGE_ENGLISH_US; + + rtl::OUString aLang, aCountry; + MsLangId::convertLanguageToIsoNames(eLang, aLang, aCountry); + lang::Locale aLocale(aLang, aCountry, rtl::OUString()); + ResMgr::SetDefaultLocale( aLocale ); +} + +void test::BootstrapFixture::setUp() +{ + // set UserInstallation to user profile dir in test/user-template rtl::Bootstrap aDefaultVars; aDefaultVars.set( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("UserInstallation") ), getURLFromSrc("/test/user-template")); @@ -76,12 +93,12 @@ test::BootstrapFixture::BootstrapFixture( bool bAssertOnDialog, bool bNeedUCB ) 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 + // 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); - if (bNeedUCB) + if (m_bNeedUCB) { // initialise UCB-Broker uno::Sequence<uno::Any> aUcbInitSequence(2); @@ -97,28 +114,25 @@ test::BootstrapFixture::BootstrapFixture( bool bAssertOnDialog, bool bNeedUCB ) xUcb->registerContentProvider(xFileProvider, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("file")), sal_True); } - // force locale (and resource files loaded) to en-US - const LanguageType eLang=LANGUAGE_ENGLISH_US; - - rtl::OUString aLang, aCountry; - MsLangId::convertLanguageToIsoNames(eLang, aLang, aCountry); - lang::Locale aLocale(aLang, aCountry, rtl::OUString()); - ResMgr::SetDefaultLocale( aLocale ); - SvtSysLocaleOptions aLocalOptions; - rtl::OUString aLangISO = MsLangId::convertLanguageToIsoString( eLang ); + rtl::OUString aLangISO = MsLangId::convertLanguageToIsoString( LANGUAGE_ENGLISH_US ); aLocalOptions.SetLocaleConfigString( aLangISO ); aLocalOptions.SetUILocaleConfigString( aLangISO ); InitVCL(m_xSFactory); - if( bAssertOnDialog ) + if( m_bAssertOnDialog ) ErrorHandler::RegisterDisplay( aBasicErrorFunc ); } +void test::BootstrapFixture::tearDown() +{ + ucbhelper::ContentBroker::get()->deinitialize(); + // uno::Reference< lang::XComponent >(m_xContext, uno::UNO_QUERY_THROW)->dispose(); +} + test::BootstrapFixture::~BootstrapFixture() { - uno::Reference< lang::XComponent >(m_xContext, uno::UNO_QUERY_THROW)->dispose(); } ::rtl::OUString test::BootstrapFixture::getURLFromSrc( const char *pPath ) |