diff options
author | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2011-09-15 04:29:49 +0200 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2011-09-15 05:19:41 +0200 |
commit | 2b75f5908ba50dc5bcd20472ad7a6087a0b0753f (patch) | |
tree | 6f7c6a8e3b104e383917abb50be2f119b7d78068 /sc/qa | |
parent | deliver libcrmf.a (diff) | |
download | core-2b75f5908ba50dc5bcd20472ad7a6087a0b0753f.tar.gz core-2b75f5908ba50dc5bcd20472ad7a6087a0b0753f.zip |
improve calc's format unit test
bug in 'formats.ods'Sheet1.B5 with number format import
Diffstat (limited to 'sc/qa')
-rw-r--r-- | sc/qa/unit/data/contentCSV/numberFormat.csv | 10 | ||||
-rw-r--r-- | sc/qa/unit/data/ods/formats.ods | bin | 9285 -> 10521 bytes | |||
-rw-r--r-- | sc/qa/unit/filters-test.cxx | 59 | ||||
-rw-r--r-- | sc/qa/unit/helper/csv_handler.hxx | 152 |
4 files changed, 175 insertions, 46 deletions
diff --git a/sc/qa/unit/data/contentCSV/numberFormat.csv b/sc/qa/unit/data/contentCSV/numberFormat.csv index b2d13aa008a4..8120173a2fec 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 Binary files differindex cb7a29ca8a37..2fa9c134a3f3 100644 --- a/sc/qa/unit/data/ods/formats.ods +++ b/sc/qa/unit/data/ods/formats.ods diff --git a/sc/qa/unit/filters-test.cxx b/sc/qa/unit/filters-test.cxx index f50dc5a1eb1d..48bec6fedc6d 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 59436e280a86..83a8e990a786 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; +}; + |