[Libreoffice-commits] .: hwpfilter/qa lotuswordpro/qa sc/qa sc/RdbTarget_sc_filters_test.mk svtools/qa sw/qa test/inc test/source writerfilter/qa

Michael Meeks michael at kemper.freedesktop.org
Wed Oct 5 08:01:46 PDT 2011


 hwpfilter/qa/cppunit/test_hwpfilter.cxx            |    9 +--
 lotuswordpro/qa/cppunit/test_lotuswordpro.cxx      |    9 ++-
 sc/RdbTarget_sc_filters_test.mk                    |    1 
 sc/qa/unit/filters-test.cxx                        |   31 ++++++++++---
 sc/qa/unit/ucalc.cxx                               |    6 ++
 svtools/qa/cppunit/filters-test.cxx                |    7 ---
 sw/qa/core/filters-test.cxx                        |    7 +--
 sw/qa/core/swdoc-test.cxx                          |   17 ++-----
 test/inc/test/bootstrapfixture.hxx                 |    8 +++
 test/inc/test/filters-test.hxx                     |    3 -
 test/source/bootstrapfixture.cxx                   |   48 +++++++++++++--------
 writerfilter/qa/cppunittests/rtftok/testrtftok.cxx |    7 ++-
 12 files changed, 95 insertions(+), 58 deletions(-)

New commits:
commit 8a0d0457a79836fa9d8ea8d4c48ecbf7bac2e95b
Author: Michael Meeks <michael.meeks at suse.com>
Date:   Wed Oct 5 16:00:44 2011 +0100

    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.

diff --git a/hwpfilter/qa/cppunit/test_hwpfilter.cxx b/hwpfilter/qa/cppunit/test_hwpfilter.cxx
index a0451ed..2e96284 100644
--- a/hwpfilter/qa/cppunit/test_hwpfilter.cxx
+++ b/hwpfilter/qa/cppunit/test_hwpfilter.cxx
@@ -40,10 +40,8 @@ namespace
     class HwpFilterTest : public test::FiltersTest
     {
     public:
-        HwpFilterTest();
-
+        virtual void setUp();
         virtual bool load(const rtl::OUString &, const rtl::OUString &rURL, const rtl::OUString &);
-
         void test();
 
         CPPUNIT_TEST_SUITE(HwpFilterTest);
@@ -53,13 +51,14 @@ namespace
         uno::Reference<document::XFilter> m_xFilter;
     };
 
-    HwpFilterTest::HwpFilterTest()
+    void HwpFilterTest::setUp()
     {
+        test::FiltersTest::setUp();
+
         m_xFilter = uno::Reference< document::XFilter >(m_xSFactory->createInstance(
             ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
                 "com.sun.comp.hwpimport.HwpImportFilter"))),
             uno::UNO_QUERY_THROW);
-
     }
 
     bool HwpFilterTest::load(const rtl::OUString &,
diff --git a/lotuswordpro/qa/cppunit/test_lotuswordpro.cxx b/lotuswordpro/qa/cppunit/test_lotuswordpro.cxx
index b68c86d..7500e25 100644
--- a/lotuswordpro/qa/cppunit/test_lotuswordpro.cxx
+++ b/lotuswordpro/qa/cppunit/test_lotuswordpro.cxx
@@ -39,7 +39,9 @@ namespace
     class LotusWordProTest : public test::FiltersTest
     {
     public:
-        LotusWordProTest();
+        LotusWordProTest() : FiltersTest(true, false) {}
+
+        virtual void setUp();
 
         virtual bool load(const rtl::OUString &,
             const rtl::OUString &rURL, const rtl::OUString &);
@@ -53,9 +55,10 @@ namespace
         uno::Reference<document::XFilter> m_xFilter;
     };
 
-    LotusWordProTest::LotusWordProTest()
-        : FiltersTest(true, false)
+    void LotusWordProTest::setUp()
     {
+        test::FiltersTest::setUp();
+
         m_xFilter = uno::Reference< document::XFilter >(m_xSFactory->createInstance(
             ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
                 "com.sun.star.comp.Writer.LotusWordProImportFilter"))),
diff --git a/sc/RdbTarget_sc_filters_test.mk b/sc/RdbTarget_sc_filters_test.mk
index a0d32bb..d6d1bc8 100644
--- a/sc/RdbTarget_sc_filters_test.mk
+++ b/sc/RdbTarget_sc_filters_test.mk
@@ -59,6 +59,7 @@ $(eval $(call gb_RdbTarget_add_old_components,sc_filters_test,\
     configmgr \
     ucb1 \
     ucpfile1 \
+    ucptdoc1 \
 ))
 
 # vim: set noet sw=4 ts=4:
diff --git a/sc/qa/unit/filters-test.cxx b/sc/qa/unit/filters-test.cxx
index bdb8997..766cb6b 100644
--- a/sc/qa/unit/filters-test.cxx
+++ b/sc/qa/unit/filters-test.cxx
@@ -39,6 +39,7 @@
 
 #include <editeng/brshitem.hxx>
 #include <editeng/justifyitem.hxx>
+#include <basic/sbxdef.hxx>
 
 #include "helper/csv_handler.hxx"
 #include "orcus/csv_parser.hpp"
@@ -55,6 +56,7 @@
 #define XLSX    2
 
 using namespace ::com::sun::star;
+using namespace ::com::sun::star::uno;
 
 namespace {
 
@@ -140,6 +142,9 @@ public:
     void createFileURL(const rtl::OUString& aFileBase, const rtl::OUString& aFileExtension, rtl::OUString& rFilePath);
     void createCSVPath(const rtl::OUString& aFileBase, rtl::OUString& rFilePath);
 
+    virtual void setUp();
+    virtual void tearDown();
+
     /**
      * Ensure CVEs remain unbroken
      */
@@ -165,6 +170,7 @@ public:
     CPPUNIT_TEST(testBugFixesODS);
     CPPUNIT_TEST(testBugFixesXLS);
     CPPUNIT_TEST(testBugFixesXLSX);
+
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -178,16 +184,16 @@ ScDocShellRef ScFiltersTest::load(const rtl::OUString &rFilter, const rtl::OUStr
     sal_uInt32 nFormat = 0;
     if (nFormatType)
         nFormat = SFX_FILTER_IMPORT | SFX_FILTER_USESOPTIONS;
-    SfxFilter aFilter(
+    SfxFilter* aFilter = new SfxFilter(
         rFilter,
         rtl::OUString(), nFormatType, nFormat, rTypeName, 0, rtl::OUString(),
         rUserData, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("private:factory/scalc*")) );
-    aFilter.SetVersion(SOFFICE_FILEFORMAT_CURRENT);
+    aFilter->SetVersion(SOFFICE_FILEFORMAT_CURRENT);
 
     ScDocShellRef xDocShRef = new ScDocShell;
-    SfxMedium aSrcMed(rURL, STREAM_STD_READ, true);
-    aSrcMed.SetFilter(&aFilter);
-    if (!xDocShRef->DoLoad(&aSrcMed))
+    SfxMedium* pSrcMed = new SfxMedium(rURL, STREAM_STD_READ, true);
+    pSrcMed->SetFilter(aFilter);
+    if (!xDocShRef->DoLoad(pSrcMed))
         // load failed.
         xDocShRef.Clear();
     else if (nFormatType)
@@ -281,6 +287,7 @@ void ScFiltersTest::testRangeName()
         CPPUNIT_ASSERT_MESSAGE("Failed to load named-ranges-globals.*", xDocSh.Is());
         ScDocument* pDoc = xDocSh->GetDocument();
         testRangeNameImpl(pDoc);
+        xDocSh->DoClose();
     }
 }
 
@@ -537,8 +544,14 @@ void ScFiltersTest::testBugFixesXLSX()
 }
 
 ScFiltersTest::ScFiltersTest()
-    : m_aBaseString(RTL_CONSTASCII_USTRINGPARAM("/sc/qa/unit/data"))
+      : m_aBaseString(RTL_CONSTASCII_USTRINGPARAM("/sc/qa/unit/data"))
+{
+}
+
+void ScFiltersTest::setUp()
 {
+    test::FiltersTest::setUp();
+
     // This is a bit of a fudge, we do this to ensure that ScGlobals::ensure,
     // which is a private symbol to us, gets called
     m_xCalcComponent =
@@ -547,6 +560,12 @@ ScFiltersTest::ScFiltersTest()
     CPPUNIT_ASSERT_MESSAGE("no calc component!", m_xCalcComponent.is());
 }
 
+void ScFiltersTest::tearDown()
+{
+    uno::Reference< lang::XComponent >( m_xCalcComponent, UNO_QUERY_THROW )->dispose();
+    test::FiltersTest::tearDown();
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(ScFiltersTest);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index aae35e3..0ccf27b 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -291,11 +291,13 @@ private:
 Test::Test()
     : m_pDoc(0)
 {
-    ScDLL::Init();
 }
 
 void Test::setUp()
 {
+    BootstrapFixture::setUp();
+
+    ScDLL::Init();
     m_xDocShRef = new ScDocShell(
         SFXMODEL_STANDARD |
         SFXMODEL_DISABLE_EMBEDDED_SCRIPTS |
@@ -307,6 +309,8 @@ void Test::setUp()
 void Test::tearDown()
 {
     m_xDocShRef.Clear();
+
+    BootstrapFixture::tearDown();
 }
 
 void Test::testCollator()
diff --git a/svtools/qa/cppunit/filters-test.cxx b/svtools/qa/cppunit/filters-test.cxx
index cb776d0..a216bc6 100644
--- a/svtools/qa/cppunit/filters-test.cxx
+++ b/svtools/qa/cppunit/filters-test.cxx
@@ -41,7 +41,7 @@ using namespace ::com::sun::star;
 class SvtoolsFiltersTest : public test::FiltersTest
 {
 public:
-    SvtoolsFiltersTest();
+    SvtoolsFiltersTest() : FiltersTest(true, false) {}
 
     virtual bool load(const rtl::OUString &, const rtl::OUString &rURL, const rtl::OUString &);
 
@@ -79,11 +79,6 @@ void SvtoolsFiltersTest::testCVEs()
         rtl::OUString());
 }
 
-SvtoolsFiltersTest::SvtoolsFiltersTest()
-    : FiltersTest(true, false)
-{
-}
-
 CPPUNIT_TEST_SUITE_REGISTRATION(SvtoolsFiltersTest);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/qa/core/filters-test.cxx b/sw/qa/core/filters-test.cxx
index b59f112..84bb4be 100644
--- a/sw/qa/core/filters-test.cxx
+++ b/sw/qa/core/filters-test.cxx
@@ -51,9 +51,8 @@ using namespace ::com::sun::star;
 class SwFiltersTest : public test::FiltersTest
 {
 public:
-    SwFiltersTest();
-
     bool load(const rtl::OUString &rFilter, const rtl::OUString &rURL, const rtl::OUString &rUserData);
+    virtual void setUp();
 
     // Ensure CVEs remain unbroken
     void testCVEs();
@@ -91,8 +90,10 @@ void SwFiltersTest::testCVEs()
             rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CWW8")));
 }
 
-SwFiltersTest::SwFiltersTest()
+void SwFiltersTest::setUp()
 {
+    test::FiltersTest::setUp();
+
     //This is a bit of a fudge, we do this to ensure that SwGlobals::ensure,
     //which is a private symbol to us, gets called
     m_xWriterComponent =
diff --git a/sw/qa/core/swdoc-test.cxx b/sw/qa/core/swdoc-test.cxx
index 992cf5b..c3ec40d 100644
--- a/sw/qa/core/swdoc-test.cxx
+++ b/sw/qa/core/swdoc-test.cxx
@@ -65,9 +65,6 @@ using namespace ::com::sun::star;
 class SwDocTest : public test::BootstrapFixture
 {
 public:
-    SwDocTest();
-    ~SwDocTest();
-
     virtual void setUp();
     virtual void tearDown();
 
@@ -441,26 +438,22 @@ void SwDocTest::randomTest()
     }
 }
 
-SwDocTest::SwDocTest()
-{
-    SwGlobals::ensure();
-}
-
 void SwDocTest::setUp()
 {
+    BootstrapFixture::setUp();
+
+    SwGlobals::ensure();
     m_pDoc = new SwDoc;
     m_xDocShRef = new SwDocShell(m_pDoc, SFX_CREATE_MODE_EMBEDDED);
     m_xDocShRef->DoInitNew(0);
 }
 
-SwDocTest::~SwDocTest()
-{
-}
-
 void SwDocTest::tearDown()
 {
     m_xDocShRef.Clear();
     delete m_pDoc;
+
+    BootstrapFixture::tearDown();
 }
 
 CPPUNIT_TEST_SUITE_REGISTRATION(SwDocTest);
diff --git a/test/inc/test/bootstrapfixture.hxx b/test/inc/test/bootstrapfixture.hxx
index 53bb39d..3c7a91f 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 ab83c55..0cc77c0 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 4b2839f..5f24697 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 )
diff --git a/writerfilter/qa/cppunittests/rtftok/testrtftok.cxx b/writerfilter/qa/cppunittests/rtftok/testrtftok.cxx
index d95728f..9a012d3 100644
--- a/writerfilter/qa/cppunittests/rtftok/testrtftok.cxx
+++ b/writerfilter/qa/cppunittests/rtftok/testrtftok.cxx
@@ -37,7 +37,8 @@ using namespace ::com::sun::star;
 class RtfTest : public test::FiltersTest
 {
 public:
-    RtfTest();
+
+    virtual void setUp();
 
     virtual bool load(const rtl::OUString &, const rtl::OUString &rURL, const rtl::OUString &);
     void test();
@@ -49,8 +50,10 @@ private:
     uno::Reference<document::XFilter> m_xFilter;
 };
 
-RtfTest::RtfTest()
+void RtfTest::setUp()
 {
+    test::FiltersTest::setUp();
+
     m_xFilter = uno::Reference< document::XFilter >(m_xSFactory->createInstance(
         ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.Writer.RtfFilter"))),
         uno::UNO_QUERY_THROW);


More information about the Libreoffice-commits mailing list