summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Mohrhard <markus.mohrhard@googlemail.com>2013-10-28 22:36:57 +0100
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2013-10-28 22:48:07 +0100
commit487db9ce89d53391cf45578cc42f6e7f3e67536c (patch)
treed3393be1ac8fb1efed11f98cd3fbf5a58251d5bf
parent6993eb83bdd4e934a6470dc189de4f7d43b98a80 (diff)
add ODS export test for formattings
Change-Id: I62ede554994c4448c6dff8f1a9e2ecb3075fdb46
-rw-r--r--sc/Library_scqahelper.mk3
-rw-r--r--sc/qa/unit/helper/qahelper.cxx120
-rw-r--r--sc/qa/unit/helper/qahelper.hxx2
-rw-r--r--sc/qa/unit/subsequent_export-test.cxx17
-rw-r--r--sc/qa/unit/subsequent_filters-test.cxx126
5 files changed, 144 insertions, 124 deletions
diff --git a/sc/Library_scqahelper.mk b/sc/Library_scqahelper.mk
index f0be5993cac0..4ea1f92a7bfb 100644
--- a/sc/Library_scqahelper.mk
+++ b/sc/Library_scqahelper.mk
@@ -35,6 +35,7 @@ $(eval $(call gb_Library_use_libraries,scqahelper,\
cppuhelper \
for \
sal \
+ sc \
sfx \
sot \
svl \
@@ -45,9 +46,9 @@ $(eval $(call gb_Library_use_libraries,scqahelper,\
tl \
unotest \
utl \
- sc \
ucbhelper \
unotest \
+ vcl \
$(gb_UWINAPI) \
))
diff --git a/sc/qa/unit/helper/qahelper.cxx b/sc/qa/unit/helper/qahelper.cxx
index 0de8b6b5098e..b21284654047 100644
--- a/sc/qa/unit/helper/qahelper.cxx
+++ b/sc/qa/unit/helper/qahelper.cxx
@@ -11,9 +11,13 @@
#include "csv_handler.hxx"
#include "drwlayer.hxx"
#include "compiler.hxx"
+#include "conditio.hxx"
+#include "stlsheet.hxx"
#include "formulacell.hxx"
#include "svx/svdpage.hxx"
#include "svx/svdoole2.hxx"
+#include <editeng/brushitem.hxx>
+#include <editeng/justifyitem.hxx>
#include <config_orcus.h>
@@ -161,6 +165,122 @@ void testCondFile(OUString&, ScDocument*, SCTAB) {}
#endif
+void testFormats(ScBootstrapFixture* pTest, ScDocument* pDoc, sal_Int32 nFormat)
+{
+ //test Sheet1 with csv file
+ OUString aCSVFileName;
+ pTest->createCSVPath(OUString("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_EQUAL_MESSAGE("font size should be 10", 200l, aFont.GetSize().getHeight());
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("font color should be black", COL_AUTO, aFont.GetColor().GetColor());
+ pPattern = pDoc->GetPattern(0,1,1);
+ pPattern->GetFont(aFont, SC_AUTOCOL_RAW);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("font size should be 12", 240l, aFont.GetSize().getHeight());
+ pPattern = pDoc->GetPattern(0,2,1);
+ pPattern->GetFont(aFont, SC_AUTOCOL_RAW);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("font should be italic", ITALIC_NORMAL, aFont.GetItalic());
+ pPattern = pDoc->GetPattern(0,4,1);
+ pPattern->GetFont(aFont, SC_AUTOCOL_RAW);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("font should be bold", WEIGHT_BOLD, aFont.GetWeight());
+ pPattern = pDoc->GetPattern(1,0,1);
+ pPattern->GetFont(aFont, SC_AUTOCOL_RAW);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("font should be blue", COL_BLUE, aFont.GetColor().GetColor());
+ pPattern = pDoc->GetPattern(1,1,1);
+ pPattern->GetFont(aFont, SC_AUTOCOL_RAW);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("font should be striked out with a single line", STRIKEOUT_SINGLE, aFont.GetStrikeout());
+ //some tests on sheet2 only for ods
+ if (nFormat == ODS)
+ {
+ pPattern = pDoc->GetPattern(1,2,1);
+ pPattern->GetFont(aFont, SC_AUTOCOL_RAW);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("font should be striked out with a double line", STRIKEOUT_DOUBLE, aFont.GetStrikeout());
+ pPattern = pDoc->GetPattern(1,3,1);
+ pPattern->GetFont(aFont, SC_AUTOCOL_RAW);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("font should be underlined with a dotted line", UNDERLINE_DOTTED, aFont.GetUnderline());
+ //check row height import
+ //disable for now until we figure out cause of win tinderboxes test failures
+ //CPPUNIT_ASSERT_EQUAL( static_cast<sal_uInt16>(256), pDoc->GetRowHeight(0,1) ); //0.178in
+ //CPPUNIT_ASSERT_EQUAL( static_cast<sal_uInt16>(304), pDoc->GetRowHeight(1,1) ); //0.211in
+ //CPPUNIT_ASSERT_EQUAL( static_cast<sal_uInt16>(477), pDoc->GetRowHeight(5,1) ); //0.3311in
+ //check column width import
+ CPPUNIT_ASSERT_EQUAL( static_cast<sal_uInt16>(555), pDoc->GetColWidth(4,1) ); //0.3854in
+ CPPUNIT_ASSERT_EQUAL( static_cast<sal_uInt16>(1280), pDoc->GetColWidth(5,1) ); //0.889in
+ CPPUNIT_ASSERT_EQUAL( static_cast<sal_uInt16>(4153), pDoc->GetColWidth(6,1) ); //2.8839in
+ //test case for i53253 where a cell has text with different styles and space between the text.
+ OUString aTestStr = pDoc->GetString(3,0,1);
+ OUString aKnownGoodStr("text14 space");
+ CPPUNIT_ASSERT_EQUAL( aKnownGoodStr, aTestStr );
+ //test case for cell text with line breaks.
+ aTestStr = pDoc->GetString(3,5,1);
+ aKnownGoodStr = "Hello,\nCalc!";
+ CPPUNIT_ASSERT_EQUAL( aKnownGoodStr, aTestStr );
+ }
+ 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_EQUAL_MESSAGE("cell content should be aligned centre horizontally", SVX_HOR_JUSTIFY_CENTER, eHorJustify);
+ //test alignment
+ pPattern = pDoc->GetPattern(2,1,1);
+ eHorJustify = static_cast<SvxCellHorJustify>(static_cast<const SvxHorJustifyItem&>(pPattern->GetItem(ATTR_HOR_JUSTIFY)).GetValue());
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("cell content should be aligned right horizontally", SVX_HOR_JUSTIFY_RIGHT, eHorJustify);
+ pPattern = pDoc->GetPattern(2,2,1);
+ eHorJustify = static_cast<SvxCellHorJustify>(static_cast<const SvxHorJustifyItem&>(pPattern->GetItem(ATTR_HOR_JUSTIFY)).GetValue());
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("cell content should be aligned block horizontally", SVX_HOR_JUSTIFY_BLOCK, eHorJustify);
+
+ //test Sheet3 only for ods and xlsx
+ if ( nFormat == ODS || nFormat == XLSX )
+ {
+ pTest->createCSVPath(OUString("conditionalFormatting."), aCSVFileName);
+ testCondFile(aCSVFileName, pDoc, 2);
+ // test parent cell style import ( fdo#55198 )
+ if ( nFormat == XLSX )
+ {
+ pPattern = pDoc->GetPattern(1,1,3);
+ ScStyleSheet* pStyleSheet = (ScStyleSheet*)pPattern->GetStyleSheet();
+ // check parent style name
+ OUString sExpected("Excel Built-in Date");
+ OUString sResult = pStyleSheet->GetName();
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("parent style for Sheet4.B2 is 'Excel Built-in Date'", sExpected, sResult);
+ // check align of style
+ SfxItemSet& rItemSet = pStyleSheet->GetItemSet();
+ eHorJustify = static_cast<SvxCellHorJustify>(static_cast< const SvxHorJustifyItem& >(rItemSet.Get( ATTR_HOR_JUSTIFY ) ).GetValue() );
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("'Excel Built-in Date' style should be aligned centre horizontally", SVX_HOR_JUSTIFY_CENTER, eHorJustify);
+ // check date format ( should be just month e.g. 29 )
+ sResult =pDoc->GetString( 1,1,3 );
+ sExpected = OUString("29");
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("'Excel Built-in Date' style should just display month", sExpected, sResult );
+
+ // check actual align applied to cell, should be the same as
+ // the style
+ eHorJustify = static_cast<SvxCellHorJustify>(static_cast< const SvxHorJustifyItem& >(pPattern->GetItem( ATTR_HOR_JUSTIFY ) ).GetValue() );
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("cell with 'Excel Built-in Date' style should be aligned centre horizontally", SVX_HOR_JUSTIFY_CENTER, eHorJustify);
+ }
+ }
+
+ ScConditionalFormat* pCondFormat = pDoc->GetCondFormat(0,0,2);
+ const ScRangeList& rRange = pCondFormat->GetRange();
+ CPPUNIT_ASSERT(rRange == ScRange(0,0,2,3,0,2));
+
+ pCondFormat = pDoc->GetCondFormat(0,1,2);
+ const ScRangeList& rRange2 = pCondFormat->GetRange();
+ CPPUNIT_ASSERT(rRange2 == ScRange(0,1,2,0,1,2));
+
+ pCondFormat = pDoc->GetCondFormat(1,1,2);
+ const ScRangeList& rRange3 = pCondFormat->GetRange();
+ CPPUNIT_ASSERT(rRange3 == ScRange(1,1,2,3,1,2));
+}
+
const SdrOle2Obj* getSingleChartObject(ScDocument& rDoc, sal_uInt16 nPage)
{
// Retrieve the chart object instance from the 2nd page (for the 2nd sheet).
diff --git a/sc/qa/unit/helper/qahelper.hxx b/sc/qa/unit/helper/qahelper.hxx
index 8d0f27df8004..a6d5a025e898 100644
--- a/sc/qa/unit/helper/qahelper.hxx
+++ b/sc/qa/unit/helper/qahelper.hxx
@@ -204,6 +204,8 @@ public:
#define ASSERT_EQUAL_TYPE( type, expected, result ) \
CPPUNIT_ASSERT_EQUAL( static_cast<type>(expected), static_cast<type>(result) );
+SCQAHELPER_DLLPUBLIC void testFormats(ScBootstrapFixture* pTest, ScDocument* pDoc, sal_Int32 nFormat);
+
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/qa/unit/subsequent_export-test.cxx b/sc/qa/unit/subsequent_export-test.cxx
index bd69cc1fe409..0e8ff65b0f1d 100644
--- a/sc/qa/unit/subsequent_export-test.cxx
+++ b/sc/qa/unit/subsequent_export-test.cxx
@@ -67,6 +67,7 @@ public:
void testRichTextExportODS();
void testCellValuesExportODS();
+ void testFormatExportODS();
void testInlineArrayXLS();
void testEmbeddedChartXLS();
@@ -86,6 +87,7 @@ public:
CPPUNIT_TEST(testNamedRangeBugfdo62729);
CPPUNIT_TEST(testRichTextExportODS);
CPPUNIT_TEST(testCellValuesExportODS);
+ CPPUNIT_TEST(testFormatExportODS);
CPPUNIT_TEST(testInlineArrayXLS);
CPPUNIT_TEST(testEmbeddedChartXLS);
CPPUNIT_TEST(testFormulaReferenceXLS);
@@ -264,6 +266,21 @@ void ScExportTest::testDataBarExportODS()
xDocSh->DoClose();
}
+void ScExportTest::testFormatExportODS()
+{
+ ScDocShellRef xShell = loadDoc("formats.", ODS);
+ CPPUNIT_ASSERT(xShell.Is());
+
+ ScDocShellRef xDocSh = saveAndReload(xShell, ODS);
+ CPPUNIT_ASSERT(xDocSh.Is());
+
+ ScDocument* pDoc = xDocSh->GetDocument();
+
+ testFormats(this, pDoc, ODS);
+
+ xDocSh->DoClose();
+}
+
void ScExportTest::testDataBarExportXLSX()
{
ScDocShellRef xShell = loadDoc("databar.", XLSX);
diff --git a/sc/qa/unit/subsequent_filters-test.cxx b/sc/qa/unit/subsequent_filters-test.cxx
index bd789b4276db..4d1fd609725c 100644
--- a/sc/qa/unit/subsequent_filters-test.cxx
+++ b/sc/qa/unit/subsequent_filters-test.cxx
@@ -546,126 +546,6 @@ void ScFiltersTest::testDatabaseRangesXLSX()
xDocSh->DoClose();
}
-namespace {
-
-void testFormats_Impl(ScFiltersTest* pFiltersTest, ScDocument* pDoc, sal_Int32 nFormat)
-{
- //test Sheet1 with csv file
- OUString aCSVFileName;
- pFiltersTest->createCSVPath(OUString("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_EQUAL_MESSAGE("font size should be 10", 200l, aFont.GetSize().getHeight());
- CPPUNIT_ASSERT_EQUAL_MESSAGE("font color should be black", COL_AUTO, aFont.GetColor().GetColor());
- pPattern = pDoc->GetPattern(0,1,1);
- pPattern->GetFont(aFont, SC_AUTOCOL_RAW);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("font size should be 12", 240l, aFont.GetSize().getHeight());
- pPattern = pDoc->GetPattern(0,2,1);
- pPattern->GetFont(aFont, SC_AUTOCOL_RAW);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("font should be italic", ITALIC_NORMAL, aFont.GetItalic());
- pPattern = pDoc->GetPattern(0,4,1);
- pPattern->GetFont(aFont, SC_AUTOCOL_RAW);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("font should be bold", WEIGHT_BOLD, aFont.GetWeight());
- pPattern = pDoc->GetPattern(1,0,1);
- pPattern->GetFont(aFont, SC_AUTOCOL_RAW);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("font should be blue", COL_BLUE, aFont.GetColor().GetColor());
- pPattern = pDoc->GetPattern(1,1,1);
- pPattern->GetFont(aFont, SC_AUTOCOL_RAW);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("font should be striked out with a single line", STRIKEOUT_SINGLE, aFont.GetStrikeout());
- //some tests on sheet2 only for ods
- if (nFormat == ODS)
- {
- pPattern = pDoc->GetPattern(1,2,1);
- pPattern->GetFont(aFont, SC_AUTOCOL_RAW);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("font should be striked out with a double line", STRIKEOUT_DOUBLE, aFont.GetStrikeout());
- pPattern = pDoc->GetPattern(1,3,1);
- pPattern->GetFont(aFont, SC_AUTOCOL_RAW);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("font should be underlined with a dotted line", UNDERLINE_DOTTED, aFont.GetUnderline());
- //check row height import
- //disable for now until we figure out cause of win tinderboxes test failures
- //CPPUNIT_ASSERT_EQUAL( static_cast<sal_uInt16>(256), pDoc->GetRowHeight(0,1) ); //0.178in
- //CPPUNIT_ASSERT_EQUAL( static_cast<sal_uInt16>(304), pDoc->GetRowHeight(1,1) ); //0.211in
- //CPPUNIT_ASSERT_EQUAL( static_cast<sal_uInt16>(477), pDoc->GetRowHeight(5,1) ); //0.3311in
- //check column width import
- CPPUNIT_ASSERT_EQUAL( static_cast<sal_uInt16>(555), pDoc->GetColWidth(4,1) ); //0.3854in
- CPPUNIT_ASSERT_EQUAL( static_cast<sal_uInt16>(1280), pDoc->GetColWidth(5,1) ); //0.889in
- CPPUNIT_ASSERT_EQUAL( static_cast<sal_uInt16>(4153), pDoc->GetColWidth(6,1) ); //2.8839in
- //test case for i53253 where a cell has text with different styles and space between the text.
- OUString aTestStr = pDoc->GetString(3,0,1);
- OUString aKnownGoodStr("text14 space");
- CPPUNIT_ASSERT_EQUAL( aKnownGoodStr, aTestStr );
- //test case for cell text with line breaks.
- aTestStr = pDoc->GetString(3,5,1);
- aKnownGoodStr = "Hello,\nCalc!";
- CPPUNIT_ASSERT_EQUAL( aKnownGoodStr, aTestStr );
- }
- 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_EQUAL_MESSAGE("cell content should be aligned centre horizontally", SVX_HOR_JUSTIFY_CENTER, eHorJustify);
- //test alignment
- pPattern = pDoc->GetPattern(2,1,1);
- eHorJustify = static_cast<SvxCellHorJustify>(static_cast<const SvxHorJustifyItem&>(pPattern->GetItem(ATTR_HOR_JUSTIFY)).GetValue());
- CPPUNIT_ASSERT_EQUAL_MESSAGE("cell content should be aligned right horizontally", SVX_HOR_JUSTIFY_RIGHT, eHorJustify);
- pPattern = pDoc->GetPattern(2,2,1);
- eHorJustify = static_cast<SvxCellHorJustify>(static_cast<const SvxHorJustifyItem&>(pPattern->GetItem(ATTR_HOR_JUSTIFY)).GetValue());
- CPPUNIT_ASSERT_EQUAL_MESSAGE("cell content should be aligned block horizontally", SVX_HOR_JUSTIFY_BLOCK, eHorJustify);
-
- //test Sheet3 only for ods
- if ( nFormat == ODS || nFormat == XLSX )
- {
- pFiltersTest->createCSVPath(OUString("conditionalFormatting."), aCSVFileName);
- testCondFile(aCSVFileName, pDoc, 2);
- // test parent cell style import ( fdo#55198 )
- if ( nFormat == XLSX )
- {
- pPattern = pDoc->GetPattern(1,1,3);
- ScStyleSheet* pStyleSheet = (ScStyleSheet*)pPattern->GetStyleSheet();
- // check parent style name
- OUString sExpected("Excel Built-in Date");
- OUString sResult = pStyleSheet->GetName();
- CPPUNIT_ASSERT_EQUAL_MESSAGE("parent style for Sheet4.B2 is 'Excel Built-in Date'", sExpected, sResult);
- // check align of style
- SfxItemSet& rItemSet = pStyleSheet->GetItemSet();
- eHorJustify = static_cast<SvxCellHorJustify>(static_cast< const SvxHorJustifyItem& >(rItemSet.Get( ATTR_HOR_JUSTIFY ) ).GetValue() );
- CPPUNIT_ASSERT_EQUAL_MESSAGE("'Excel Built-in Date' style should be aligned centre horizontally", SVX_HOR_JUSTIFY_CENTER, eHorJustify);
- // check date format ( should be just month e.g. 29 )
- sResult =pDoc->GetString( 1,1,3 );
- sExpected = OUString("29");
- CPPUNIT_ASSERT_EQUAL_MESSAGE("'Excel Built-in Date' style should just display month", sExpected, sResult );
-
- // check actual align applied to cell, should be the same as
- // the style
- eHorJustify = static_cast<SvxCellHorJustify>(static_cast< const SvxHorJustifyItem& >(pPattern->GetItem( ATTR_HOR_JUSTIFY ) ).GetValue() );
- CPPUNIT_ASSERT_EQUAL_MESSAGE("cell with 'Excel Built-in Date' style should be aligned centre horizontally", SVX_HOR_JUSTIFY_CENTER, eHorJustify);
- }
- }
-
- ScConditionalFormat* pCondFormat = pDoc->GetCondFormat(0,0,2);
- const ScRangeList& rRange = pCondFormat->GetRange();
- CPPUNIT_ASSERT(rRange == ScRange(0,0,2,3,0,2));
-
- pCondFormat = pDoc->GetCondFormat(0,1,2);
- const ScRangeList& rRange2 = pCondFormat->GetRange();
- CPPUNIT_ASSERT(rRange2 == ScRange(0,1,2,0,1,2));
-
- pCondFormat = pDoc->GetCondFormat(1,1,2);
- const ScRangeList& rRange3 = pCondFormat->GetRange();
- CPPUNIT_ASSERT(rRange3 == ScRange(1,1,2,3,1,2));
-}
-
-}
-
void ScFiltersTest::testFormatsODS()
{
ScDocShellRef xDocSh = loadDoc("formats.", ODS);
@@ -673,7 +553,7 @@ void ScFiltersTest::testFormatsODS()
ScDocument* pDoc = xDocSh->GetDocument();
- testFormats_Impl(this, pDoc, ODS);
+ testFormats(this, pDoc, ODS);
xDocSh->DoClose();
}
@@ -684,7 +564,7 @@ void ScFiltersTest::testFormatsXLS()
ScDocument* pDoc = xDocSh->GetDocument();
- testFormats_Impl(this, pDoc, XLS);
+ testFormats(this, pDoc, XLS);
xDocSh->DoClose();
}
@@ -695,7 +575,7 @@ void ScFiltersTest::testFormatsXLSX()
ScDocument* pDoc = xDocSh->GetDocument();
- testFormats_Impl(this, pDoc, XLSX);
+ testFormats(this, pDoc, XLSX);
xDocSh->DoClose();
}