diff options
author | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2012-02-11 15:23:26 +0100 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2012-02-11 17:21:59 +0100 |
commit | 8fab50dcb2e4a011e4a68c5eaa20e06787af26ad (patch) | |
tree | 3c84d62f086df67f6d54d3165cc94ebc4b97df7b /sc/qa | |
parent | 423fb7b73673cb0fa19359bcdbe0156dcc34b01c (diff) |
refactor subsequent_filters-test and move each test into own method
Diffstat (limited to 'sc/qa')
-rw-r--r-- | sc/qa/unit/subsequent_filters-test.cxx | 325 |
1 files changed, 181 insertions, 144 deletions
diff --git a/sc/qa/unit/subsequent_filters-test.cxx b/sc/qa/unit/subsequent_filters-test.cxx index 374041e760b4..af0b159f694a 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() |