[Libreoffice-commits] .: 2 commits - sc/qa

Markus Mohrhard mmohrhard at kemper.freedesktop.org
Wed Sep 14 20:25:17 PDT 2011


 sc/qa/unit/data/contentCSV/numberFormat.csv |   10 +
 sc/qa/unit/data/ods/formats.ods             |binary
 sc/qa/unit/data/xls/formats.xls             |binary
 sc/qa/unit/data/xlsx/formats.xlsx           |binary
 sc/qa/unit/filters-test.cxx                 |  160 +++++++++++++++++++---------
 sc/qa/unit/helper/csv_handler.hxx           |  152 ++++++++++++++++++++------
 6 files changed, 232 insertions(+), 90 deletions(-)

New commits:
commit 4fe079747a25013032724418b7ec76a827426907
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Thu Sep 15 04:46:03 2011 +0200

    add formats test for xls and xlsx

diff --git a/sc/qa/unit/data/xls/formats.xls b/sc/qa/unit/data/xls/formats.xls
new file mode 100644
index 0000000..5868a93
Binary files /dev/null and b/sc/qa/unit/data/xls/formats.xls differ
diff --git a/sc/qa/unit/data/xlsx/formats.xlsx b/sc/qa/unit/data/xlsx/formats.xlsx
new file mode 100644
index 0000000..2cd31f5
Binary files /dev/null and b/sc/qa/unit/data/xlsx/formats.xlsx differ
diff --git a/sc/qa/unit/filters-test.cxx b/sc/qa/unit/filters-test.cxx
index 48bec6f..3b9bc50 100644
--- a/sc/qa/unit/filters-test.cxx
+++ b/sc/qa/unit/filters-test.cxx
@@ -82,6 +82,10 @@ const int indeterminate = 2;
 #define XLS_FORMAT_TYPE 318767171
 #define XLSX_FORMAT_TYPE 268959811
 
+#define ODS     0
+#define XLS     1
+#define XLSX    2
+
 using namespace ::com::sun::star;
 
 namespace {
@@ -496,74 +500,83 @@ void FiltersTest::testDatabaseRanges()
 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);
+    for(int 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;
+        createFilePath(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();
+        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->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);
-    pPattern = pDoc->GetPattern(1,4,1);
-    Color aColor = static_cast<const SvxBrushItem&>(pPattern->GetItem(ATTR_BACKGROUND)).GetColor();
-    std::cerr << "red: " << (int)aColor.GetRed() << " green: " << (int)aColor.GetGreen() << " blue: " << (int)aColor.GetBlue() << std::endl;
-    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 centre 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 centre horizontally", eHorJustify == SVX_HOR_JUSTIFY_BLOCK);
-
-    //test Sheet3
-    rtl::OUString aCondString = getConditionalFormatString(pDoc, 3,0,2);
-    std::cerr << rtl::OUStringToOString(aCondString, RTL_TEXTENCODING_UTF8).getStr() << std::endl;
-    createCSVPath(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("conditionalFormatting.")), aCSVFileName);
-    testCondFile(aCSVFileName, pDoc, 2);
+        //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->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 (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);
+            std::cerr << rtl::OUStringToOString(aCondString, RTL_TEXTENCODING_UTF8).getStr() << std::endl;
+            createCSVPath(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("conditionalFormatting.")), aCSVFileName);
+            testCondFile(aCSVFileName, pDoc, 2);
+        }
+    }
 }
 
 void FiltersTest::testBugFixesODS()
commit 2b75f5908ba50dc5bcd20472ad7a6087a0b0753f
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Thu Sep 15 04:29:49 2011 +0200

    improve calc's format unit test
    
    bug in 'formats.ods'Sheet1.B5 with number format import

diff --git a/sc/qa/unit/data/contentCSV/numberFormat.csv b/sc/qa/unit/data/contentCSV/numberFormat.csv
index b2d13aa..8120173 100644
--- a/sc/qa/unit/data/contentCSV/numberFormat.csv
+++ b/sc/qa/unit/data/contentCSV/numberFormat.csv
@@ -1,4 +1,6 @@
-2.00,-3.00
-40.10%,-22%
-"$12,345.00","-$1,234.00"
-
+2.00, -3.00
+40.10%, -22%
+"$12,345.00", "-$1,234.00"
+2.59E+005, -2.35E+03
+25 31/82
+FALSE, TRUE
diff --git a/sc/qa/unit/data/ods/formats.ods b/sc/qa/unit/data/ods/formats.ods
index cb7a29c..2fa9c13 100644
Binary files a/sc/qa/unit/data/ods/formats.ods 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 f50dc5a..48bec6f 100644
--- a/sc/qa/unit/filters-test.cxx
+++ b/sc/qa/unit/filters-test.cxx
@@ -60,10 +60,15 @@
 #include <sfx2/docfile.hxx>
 #include <sfx2/sfxmodelfactory.hxx>
 
+#include <editeng/brshitem.hxx>
+#include <editeng/justifyitem.hxx>
+
 #include "docsh.hxx"
 #include "document.hxx"
 #include "postit.hxx"
 #include "patattr.hxx"
+#include "scitems.hxx"
+#include "cellform.hxx"
 
 #include "helper/csv_handler.hxx"
 #include "orcus/csv_parser.hpp"
@@ -103,9 +108,9 @@ void loadFile(const rtl::OUString& aFileName, std::string& aContent)
     aContent = aOStream.str();
 }
 
-void testFile(rtl::OUString& aFileName, ScDocument* pDoc, SCTAB nTab)
+void testFile(rtl::OUString& aFileName, ScDocument* pDoc, SCTAB nTab, StringType aStringFormat = StringValue)
 {
-    csv_handler aHandler(pDoc, nTab);
+    csv_handler aHandler(pDoc, nTab, aStringFormat);
     orcus::csv_parser_config aConfig;
     aConfig.delimiters.push_back(',');
     aConfig.delimiters.push_back(';');
@@ -119,9 +124,32 @@ void testFile(rtl::OUString& aFileName, ScDocument* pDoc, SCTAB nTab)
     }
     catch (const orcus::csv_parse_error& e)
     {
-        std::cout << "reading csv content file failed" << e.what() << std::endl;
+        std::cout << "reading csv content file failed: " << e.what() << std::endl;
+        CPPUNIT_ASSERT_MESSAGE("csv parser error", false);
+    }
+}
+
+//need own handler because conditional formatting strings must be generated
+void testCondFile(rtl::OUString& aFileName, ScDocument* pDoc, SCTAB nTab)
+{
+    conditional_format_handler aHandler(pDoc, nTab);
+    orcus::csv_parser_config aConfig;
+    aConfig.delimiters.push_back(',');
+    aConfig.delimiters.push_back(';');
+    aConfig.text_qualifier = '"';
+    std::string aContent;
+    loadFile(aFileName, aContent);
+    orcus::csv_parser<conditional_format_handler> parser ( &aContent[0], aContent.size() , aHandler, aConfig);
+    try
+    {
+        parser.parse();
+    }
+    catch (const orcus::csv_parse_error& e)
+    {
+        std::cout << "reading csv content file failed: " << e.what() << std::endl;
         CPPUNIT_ASSERT_MESSAGE("csv parser error", false);
     }
+
 }
 
 }
@@ -456,12 +484,10 @@ void FiltersTest::testDatabaseRanges()
     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);
@@ -485,9 +511,10 @@ void FiltersTest::testFormats()
     //test Sheet1 with csv file
     rtl::OUString aCSVFileName;
     createCSVPath(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("numberFormat.")), aCSVFileName);
-    testFile(aCSVFileName, pDoc, 0);
+    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;
@@ -517,6 +544,26 @@ void FiltersTest::testFormats()
     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();
+    std::cerr << "red: " << (int)aColor.GetRed() << " green: " << (int)aColor.GetGreen() << " blue: " << (int)aColor.GetBlue() << std::endl;
+    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 centre 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 centre horizontally", eHorJustify == SVX_HOR_JUSTIFY_BLOCK);
+
+    //test Sheet3
+    rtl::OUString aCondString = getConditionalFormatString(pDoc, 3,0,2);
+    std::cerr << rtl::OUStringToOString(aCondString, RTL_TEXTENCODING_UTF8).getStr() << std::endl;
+    createCSVPath(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("conditionalFormatting.")), aCSVFileName);
+    testCondFile(aCSVFileName, pDoc, 2);
 }
 
 void FiltersTest::testBugFixesODS()
diff --git a/sc/qa/unit/helper/csv_handler.hxx b/sc/qa/unit/helper/csv_handler.hxx
index 59436e2..83a8e99 100644
--- a/sc/qa/unit/helper/csv_handler.hxx
+++ b/sc/qa/unit/helper/csv_handler.hxx
@@ -29,33 +29,44 @@
 
 #define DEBUG_CSV_HANDLER 0
 
+
+namespace {
+
+rtl::OUString getConditionalFormatString(ScDocument* pDoc, SCCOL nCol, SCROW nRow, SCTAB nTab)
+{
+    String aString;
+    Color* pColor;
+    ScBaseCell* pCell = pDoc->GetCell(ScAddress(nCol, nRow, nTab));
+    const SfxItemSet* pCondSet = pDoc->GetCondResult( nCol, nRow, nTab );
+    const ScPatternAttr* pPattern = pDoc->GetPattern(nCol, nRow, nTab);
+    SvNumberFormatter* pFormatter = pDoc->GetFormatTable();
+    sal_uInt32 nFormat = pPattern->GetNumberFormat( pFormatter, pCondSet );
+    ScCellFormat::GetString( pCell, nFormat, aString, &pColor, *pFormatter);
+    return rtl::OUString(aString);
+}
+
+}
+
+
+enum StringType { PureString, FormulaValue, StringValue };
+
 class csv_handler
 {
 public:
 
-    enum StringType { PureString, FormulaString };
 
-    csv_handler(ScDocument* pDoc, SCTAB nTab, StringType aType = PureString):
+    csv_handler(ScDocument* pDoc, SCTAB nTab, StringType aType = StringValue):
             mpDoc(pDoc),
             mnCol(0),
             mnRow(0),
             mnTab(nTab),
             maStringType(aType)  {}
 
-    void begin_parse()
-    {
-
-    }
-
-    void end_parse()
-    {
-
-    }
+    void begin_parse() {}
 
-    void begin_row()
-    {
+    void end_parse() {}
 
-    }
+    void begin_row() {}
 
     void end_row()
     {
@@ -68,39 +79,62 @@ public:
 #if DEBUG_CSV_HANDLER
         std::cout << "Col: " << mnCol << " Row: " << mnRow << std::endl;
 #endif //DEBUG_CSV_HANDLER
-        char* pRemainingChars = NULL;
-        std::string aStr(p, n);
-        double nValue = strtod(&aStr[0], &pRemainingChars);
-        if (*pRemainingChars)
+        if (maStringType == PureString)
         {
-            rtl::OUString aString;
-            switch (maStringType)
-            {
-                case PureString:
-                    mpDoc->GetString(mnCol, mnRow, mnTab, aString);
-                    break;
-                case FormulaString:
-                    mpDoc->GetFormula(mnCol, mnRow, mnTab, aString);
-                    break;
-                default:
-                    break;
-            }
             rtl::OUString aCSVString(p, n, RTL_TEXTENCODING_UTF8);
+            rtl::OUString aString;
+            mpDoc->GetString(mnCol, mnRow, mnTab, aString);
+
 #if DEBUG_CSV_HANDLER
-            std::cout << "String: " << rtl::OUStringToOString(aString, RTL_TEXTENCODING_UTF8).getStr() << std::endl;
-            std::cout << "CSVString: " << rtl::OUStringToOString(aCSVString, RTL_TEXTENCODING_UTF8).getStr() << std::endl;
-            std::cout << "result: " << (int)(aCSVString == aString) << std::endl;
+                std::cout << "String: " << rtl::OUStringToOString(aString, RTL_TEXTENCODING_UTF8).getStr() << std::endl;
+                std::cout << "CSVString: " << rtl::OUStringToOString(aCSVString, RTL_TEXTENCODING_UTF8).getStr() << std::endl;
+                std::cout << "result: " << (int)(aCSVString == aString) << std::endl;
 #endif //DEBUG_CSV_HANDLER
 
             CPPUNIT_ASSERT_MESSAGE("content is not correct in cell", aString == aCSVString);
         }
         else
         {
-            double aValue;
-            mpDoc->GetValue(mnCol, mnRow, mnTab, aValue);
-            CPPUNIT_ASSERT_MESSAGE("content is not correct in cell", aValue == nValue);
+            char* pRemainingChars = NULL;
+            std::string aStr(p, n);
+            double nValue = strtod(&aStr[0], &pRemainingChars);
+            if (*pRemainingChars)
+            {
+                rtl::OUString aString;
+                switch (maStringType)
+                {
+                    case StringValue:
+                        mpDoc->GetString(mnCol, mnRow, mnTab, aString);
+                        break;
+                    case FormulaValue:
+                        mpDoc->GetFormula(mnCol, mnRow, mnTab, aString);
+                        break;
+                    default:
+                        break;
+                }
+                rtl::OUString aCSVString(p, n, RTL_TEXTENCODING_UTF8);
+#if DEBUG_CSV_HANDLER
+                std::cout << "String: " << rtl::OUStringToOString(aString, RTL_TEXTENCODING_UTF8).getStr() << std::endl;
+                std::cout << "CSVString: " << rtl::OUStringToOString(aCSVString, RTL_TEXTENCODING_UTF8).getStr() << std::endl;
+                std::cout << "result: " << (int)(aCSVString == aString) << std::endl;
+#endif //DEBUG_CSV_HANDLER
+
+                CPPUNIT_ASSERT_MESSAGE("content is not correct in cell", aString == aCSVString);
+            }
+            else
+            {
+                double aValue;
+                mpDoc->GetValue(mnCol, mnRow, mnTab, aValue);
+#if DEBUG_CSV_HANDLER
+                std::cout << "Value: " << aValue << std::endl;
+                std::cout << "CSVValue: " << nValue << std::endl;
+                std::cout << "result: " << (int)(aValue == nValue) << std::endl;
+#endif //DEBUG_CSV_HANDLER
+                CPPUNIT_ASSERT_MESSAGE("content is not correct in cell", aValue == nValue);
+            }
         }
         ++mnCol;
+
     }
 
 private:
@@ -110,3 +144,49 @@ private:
     SCTAB mnTab;
     StringType maStringType;
 };
+
+
+class conditional_format_handler
+{
+public:
+    conditional_format_handler(ScDocument* pDoc, SCTAB nTab):
+        mpDoc(pDoc),
+        mnCol(0),
+        mnRow(0),
+        mnTab(nTab) {}
+
+    void begin_parse() {}
+
+    void end_parse() {}
+
+    void begin_row() {}
+
+    void end_row()
+    {
+        ++mnRow;
+        mnCol = 0;
+    }
+
+    void cell(const char* p, size_t n)
+    {
+#if DEBUG_CSV_HANDLER
+        std::cout << "Col: " << mnCol << " Row: " << mnRow << std::endl;
+#endif //DEBUG_CSV_HANDLER
+        rtl::OUString aString = getConditionalFormatString(mpDoc, mnCol, mnRow, mnTab);
+        rtl::OUString aCSVString(p, n, RTL_TEXTENCODING_UTF8);
+#if DEBUG_CSV_HANDLER
+        std::cout << "String: " << rtl::OUStringToOString(aString, RTL_TEXTENCODING_UTF8).getStr() << std::endl;
+        std::cout << "CSVString: " << rtl::OUStringToOString(aCSVString, RTL_TEXTENCODING_UTF8).getStr() << std::endl;
+        std::cout << "result: " << (int)(aCSVString == aString) << std::endl;
+#endif //DEBUG_CSV_HANDLER
+        CPPUNIT_ASSERT_MESSAGE("", aString == aCSVString );
+        ++mnCol;
+    }
+
+private:
+    ScDocument* mpDoc;
+    SCCOL mnCol;
+    SCROW mnRow;
+    SCTAB mnTab;
+};
+


More information about the Libreoffice-commits mailing list