[Libreoffice-commits] .: 3 commits - dbaccess/CppunitTest_dbaccess_macros_test.mk dbaccess/qa sc/qa

Markus Mohrhard mmohrhard at kemper.freedesktop.org
Sat Feb 11 08:26:01 PST 2012


 dbaccess/CppunitTest_dbaccess_macros_test.mk |  140 +++++++++++
 dbaccess/qa/extras/macros-test.cxx           |  114 +++++++++
 dbaccess/qa/extras/testdocuments/testdb.odb  |binary
 sc/qa/unit/filters-test.cxx                  |  107 +++++---
 sc/qa/unit/subsequent_filters-test.cxx       |  325 +++++++++++++++------------
 5 files changed, 498 insertions(+), 188 deletions(-)

New commits:
commit 0f4451c0b3bda3d14c7672ca670b4de959495365
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Sat Feb 11 17:20:03 2012 +0100

    first part of a c++ based test for base

diff --git a/dbaccess/CppunitTest_dbaccess_macros_test.mk b/dbaccess/CppunitTest_dbaccess_macros_test.mk
new file mode 100644
index 0000000..028be5e
--- /dev/null
+++ b/dbaccess/CppunitTest_dbaccess_macros_test.mk
@@ -0,0 +1,140 @@
+# -*- 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) 2011 Red Hat, Inc., Caolán McNamara <caolanm at redhat.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_CppunitTest_CppunitTest,dbaccess_macros_test))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,dbaccess_macros_test, \
+    dbaccess/qa/extras/macros-test \
+))
+
+$(eval $(call gb_CppunitTest_add_linked_libs,dbaccess_macros_test, \
+    avmedia \
+    basegfx \
+    comphelper \
+    cppu \
+    cppuhelper \
+    dba \
+    dbu \
+    dbu \
+    sdbt \
+    drawinglayer \
+    editeng \
+    fileacc \
+    for \
+    forui \
+    i18nisolang1 \
+    msfilter \
+    oox \
+    sal \
+    salhelper \
+    sax \
+    sb \
+    sfx \
+    sot \
+    svl \
+    svt \
+    svx \
+    svxcore \
+	test \
+    tl \
+    tk \
+    ucbhelper \
+	unotest \
+    utl \
+    vbahelper \
+    vcl \
+    xo \
+	$(gb_STDLIBS) \
+))
+
+$(eval $(call gb_CppunitTest_set_include,dbaccess_macros_test,\
+    -I$(realpath $(SRCDIR)/sc/source/ui/inc) \
+    -I$(realpath $(SRCDIR)/sc/inc) \
+    $$(INCLUDE) \
+))
+
+$(eval $(call gb_CppunitTest_add_api,dbaccess_macros_test,\
+    offapi \
+    oovbaapi \
+    udkapi \
+))
+
+$(eval $(call gb_CppunitTest_uses_ure,dbaccess_macros_test))
+
+$(eval $(call gb_CppunitTest_add_type_rdbs,dbaccess_macros_test,\
+    oovbaapi \
+    types \
+))
+
+$(eval $(call gb_CppunitTest_add_components,dbaccess_macros_test,\
+    basic/util/sb \
+    comphelper/util/comphelp \
+    configmgr/source/configmgr \
+    dbaccess/util/dba \
+    dbaccess/util/dbu \
+    dbaccess/util/sdbt \
+    dbaccess/source/filter/xml/dbaxml \
+    fileaccess/source/fileacc \
+    filter/source/config/cache/filterconfig1 \
+    forms/util/frm \
+    framework/util/fwk \
+    i18npool/util/i18npool \
+    oox/util/oox \
+    package/source/xstor/xstor \
+    package/util/package2 \
+    sax/source/expatwrap/expwrap \
+    sax/source/fastparser/fastsax \
+    scripting/source/basprov/basprov \
+    scripting/util/scriptframe \
+    sfx2/util/sfx \
+    sot/util/sot \
+    svl/source/fsstor/fsstorage \
+    toolkit/util/tk \
+    ucb/source/core/ucb1 \
+    ucb/source/ucp/file/ucpfile1 \
+    ucb/source/ucp/tdoc/ucptdoc1 \
+    unotools/util/utl \
+    unoxml/source/rdf/unordf \
+    unoxml/source/service/unoxml \
+))
+
+$(eval $(call gb_CppunitTest_set_args,dbaccess_macros_test,\
+    --headless \
+    --protector unoexceptionprotector$(gb_Library_DLLEXT) unoexceptionprotector \
+    "-env:CONFIGURATION_LAYERS=xcsxcu:$(call gb_CppunitTarget__make_url,$(OUTDIR)/xml/registry) module:$(call gb_CppunitTarget__make_url,$(OUTDIR)/xml/registry/spool) xcsxcu:$(call gb_CppunitTarget__make_url,$(OUTDIR)/unittest/registry)" \
+))
+    # .../spool is required for the (somewhat strange) filter configuration
+
+# we need to
+# a) explicitly depend on library msword because it is not implied by a link
+#    relation
+# b) explicitly depend on the sc resource files needed at unit-test runtime
+$(call gb_CppunitTest_get_target,dbaccess_macros_test) : \
+    $(WORKDIR)/AllLangRes/dbaccess \
+    $(call gb_Library_get_target,localedata_en) \
+
+# vim: set noet sw=4 ts=4:
diff --git a/dbaccess/qa/extras/macros-test.cxx b/dbaccess/qa/extras/macros-test.cxx
new file mode 100644
index 0000000..9443e9e
--- /dev/null
+++ b/dbaccess/qa/extras/macros-test.cxx
@@ -0,0 +1,114 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * 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) 2010 Red Hat, Inc., Caolán McNamara <caolanm at redhat.com>
+ *  (initial developer)
+ * Copyright (C) 2011 Markus Mohrhard <markus.mohrhard at googlemail.com>
+ *
+ * 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.
+ */
+
+#include <sal/config.h>
+#include <test/bootstrapfixture.hxx>
+#include <unotest/macros_test.hxx>
+#include <rtl/strbuf.hxx>
+#include <osl/file.hxx>
+
+#include <sfx2/app.hxx>
+#include <sfx2/docfilt.hxx>
+#include <sfx2/docfile.hxx>
+#include <sfx2/sfxmodelfactory.hxx>
+#include <svl/intitem.hxx>
+
+#include <basic/sbxdef.hxx>
+
+using namespace ::com::sun::star;
+using namespace ::com::sun::star::uno;
+
+
+class DBAccessTest : public test::BootstrapFixture, public unotest::MacrosTest
+{
+public:
+    DBAccessTest();
+
+    void createFileURL(const rtl::OUString& aFileBase, const rtl::OUString& aFileExtension, rtl::OUString& rFilePath);
+
+    virtual void setUp();
+    virtual void tearDown();
+
+    void test();
+
+    CPPUNIT_TEST_SUITE(DBAccessTest);
+    CPPUNIT_TEST(test);
+    CPPUNIT_TEST_SUITE_END();
+
+private:
+    rtl::OUString m_aBaseString;
+};
+
+
+void DBAccessTest::createFileURL(const rtl::OUString& aFileBase, const rtl::OUString& aFileExtension, rtl::OUString& rFilePath)
+{
+    rtl::OUString aSep(RTL_CONSTASCII_USTRINGPARAM("/"));
+    rtl::OUStringBuffer aBuffer( getSrcRootURL() );
+    aBuffer.append(m_aBaseString);
+    aBuffer.append(aSep).append(aFileBase).append(aFileExtension);
+    rFilePath = aBuffer.makeStringAndClear();
+}
+
+DBAccessTest::DBAccessTest()
+      : m_aBaseString(RTL_CONSTASCII_USTRINGPARAM("/dbaccess/qa/extras/testdocuments"))
+{
+}
+
+void DBAccessTest::test()
+{
+    const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("testdb."));
+    const rtl::OUString aFileExtension(RTL_CONSTASCII_USTRINGPARAM("odb"));
+    rtl::OUString aFileName;
+    createFileURL(aFileNameBase, aFileExtension, aFileName);
+    uno::Reference< lang::XComponent > xComponent = loadFromDesktop(aFileName);
+    CPPUNIT_ASSERT(xComponent.is());
+}
+
+void DBAccessTest::setUp()
+{
+    test::BootstrapFixture::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
+    mxDesktop = Reference<com::sun::star::frame::XDesktop>( getMultiServiceFactory()->createInstance(
+                rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.Desktop" ))), UNO_QUERY );
+    CPPUNIT_ASSERT_MESSAGE("", mxDesktop.is());
+}
+
+void DBAccessTest::tearDown()
+{
+    test::BootstrapFixture::tearDown();
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(DBAccessTest);
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/dbaccess/qa/extras/testdocuments/testdb.odb b/dbaccess/qa/extras/testdocuments/testdb.odb
new file mode 100644
index 0000000..038e998
Binary files /dev/null and b/dbaccess/qa/extras/testdocuments/testdb.odb differ
commit 8fab50dcb2e4a011e4a68c5eaa20e06787af26ad
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Sat Feb 11 15:23:26 2012 +0100

    refactor subsequent_filters-test and move each test into own method

diff --git a/sc/qa/unit/subsequent_filters-test.cxx b/sc/qa/unit/subsequent_filters-test.cxx
index 374041e..af0b159 100644
--- a/sc/qa/unit/subsequent_filters-test.cxx
+++ b/sc/qa/unit/subsequent_filters-test.cxx
@@ -92,11 +92,15 @@ public:
     virtual void tearDown();
 
     //ods, xls, xlsx filter tests
-    void testRangeName();
-    void testFunctions();
-    void testDatabaseRanges();
-    void testFormats();
-    void testMatrix();
+    void testRangeNameXLS();
+    void testRangeNameXLSX();
+    void testFunctionsODS();
+    void testDatabaseRangesODS();
+    void testFormatsODS();
+    void testFormatsXLS();
+    void testFormatsXLSX();
+    void testMatrixODS();
+    void testMatrixXLS();
     void testBugFixesODS();
     void testBugFixesXLS();
     void testBugFixesXLSX();
@@ -105,11 +109,15 @@ public:
     void testPassword();
 
     CPPUNIT_TEST_SUITE(ScFiltersTest);
-    CPPUNIT_TEST(testRangeName);
-    CPPUNIT_TEST(testFunctions);
-    CPPUNIT_TEST(testDatabaseRanges);
-    CPPUNIT_TEST(testFormats);
-    CPPUNIT_TEST(testMatrix);
+    CPPUNIT_TEST(testRangeNameXLS);
+    CPPUNIT_TEST(testRangeNameXLSX);
+    CPPUNIT_TEST(testFunctionsODS);
+    CPPUNIT_TEST(testDatabaseRangesODS);
+    CPPUNIT_TEST(testFormatsODS);
+    CPPUNIT_TEST(testFormatsXLS);
+    CPPUNIT_TEST(testFormatsXLSX);
+    CPPUNIT_TEST(testMatrixODS);
+    CPPUNIT_TEST(testMatrixXLS);
     CPPUNIT_TEST(testBugFixesODS);
     CPPUNIT_TEST(testBugFixesXLS);
     CPPUNIT_TEST(testBugFixesXLSX);
@@ -127,6 +135,8 @@ public:
     CPPUNIT_TEST_SUITE_END();
 
 private:
+    ScDocShellRef loadDoc(const rtl::OUString& rName, sal_Int32 nType);
+
     uno::Reference<uno::XInterface> m_xCalcComponent;
     ::rtl::OUString m_aBaseString;
 };
@@ -167,6 +177,18 @@ bool ScFiltersTest::load(const rtl::OUString &rFilter, const rtl::OUString &rURL
     return bLoaded;
 }
 
+ScDocShellRef ScFiltersTest::loadDoc(const rtl::OUString& rName, sal_Int32 nFormat)
+{
+    rtl::OUString aFileExtension(aFileFormats[nFormat].pName, strlen(aFileFormats[nFormat].pName), RTL_TEXTENCODING_UTF8 );
+    rtl::OUString aFilterName(aFileFormats[nFormat].pFilterName, strlen(aFileFormats[nFormat].pFilterName), RTL_TEXTENCODING_UTF8) ;
+    rtl::OUString aFileName;
+    createFileURL( rName, aFileExtension, aFileName );
+    rtl::OUString aFilterType(aFileFormats[nFormat].pTypeName, strlen(aFileFormats[nFormat].pTypeName), RTL_TEXTENCODING_UTF8);
+    ScDocShellRef xDocSh = load (aFilterName, aFileName, rtl::OUString(), aFilterType, aFileFormats[nFormat].nFormatType);
+    CPPUNIT_ASSERT(xDocSh.Is());
+    return xDocSh;
+}
+
 void ScFiltersTest::createFileURL(const rtl::OUString& aFileBase, const rtl::OUString& aFileExtension, rtl::OUString& rFilePath)
 {
     rtl::OUString aSep(RTL_CONSTASCII_USTRINGPARAM("/"));
@@ -216,46 +238,40 @@ void testRangeNameImpl(ScDocument* pDoc)
 
 }
 
-void ScFiltersTest::testRangeName()
+void ScFiltersTest::testRangeNameXLS()
 {
     const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("named-ranges-global."));
-    //XLSX does not work yet
-    for (sal_uInt32 i = 1; i < 3; ++i)
-    {
-        rtl::OUString aFileExtension(aFileFormats[i].pName, strlen(aFileFormats[i].pName), RTL_TEXTENCODING_UTF8 );
-        rtl::OUString aFilterName(aFileFormats[i].pFilterName, strlen(aFileFormats[i].pFilterName), RTL_TEXTENCODING_UTF8) ;
-        rtl::OUString aFileName;
-        createFileURL( aFileNameBase, aFileExtension, aFileName );
-        rtl::OUString aFilterType(aFileFormats[i].pTypeName, strlen(aFileFormats[i].pTypeName), RTL_TEXTENCODING_UTF8);
-        std::cout << aFileFormats[i].pName << " Test" << std::endl;
-        ScDocShellRef xDocSh = load (aFilterName, aFileName, rtl::OUString(), aFilterType, aFileFormats[i].nFormatType);
-        xDocSh->DoHardRecalc(true);
-
-        CPPUNIT_ASSERT_MESSAGE("Failed to load named-ranges-globals.*", xDocSh.Is());
-        ScDocument* pDoc = xDocSh->GetDocument();
-        testRangeNameImpl(pDoc);
-
-        rtl::OUString aSheet2CSV(RTL_CONSTASCII_USTRINGPARAM("rangeExp_Sheet2."));
-        rtl::OUString aCSVPath;
-        createCSVPath( aSheet2CSV, aCSVPath );
-        // fdo#44587
-        if (i != XLSX)
-            testFile( aCSVPath, pDoc, 1);
+    ScDocShellRef xDocSh = loadDoc(aFileNameBase, XLS);
+    xDocSh->DoHardRecalc(true);
 
-        xDocSh->DoClose();
-    }
+    ScDocument* pDoc = xDocSh->GetDocument();
+    testRangeNameImpl(pDoc);
+
+    rtl::OUString aSheet2CSV(RTL_CONSTASCII_USTRINGPARAM("rangeExp_Sheet2."));
+    rtl::OUString aCSVPath;
+    createCSVPath( aSheet2CSV, aCSVPath );
+    // fdo#44587
+    testFile( aCSVPath, pDoc, 1);
+
+    xDocSh->DoClose();
+}
+
+void ScFiltersTest::testRangeNameXLSX()
+{
+    const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("named-ranges-global."));
+    ScDocShellRef xDocSh = loadDoc(aFileNameBase, XLSX);
+    xDocSh->DoHardRecalc(true);
+
+    ScDocument* pDoc = xDocSh->GetDocument();
+    testRangeNameImpl(pDoc);
+
+    xDocSh->DoClose();
 }
 
-void ScFiltersTest::testFunctions()
+void ScFiltersTest::testFunctionsODS()
 {
     const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("functions."));
-    rtl::OUString aFileExtension(aFileFormats[0].pName, strlen(aFileFormats[0].pName), RTL_TEXTENCODING_UTF8 );
-    rtl::OUString aFilterName(aFileFormats[0].pFilterName, strlen(aFileFormats[0].pFilterName), RTL_TEXTENCODING_UTF8) ;
-    rtl::OUString aFileName;
-    createFileURL(aFileNameBase, aFileExtension, aFileName);
-    rtl::OUString aFilterType(aFileFormats[0].pTypeName, strlen(aFileFormats[0].pTypeName), RTL_TEXTENCODING_UTF8);
-    std::cout << aFileFormats[0].pName << " Test" << std::endl;
-    ScDocShellRef xDocSh = load (aFilterName, aFileName, rtl::OUString(), aFilterType, aFileFormats[0].nFormatType);
+    ScDocShellRef xDocSh = loadDoc( aFileNameBase, ODS );
     xDocSh->DoHardRecalc(true);
 
     CPPUNIT_ASSERT_MESSAGE("Failed to load functions.*", xDocSh.Is());
@@ -278,19 +294,12 @@ void ScFiltersTest::testFunctions()
     xDocSh->DoClose();
 }
 
-void ScFiltersTest::testDatabaseRanges()
+void ScFiltersTest::testDatabaseRangesODS()
 {
     const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("database."));
-    rtl::OUString aFileExtension(aFileFormats[0].pName, strlen(aFileFormats[0].pName), RTL_TEXTENCODING_UTF8 );
-    rtl::OUString aFilterName(aFileFormats[0].pFilterName, strlen(aFileFormats[0].pFilterName), RTL_TEXTENCODING_UTF8) ;
-    rtl::OUString aFileName;
-    createFileURL(aFileNameBase, aFileExtension, aFileName);
-    rtl::OUString aFilterType(aFileFormats[0].pTypeName, strlen(aFileFormats[0].pTypeName), RTL_TEXTENCODING_UTF8);
-    std::cout << aFileFormats[0].pName << " Test" << std::endl;
-    ScDocShellRef xDocSh = load (aFilterName, aFileName, rtl::OUString(), aFilterType, aFileFormats[0].nFormatType);
+    ScDocShellRef xDocSh = loadDoc(aFileNameBase, 0);
     xDocSh->DoHardRecalc(true);
 
-    CPPUNIT_ASSERT_MESSAGE("Failed to load database.*", xDocSh.Is());
     ScDocument* pDoc = xDocSh->GetDocument();
     ScDBCollection* pDBCollection = pDoc->GetDBCollection();
     CPPUNIT_ASSERT_MESSAGE("no database collection", pDBCollection);
@@ -322,110 +331,138 @@ void ScFiltersTest::testDatabaseRanges()
     xDocSh->DoClose();
 }
 
-void ScFiltersTest::testFormats()
+namespace {
+
+void testFormats_Impl(ScFiltersTest* pFiltersTest, ScDocument* pDoc, sal_Int32 nFormat)
 {
-    const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("formats."));
-    for(int i = 0; i < 3; ++i)
+    //test Sheet1 with csv file
+    rtl::OUString aCSVFileName;
+    pFiltersTest->createCSVPath(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("numberFormat.")), aCSVFileName);
+    testFile(aCSVFileName, pDoc, 0, PureString);
+    //need to test the color of B3
+    //it's not a font color!
+    //formatting for B5: # ??/100 gets lost during import
+
+    //test Sheet2
+    const ScPatternAttr* pPattern = NULL;
+    pPattern = pDoc->GetPattern(0,0,1);
+    Font aFont;
+    pPattern->GetFont(aFont,SC_AUTOCOL_RAW);
+    CPPUNIT_ASSERT_MESSAGE("font size should be 10", aFont.GetSize().getHeight() == 200);
+    CPPUNIT_ASSERT_MESSAGE("font color should be black", aFont.GetColor() == COL_AUTO);
+    pPattern = pDoc->GetPattern(0,1,1);
+    pPattern->GetFont(aFont, SC_AUTOCOL_RAW);
+    CPPUNIT_ASSERT_MESSAGE("font size should be 12", aFont.GetSize().getHeight() == 240);
+    pPattern = pDoc->GetPattern(0,2,1);
+    pPattern->GetFont(aFont, SC_AUTOCOL_RAW);
+    CPPUNIT_ASSERT_MESSAGE("font should be italic",aFont.GetItalic() == ITALIC_NORMAL);
+    pPattern = pDoc->GetPattern(0,4,1);
+    pPattern->GetFont(aFont, SC_AUTOCOL_RAW);
+    CPPUNIT_ASSERT_MESSAGE("font should be bold",aFont.GetWeight() == WEIGHT_BOLD );
+    pPattern = pDoc->GetPattern(1,0,1);
+    pPattern->GetFont(aFont, SC_AUTOCOL_RAW);
+    CPPUNIT_ASSERT_MESSAGE("font should be blue", aFont.GetColor() == COL_BLUE );
+    pPattern = pDoc->GetPattern(1,1,1);
+    pPattern->GetFont(aFont, SC_AUTOCOL_RAW);
+    CPPUNIT_ASSERT_MESSAGE("font should be striked out with a single line", aFont.GetStrikeout() == STRIKEOUT_SINGLE );
+    //test double strikeout only for ods
+    if (nFormat == ODS)
     {
-        rtl::OUString aFileExtension(aFileFormats[i].pName, strlen(aFileFormats[i].pName), RTL_TEXTENCODING_UTF8 );
-        rtl::OUString aFilterName(aFileFormats[i].pFilterName, strlen(aFileFormats[i].pFilterName), RTL_TEXTENCODING_UTF8) ;
-        rtl::OUString aFileName;
-        createFileURL(aFileNameBase, aFileExtension, aFileName);
-        rtl::OUString aFilterType(aFileFormats[i].pTypeName, strlen(aFileFormats[i].pTypeName), RTL_TEXTENCODING_UTF8);
-        std::cout << aFileFormats[i].pName << " Test" << std::endl;
-        ScDocShellRef xDocSh = load (aFilterName, aFileName, rtl::OUString(), aFilterType, aFileFormats[i].nFormatType);
-        xDocSh->DoHardRecalc(true);
-
-        CPPUNIT_ASSERT_MESSAGE("Failed to load formats.*", xDocSh.Is());
-        ScDocument* pDoc = xDocSh->GetDocument();
-
-        //test Sheet1 with csv file
-        rtl::OUString aCSVFileName;
-        createCSVPath(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("numberFormat.")), aCSVFileName);
-        testFile(aCSVFileName, pDoc, 0, PureString);
-        //need to test the color of B3
-        //it's not a font color!
-        //formatting for B5: # ??/100 gets lost during import
-
-        //test Sheet2
-        const ScPatternAttr* pPattern = NULL;
-        pPattern = pDoc->GetPattern(0,0,1);
-        Font aFont;
-        pPattern->GetFont(aFont,SC_AUTOCOL_RAW);
-        CPPUNIT_ASSERT_MESSAGE("font size should be 10", aFont.GetSize().getHeight() == 200);
-        CPPUNIT_ASSERT_MESSAGE("font color should be black", aFont.GetColor() == COL_AUTO);
-        pPattern = pDoc->GetPattern(0,1,1);
-        pPattern->GetFont(aFont, SC_AUTOCOL_RAW);
-        CPPUNIT_ASSERT_MESSAGE("font size should be 12", aFont.GetSize().getHeight() == 240);
-        pPattern = pDoc->GetPattern(0,2,1);
-        pPattern->GetFont(aFont, SC_AUTOCOL_RAW);
-        CPPUNIT_ASSERT_MESSAGE("font should be italic",aFont.GetItalic() == ITALIC_NORMAL);
-        pPattern = pDoc->GetPattern(0,4,1);
+        pPattern = pDoc->GetPattern(1,2,1);
         pPattern->GetFont(aFont, SC_AUTOCOL_RAW);
-        CPPUNIT_ASSERT_MESSAGE("font should be bold",aFont.GetWeight() == WEIGHT_BOLD );
-        pPattern = pDoc->GetPattern(1,0,1);
+        CPPUNIT_ASSERT_MESSAGE("font should be striked out with a double line", aFont.GetStrikeout() == STRIKEOUT_DOUBLE );
+        pPattern = pDoc->GetPattern(1,3,1);
         pPattern->GetFont(aFont, SC_AUTOCOL_RAW);
-        CPPUNIT_ASSERT_MESSAGE("font should be blue", aFont.GetColor() == COL_BLUE );
-        pPattern = pDoc->GetPattern(1,1,1);
-        pPattern->GetFont(aFont, SC_AUTOCOL_RAW);
-        CPPUNIT_ASSERT_MESSAGE("font should be striked out with a single line", aFont.GetStrikeout() == STRIKEOUT_SINGLE );
-        //test double strikeout only for ods
-        if (i == ODS)
-        {
-            pPattern = pDoc->GetPattern(1,2,1);
-            pPattern->GetFont(aFont, SC_AUTOCOL_RAW);
-            CPPUNIT_ASSERT_MESSAGE("font should be striked out with a double line", aFont.GetStrikeout() == STRIKEOUT_DOUBLE );
-            pPattern = pDoc->GetPattern(1,3,1);
-            pPattern->GetFont(aFont, SC_AUTOCOL_RAW);
-            CPPUNIT_ASSERT_MESSAGE("font should be underlined with a dotted line", aFont.GetUnderline() == UNDERLINE_DOTTED);
-        }
-        pPattern = pDoc->GetPattern(1,4,1);
-        Color aColor = static_cast<const SvxBrushItem&>(pPattern->GetItem(ATTR_BACKGROUND)).GetColor();
-        CPPUNIT_ASSERT_MESSAGE("background color should be green", aColor == COL_LIGHTGREEN);
-        pPattern = pDoc->GetPattern(2,0,1);
-        SvxCellHorJustify eHorJustify = static_cast<SvxCellHorJustify>(static_cast<const SvxHorJustifyItem&>(pPattern->GetItem(ATTR_HOR_JUSTIFY)).GetValue());
-        CPPUNIT_ASSERT_MESSAGE("cell content should be aligned centre horizontally", eHorJustify == SVX_HOR_JUSTIFY_CENTER);
-        //test alignment
-        pPattern = pDoc->GetPattern(2,1,1);
-        eHorJustify = static_cast<SvxCellHorJustify>(static_cast<const SvxHorJustifyItem&>(pPattern->GetItem(ATTR_HOR_JUSTIFY)).GetValue());
-        CPPUNIT_ASSERT_MESSAGE("cell content should be aligned right horizontally", eHorJustify == SVX_HOR_JUSTIFY_RIGHT);
-        pPattern = pDoc->GetPattern(2,2,1);
-        eHorJustify = static_cast<SvxCellHorJustify>(static_cast<const SvxHorJustifyItem&>(pPattern->GetItem(ATTR_HOR_JUSTIFY)).GetValue());
-        CPPUNIT_ASSERT_MESSAGE("cell content should be aligned block horizontally", eHorJustify == SVX_HOR_JUSTIFY_BLOCK);
-
-        //test Sheet3 only for ods
-        if ( i == ODS )
-        {
-            rtl::OUString aCondString = getConditionalFormatString(pDoc, 3,0,2);
-            createCSVPath(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("conditionalFormatting.")), aCSVFileName);
-            testCondFile(aCSVFileName, pDoc, 2);
-        }
-        xDocSh->DoClose();
+        CPPUNIT_ASSERT_MESSAGE("font should be underlined with a dotted line", aFont.GetUnderline() == UNDERLINE_DOTTED);
+    }
+    pPattern = pDoc->GetPattern(1,4,1);
+    Color aColor = static_cast<const SvxBrushItem&>(pPattern->GetItem(ATTR_BACKGROUND)).GetColor();
+    CPPUNIT_ASSERT_MESSAGE("background color should be green", aColor == COL_LIGHTGREEN);
+    pPattern = pDoc->GetPattern(2,0,1);
+    SvxCellHorJustify eHorJustify = static_cast<SvxCellHorJustify>(static_cast<const SvxHorJustifyItem&>(pPattern->GetItem(ATTR_HOR_JUSTIFY)).GetValue());
+    CPPUNIT_ASSERT_MESSAGE("cell content should be aligned centre horizontally", eHorJustify == SVX_HOR_JUSTIFY_CENTER);
+    //test alignment
+    pPattern = pDoc->GetPattern(2,1,1);
+    eHorJustify = static_cast<SvxCellHorJustify>(static_cast<const SvxHorJustifyItem&>(pPattern->GetItem(ATTR_HOR_JUSTIFY)).GetValue());
+    CPPUNIT_ASSERT_MESSAGE("cell content should be aligned right horizontally", eHorJustify == SVX_HOR_JUSTIFY_RIGHT);
+    pPattern = pDoc->GetPattern(2,2,1);
+    eHorJustify = static_cast<SvxCellHorJustify>(static_cast<const SvxHorJustifyItem&>(pPattern->GetItem(ATTR_HOR_JUSTIFY)).GetValue());
+    CPPUNIT_ASSERT_MESSAGE("cell content should be aligned block horizontally", eHorJustify == SVX_HOR_JUSTIFY_BLOCK);
+
+    //test Sheet3 only for ods
+    if ( nFormat == ODS )
+    {
+        rtl::OUString aCondString = getConditionalFormatString(pDoc, 3,0,2);
+        pFiltersTest->createCSVPath(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("conditionalFormatting.")), aCSVFileName);
+        testCondFile(aCSVFileName, pDoc, 2);
     }
 }
 
-void ScFiltersTest::testMatrix()
+}
+
+void ScFiltersTest::testFormatsODS()
+{
+    const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("formats."));
+    ScDocShellRef xDocSh = loadDoc(aFileNameBase, 0);
+    xDocSh->DoHardRecalc(true);
+
+    ScDocument* pDoc = xDocSh->GetDocument();
+
+    testFormats_Impl(this, pDoc, ODS);
+    xDocSh->DoClose();
+}
+
+void ScFiltersTest::testFormatsXLS()
+{
+    const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("formats."));
+    ScDocShellRef xDocSh = loadDoc(aFileNameBase, 1);
+    xDocSh->DoHardRecalc(true);
+
+    ScDocument* pDoc = xDocSh->GetDocument();
+
+    testFormats_Impl(this, pDoc, XLS);
+    xDocSh->DoClose();
+}
+
+void ScFiltersTest::testFormatsXLSX()
+{
+    const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("formats."));
+    ScDocShellRef xDocSh = loadDoc(aFileNameBase, 2);
+    xDocSh->DoHardRecalc(true);
+
+    ScDocument* pDoc = xDocSh->GetDocument();
+
+    testFormats_Impl(this, pDoc, XLSX);
+    xDocSh->DoClose();
+}
+
+void ScFiltersTest::testMatrixODS()
 {
     const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("matrix."));
-    for (int i = 0; i < 2; ++i)
-    {
-        rtl::OUString aFileExtension(aFileFormats[1].pName, strlen(aFileFormats[1].pName), RTL_TEXTENCODING_UTF8 );
-        rtl::OUString aFilterName(aFileFormats[1].pFilterName, strlen(aFileFormats[1].pFilterName), RTL_TEXTENCODING_UTF8) ;
-        rtl::OUString aFileName;
-        createFileURL(aFileNameBase, aFileExtension, aFileName);
-        rtl::OUString aFilterType(aFileFormats[1].pTypeName, strlen(aFileFormats[1].pTypeName), RTL_TEXTENCODING_UTF8);
-        std::cout << aFileFormats[1].pName << " Test" << std::endl;
-        ScDocShellRef xDocSh = load (aFilterName, aFileName, rtl::OUString(), aFilterType, aFileFormats[1].nFormatType);
+    ScDocShellRef xDocSh = loadDoc( aFileNameBase, 0);
 
-        CPPUNIT_ASSERT_MESSAGE("Failed to load matrix.*", xDocSh.Is());
-        ScDocument* pDoc = xDocSh->GetDocument();
+    ScDocument* pDoc = xDocSh->GetDocument();
 
-        rtl::OUString aCSVFileName;
-        createCSVPath(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("matrix.")), aCSVFileName);
-        testFile(aCSVFileName, pDoc, 0);
+    rtl::OUString aCSVFileName;
+    createCSVPath(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("matrix.")), aCSVFileName);
+    testFile(aCSVFileName, pDoc, 0);
 
-        xDocSh->DoClose();
-    }
+    xDocSh->DoClose();
+}
+
+void ScFiltersTest::testMatrixXLS()
+{
+    const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("matrix."));
+    ScDocShellRef xDocSh = loadDoc( aFileNameBase, 1);
+
+    CPPUNIT_ASSERT_MESSAGE("Failed to load matrix.*", xDocSh.Is());
+    ScDocument* pDoc = xDocSh->GetDocument();
+
+    rtl::OUString aCSVFileName;
+    createCSVPath(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("matrix.")), aCSVFileName);
+    testFile(aCSVFileName, pDoc, 0);
+
+    xDocSh->DoClose();
 }
 
 void ScFiltersTest::testBugFixesODS()
commit 423fb7b73673cb0fa19359bcdbe0156dcc34b01c
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Sat Feb 11 15:05:24 2012 +0100

    refactor filters-test and move each test in own method

diff --git a/sc/qa/unit/filters-test.cxx b/sc/qa/unit/filters-test.cxx
index 3697c39..4e40f57 100644
--- a/sc/qa/unit/filters-test.cxx
+++ b/sc/qa/unit/filters-test.cxx
@@ -102,8 +102,10 @@ public:
     void testCVEs();
 
     //ods, xls, xlsx filter tests
-    void testRangeName(); // only test ods here, xls and xlsx in subsequent_filters-test
-    void testContent();
+    void testRangeNameODS(); // only test ods here, xls and xlsx in subsequent_filters-test
+    void testContentODS();
+    void testContentXLS();
+    void testContentXLSX();
 
 #if TEST_BUG_FILES
     //goes recursively through all files in this dir and tries to open them
@@ -116,8 +118,10 @@ public:
 
     CPPUNIT_TEST_SUITE(ScFiltersTest);
     CPPUNIT_TEST(testCVEs);
-    CPPUNIT_TEST(testRangeName);
-    CPPUNIT_TEST(testContent);
+    CPPUNIT_TEST(testRangeNameODS);
+    CPPUNIT_TEST(testContentODS);
+    CPPUNIT_TEST(testContentXLS);
+    CPPUNIT_TEST(testContentXLSX);
 
 #if TEST_BUG_FILES
     CPPUNIT_TEST(testBugFiles);
@@ -127,6 +131,7 @@ public:
     CPPUNIT_TEST_SUITE_END();
 
 private:
+    ScDocShellRef loadDoc(const rtl::OUString& rName, sal_Int32 nFormat);
     uno::Reference<uno::XInterface> m_xCalcComponent;
     ::rtl::OUString m_aBaseString;
 };
@@ -278,31 +283,33 @@ void testRangeNameImpl(ScDocument* pDoc)
 
 }
 
-void ScFiltersTest::testRangeName()
+ScDocShellRef ScFiltersTest::loadDoc(const rtl::OUString& rName, sal_Int32 nFormat)
+{
+    rtl::OUString aFileExtension(aFileFormats[nFormat].pName, strlen(aFileFormats[nFormat].pName), RTL_TEXTENCODING_UTF8 );
+    rtl::OUString aFilterName(aFileFormats[nFormat].pFilterName, strlen(aFileFormats[nFormat].pFilterName), RTL_TEXTENCODING_UTF8) ;
+    rtl::OUString aFileName;
+    createFileURL( rName, aFileExtension, aFileName );
+    rtl::OUString aFilterType(aFileFormats[nFormat].pTypeName, strlen(aFileFormats[nFormat].pTypeName), RTL_TEXTENCODING_UTF8);
+    ScDocShellRef xDocSh = load (aFilterName, aFileName, rtl::OUString(), aFilterType, aFileFormats[nFormat].nFormatType);
+    CPPUNIT_ASSERT(xDocSh.Is());
+    return xDocSh;
+}
+
+void ScFiltersTest::testRangeNameODS()
 {
     const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("named-ranges-global."));
-    //XLSX does not work yet
-    for (sal_uInt32 i = 0; i < 1; ++i)
-    {
-        rtl::OUString aFileExtension(aFileFormats[i].pName, strlen(aFileFormats[i].pName), RTL_TEXTENCODING_UTF8 );
-        rtl::OUString aFilterName(aFileFormats[i].pFilterName, strlen(aFileFormats[i].pFilterName), RTL_TEXTENCODING_UTF8) ;
-        rtl::OUString aFileName;
-        createFileURL( aFileNameBase, aFileExtension, aFileName );
-        rtl::OUString aFilterType(aFileFormats[i].pTypeName, strlen(aFileFormats[i].pTypeName), RTL_TEXTENCODING_UTF8);
-        std::cout << aFileFormats[i].pName << " Test" << std::endl;
-        ScDocShellRef xDocSh = load (aFilterName, aFileName, rtl::OUString(), aFilterType, aFileFormats[i].nFormatType);
-        xDocSh->DoHardRecalc(true);
-
-        CPPUNIT_ASSERT_MESSAGE("Failed to load named-ranges-globals.*", xDocSh.Is());
-        ScDocument* pDoc = xDocSh->GetDocument();
-        testRangeNameImpl(pDoc);
-
-        rtl::OUString aSheet2CSV(RTL_CONSTASCII_USTRINGPARAM("rangeExp_Sheet2."));
-        rtl::OUString aCSVPath;
-        createCSVPath( aSheet2CSV, aCSVPath );
-        testFile( aCSVPath, pDoc, 1);
-        xDocSh->DoClose();
-    }
+    ScDocShellRef xDocSh = loadDoc(aFileNameBase, 1);
+    xDocSh->DoHardRecalc(true);
+
+    CPPUNIT_ASSERT_MESSAGE("Failed to load named-ranges-globals.*", xDocSh.Is());
+    ScDocument* pDoc = xDocSh->GetDocument();
+    testRangeNameImpl(pDoc);
+
+    rtl::OUString aSheet2CSV(RTL_CONSTASCII_USTRINGPARAM("rangeExp_Sheet2."));
+    rtl::OUString aCSVPath;
+    createCSVPath( aSheet2CSV, aCSVPath );
+    testFile( aCSVPath, pDoc, 1);
+    xDocSh->DoClose();
 }
 
 namespace {
@@ -345,25 +352,37 @@ void testContentImpl(ScDocument* pDoc) //same code for ods, xls, xlsx
 
 }
 
-void ScFiltersTest::testContent()
+void ScFiltersTest::testContentODS()
 {
     const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("universal-content."));
-    for (sal_uInt32 i = 0; i < 3; ++i)
-    {
-        rtl::OUString aFileExtension(aFileFormats[i].pName, strlen(aFileFormats[i].pName), RTL_TEXTENCODING_UTF8 );
-        rtl::OUString aFilterName(aFileFormats[i].pFilterName, strlen(aFileFormats[i].pFilterName), RTL_TEXTENCODING_UTF8) ;
-        rtl::OUString aFileName;
-        createFileURL(aFileNameBase, aFileExtension, aFileName);
-        rtl::OUString aFilterType(aFileFormats[i].pTypeName, strlen(aFileFormats[i].pTypeName), RTL_TEXTENCODING_UTF8);
-        std::cout << aFileFormats[i].pName << " Test" << std::endl;
-        ScDocShellRef xDocSh = load (aFilterName, aFileName, rtl::OUString(), aFilterType, aFileFormats[i].nFormatType);
-        xDocSh->DoHardRecalc(true);
-
-        CPPUNIT_ASSERT_MESSAGE("Failed to load universal-content.*", xDocSh.Is());
-        ScDocument* pDoc = xDocSh->GetDocument();
-        testContentImpl(pDoc);
-        xDocSh->DoClose();
-    }
+    ScDocShellRef xDocSh = loadDoc(aFileNameBase, 0);
+    xDocSh->DoHardRecalc(true);
+
+    ScDocument* pDoc = xDocSh->GetDocument();
+    testContentImpl(pDoc);
+    xDocSh->DoClose();
+}
+
+void ScFiltersTest::testContentXLS()
+{
+    const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("universal-content."));
+    ScDocShellRef xDocSh = loadDoc(aFileNameBase, 1);
+    xDocSh->DoHardRecalc(true);
+
+    ScDocument* pDoc = xDocSh->GetDocument();
+    testContentImpl(pDoc);
+    xDocSh->DoClose();
+}
+
+void ScFiltersTest::testContentXLSX()
+{
+    const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("universal-content."));
+    ScDocShellRef xDocSh = loadDoc(aFileNameBase, 2);
+    xDocSh->DoHardRecalc(true);
+
+    ScDocument* pDoc = xDocSh->GetDocument();
+    testContentImpl(pDoc);
+    xDocSh->DoClose();
 }
 
 ScFiltersTest::ScFiltersTest()


More information about the Libreoffice-commits mailing list