[Libreoffice-commits] .: 3 commits - sc/inc sc/qa sc/source

Markus Mohrhard mmohrhard at kemper.freedesktop.org
Tue Sep 13 19:06:08 PDT 2011


 sc/inc/dbdata.hxx                |    3 +
 sc/qa/unit/data/ods/database.ods |binary
 sc/qa/unit/data/ods/formats.ods  |binary
 sc/qa/unit/filters-test.cxx      |  102 +++++++++++++++++++++++++++++++++++++++
 sc/source/core/tool/compiler.cxx |    2 
 sc/source/core/tool/dbdata.cxx   |   23 ++++++++
 6 files changed, 129 insertions(+), 1 deletion(-)

New commits:
commit 61732a8d8a1339364a9ae98959c74d9a9f5e203e
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Wed Sep 14 03:56:38 2011 +0200

    add unit test for formated cells

diff --git a/sc/qa/unit/data/ods/formats.ods b/sc/qa/unit/data/ods/formats.ods
new file mode 100644
index 0000000..cb7a29c
Binary files /dev/null and b/sc/qa/unit/data/ods/formats.ods differ
diff --git a/sc/qa/unit/filters-test.cxx b/sc/qa/unit/filters-test.cxx
index 5b64060..f50dc5a 100644
--- a/sc/qa/unit/filters-test.cxx
+++ b/sc/qa/unit/filters-test.cxx
@@ -63,6 +63,7 @@
 #include "docsh.hxx"
 #include "document.hxx"
 #include "postit.hxx"
+#include "patattr.hxx"
 
 #include "helper/csv_handler.hxx"
 #include "orcus/csv_parser.hpp"
@@ -152,6 +153,7 @@ public:
     void testContent();
     void testFunctions();
     void testDatabaseRanges();
+    void testFormats();
     void testBugFixesODS();
     void testBugFixesXLS();
     void testBugFixesXLSX();
@@ -162,6 +164,7 @@ public:
     CPPUNIT_TEST(testContent);
     CPPUNIT_TEST(testFunctions);
     CPPUNIT_TEST(testDatabaseRanges);
+    CPPUNIT_TEST(testFormats);
     CPPUNIT_TEST(testBugFixesODS);
     CPPUNIT_TEST(testBugFixesXLS);
     CPPUNIT_TEST(testBugFixesXLSX);
@@ -429,8 +432,9 @@ void FiltersTest::testDatabaseRanges()
     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);
+    xDocSh->DoHardRecalc(true);
 
-    CPPUNIT_ASSERT_MESSAGE("Failed to load functions.*", xDocSh.Is());
+    CPPUNIT_ASSERT_MESSAGE("Failed to load database.*", xDocSh.Is());
     ScDocument* pDoc = xDocSh->GetDocument();
     ScDBCollection* pDBCollection = pDoc->GetDBCollection();
     CPPUNIT_ASSERT_MESSAGE("no database collection", pDBCollection);
@@ -463,6 +467,58 @@ void FiltersTest::testDatabaseRanges()
     CPPUNIT_ASSERT_MESSAGE("Sheet2: B11: formula result is incorrect", aValue == 2);
 }
 
+void FiltersTest::testFormats()
+{
+    const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("formats."));
+    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;
+    createFilePath(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);
+    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);
+    //need to test the color of B3
+    //it's not a font color!
+
+    //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 );
+    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);
+}
+
 void FiltersTest::testBugFixesODS()
 {
     const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("bug-fixes."));
commit b6d3f5c2c18ad0e1f41cb7b5d6c9072f1c79ff46
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Tue Sep 13 22:33:58 2011 +0200

    ScCompiler::IsDBRange compares upper case strings

diff --git a/sc/inc/dbdata.hxx b/sc/inc/dbdata.hxx
index 2772a02..c48aa1a 100644
--- a/sc/inc/dbdata.hxx
+++ b/sc/inc/dbdata.hxx
@@ -55,6 +55,7 @@ private:
 
     // DBParam
     const ::rtl::OUString aName;
+    ::rtl::OUString aUpper;
     SCTAB           nTable;
     SCCOL           nStartCol;
     SCROW           nStartRow;
@@ -98,6 +99,7 @@ public:
 
     SCTAB       GetTable() const;
     const ::rtl::OUString& GetName() const { return aName; }
+    const ::rtl::OUString& GetUpperName() const { return aUpper; }
     void        GetArea(SCTAB& rTab, SCCOL& rCol1, SCROW& rRow1, SCCOL& rCol2, SCROW& rRow2) const;
     SC_DLLPUBLIC void GetArea(ScRange& rRange) const;
     void        SetArea(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2);
@@ -186,6 +188,7 @@ public:
         const_iterator end() const;
         ScDBData* findByIndex(sal_uInt16 nIndex);
         ScDBData* findByName(const ::rtl::OUString& rName);
+        ScDBData* findByUpperName(const ::rtl::OUString& rName);
         bool insert(ScDBData* p);
         void erase(iterator itr);
         void erase(const ScDBData& r);
diff --git a/sc/qa/unit/filters-test.cxx b/sc/qa/unit/filters-test.cxx
index 87b28f2..5b64060 100644
--- a/sc/qa/unit/filters-test.cxx
+++ b/sc/qa/unit/filters-test.cxx
@@ -438,7 +438,6 @@ void FiltersTest::testDatabaseRanges()
     ScDBData* pAnonDBData = pDoc->GetAnonymousDBData(0);
     CPPUNIT_ASSERT_MESSAGE("missing anonymous DB data in sheet 1", pAnonDBData);
     //control hidden rows
-    /*
     bool bHidden;
     SCROW nRow1, nRow2;
     bHidden = pDoc->RowHidden(0, 0, &nRow1, &nRow2);
@@ -462,7 +461,6 @@ void FiltersTest::testDatabaseRanges()
     CPPUNIT_ASSERT_MESSAGE("Sheet2: A11: formula result is incorrect", aValue == 4);
     pDoc->GetValue(1, 10, 1, aValue);
     CPPUNIT_ASSERT_MESSAGE("Sheet2: B11: formula result is incorrect", aValue == 2);
-*/
 }
 
 void FiltersTest::testBugFixesODS()
diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx
index cc6d69f..876c992 100644
--- a/sc/source/core/tool/compiler.cxx
+++ b/sc/source/core/tool/compiler.cxx
@@ -3014,7 +3014,7 @@ bool ScCompiler::IsExternalNamedRange( const String& rSymbol )
 bool ScCompiler::IsDBRange( const String& rName )
 {
     ScDBCollection::NamedDBs& rDBs = pDoc->GetDBCollection()->getNamedDBs();
-    const ScDBData* p = rDBs.findByName(rName);
+    const ScDBData* p = rDBs.findByUpperName(rName);
     if (!p)
         return false;
 
diff --git a/sc/source/core/tool/dbdata.cxx b/sc/source/core/tool/dbdata.cxx
index e4baa4f..f4881f6 100644
--- a/sc/source/core/tool/dbdata.cxx
+++ b/sc/source/core/tool/dbdata.cxx
@@ -62,6 +62,7 @@ ScDBData::ScDBData( const ::rtl::OUString& rName,
                     SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
                     bool bByR, bool bHasH) :
     aName       (rName),
+    aUpper      (rName),
     nTable      (nTab),
     nStartCol   (nCol1),
     nStartRow   (nRow1),
@@ -78,6 +79,7 @@ ScDBData::ScDBData( const ::rtl::OUString& rName,
     bAutoFilter (false),
     bModified   (false)
 {
+    ScGlobal::pCharClass->toUpper(aUpper);
     ScSortParam aSortParam;
     ScQueryParam aQueryParam;
     ScImportParam aImportParam;
@@ -94,6 +96,7 @@ ScDBData::ScDBData( const ScDBData& rData ) :
     maSubTotal          (rData.maSubTotal),
     maImportParam       (rData.maImportParam),
     aName               (rData.aName),
+    aUpper              (rData.aUpper),
     nTable              (rData.nTable),
     nStartCol           (rData.nStartCol),
     nStartRow           (rData.nStartRow),
@@ -120,6 +123,7 @@ ScDBData::ScDBData( const ::rtl::OUString& rName, const ScDBData& rData ) :
     maSubTotal          (rData.maSubTotal),
     maImportParam       (rData.maImportParam),
     aName               (rName),
+    aUpper              (rName),
     nTable              (rData.nTable),
     nStartCol           (rData.nStartCol),
     nStartRow           (rData.nStartRow),
@@ -137,6 +141,7 @@ ScDBData::ScDBData( const ::rtl::OUString& rName, const ScDBData& rData ) :
     bAutoFilter         (rData.bAutoFilter),
     bModified           (rData.bModified)
 {
+    ScGlobal::pCharClass->toUpper(aUpper);
 }
 
 ScDBData& ScDBData::operator= (const ScDBData& rData)
@@ -645,6 +650,17 @@ public:
     }
 };
 
+class FindByUpperName : public unary_function<ScDBData, bool>
+{
+    const ::rtl::OUString& mrName;
+public:
+    FindByUpperName(const ::rtl::OUString& rName) : mrName(rName) {}
+    bool operator() (const ScDBData& r) const
+    {
+        return r.GetUpperName() == mrName;
+    }
+};
+
 class FindFilterDBByTable : public unary_function<ScDBData, bool>
 {
     SCTAB mnTab;
@@ -701,6 +717,13 @@ ScDBData* ScDBCollection::NamedDBs::findByName(const ::rtl::OUString& rName)
     return itr == maDBs.end() ? NULL : &(*itr);
 }
 
+ScDBData* ScDBCollection::NamedDBs::findByUpperName(const ::rtl::OUString& rName)
+{
+    DBsType::iterator itr = find_if(
+        maDBs.begin(), maDBs.end(), FindByUpperName(rName));
+    return itr == maDBs.end() ? NULL : &(*itr);
+}
+
 bool ScDBCollection::NamedDBs::insert(ScDBData* p)
 {
     auto_ptr<ScDBData> pData(p);
commit ba361f9baac5e4162395f9a404a229e6a46985c3
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Tue Sep 13 17:31:07 2011 +0200

    add database unit test

diff --git a/sc/qa/unit/data/ods/database.ods b/sc/qa/unit/data/ods/database.ods
new file mode 100644
index 0000000..c8039f9
Binary files /dev/null and b/sc/qa/unit/data/ods/database.ods differ
diff --git a/sc/qa/unit/filters-test.cxx b/sc/qa/unit/filters-test.cxx
index dcccb0b..87b28f2 100644
--- a/sc/qa/unit/filters-test.cxx
+++ b/sc/qa/unit/filters-test.cxx
@@ -151,6 +151,7 @@ public:
     void testRangeName();
     void testContent();
     void testFunctions();
+    void testDatabaseRanges();
     void testBugFixesODS();
     void testBugFixesXLS();
     void testBugFixesXLSX();
@@ -160,6 +161,7 @@ public:
     CPPUNIT_TEST(testRangeName);
     CPPUNIT_TEST(testContent);
     CPPUNIT_TEST(testFunctions);
+    CPPUNIT_TEST(testDatabaseRanges);
     CPPUNIT_TEST(testBugFixesODS);
     CPPUNIT_TEST(testBugFixesXLS);
     CPPUNIT_TEST(testBugFixesXLSX);
@@ -417,6 +419,52 @@ void FiltersTest::testFunctions()
     testFile(aCSVFileName, pDoc, 0);
 }
 
+void FiltersTest::testDatabaseRanges()
+{
+    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;
+    createFilePath(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);
+
+    CPPUNIT_ASSERT_MESSAGE("Failed to load functions.*", xDocSh.Is());
+    ScDocument* pDoc = xDocSh->GetDocument();
+    ScDBCollection* pDBCollection = pDoc->GetDBCollection();
+    CPPUNIT_ASSERT_MESSAGE("no database collection", pDBCollection);
+
+    ScDBData* pAnonDBData = pDoc->GetAnonymousDBData(0);
+    CPPUNIT_ASSERT_MESSAGE("missing anonymous DB data in sheet 1", pAnonDBData);
+    //control hidden rows
+    /*
+    bool bHidden;
+    SCROW nRow1, nRow2;
+    bHidden = pDoc->RowHidden(0, 0, &nRow1, &nRow2);
+    CPPUNIT_ASSERT_MESSAGE("Sheet1: row 0 should be visible", !bHidden && nRow1 == 0 && nRow2 == 0);
+    bHidden = pDoc->RowHidden(1, 0, &nRow1, &nRow2);
+    CPPUNIT_ASSERT_MESSAGE("Sheet1: rows 1-2 should be hidden", bHidden && nRow1 == 1 && nRow2 == 2);
+    bHidden = pDoc->RowHidden(3, 0, &nRow1, &nRow2);
+    CPPUNIT_ASSERT_MESSAGE("Sheet1: row 3 should be visible", !bHidden && nRow1 == 3 && nRow2 == 3);
+    bHidden = pDoc->RowHidden(4, 0, &nRow1, &nRow2);
+    CPPUNIT_ASSERT_MESSAGE("Sheet1: row 4-5 should be hidden", bHidden && nRow1 == 4 && nRow2 == 5);
+    bHidden = pDoc->RowHidden(6, 0, &nRow1, &nRow2);
+    CPPUNIT_ASSERT_MESSAGE("Sheet1: row 6-end should be visible", !bHidden && nRow1 == 6 && nRow2 == MAXROW);
+    double aValue;
+    pDoc->GetValue(0,10,1, aValue);
+    std::cout << aValue << std::endl;
+    rtl::OUString aString;
+    pDoc->GetFormula(0,10,1,aString);
+    rtl::OString aOString;
+    aOString = rtl::OUStringToOString(aString, RTL_TEXTENCODING_UTF8);
+    std::cout << aOString.getStr() << std::endl;
+    CPPUNIT_ASSERT_MESSAGE("Sheet2: A11: formula result is incorrect", aValue == 4);
+    pDoc->GetValue(1, 10, 1, aValue);
+    CPPUNIT_ASSERT_MESSAGE("Sheet2: B11: formula result is incorrect", aValue == 2);
+*/
+}
+
 void FiltersTest::testBugFixesODS()
 {
     const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("bug-fixes."));


More information about the Libreoffice-commits mailing list