diff options
author | Xisco Fauli <xiscofauli@libreoffice.org> | 2022-11-16 13:10:01 +0100 |
---|---|---|
committer | Xisco Fauli <xiscofauli@libreoffice.org> | 2022-11-16 15:54:09 +0100 |
commit | d6ed1e058975f94aa0b79428f4d735095a68c74a (patch) | |
tree | fbe6b33ff8af7e552ff97c4bbfbc4bff477b5f2b | |
parent | 7c43a3ad40d394ac60d269c12c3d84f588442c83 (diff) |
sc: move filter tests where they belong. (part 1)
it reduces duplicated code
Change-Id: Iba4898e414b87c962b3e923c8c0cf8ca12434167
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142765
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
-rw-r--r-- | sc/qa/unit/filters-test.cxx | 196 | ||||
-rw-r--r-- | sc/qa/unit/subsequent_filters_test.cxx | 162 |
2 files changed, 162 insertions, 196 deletions
diff --git a/sc/qa/unit/filters-test.cxx b/sc/qa/unit/filters-test.cxx index 88fec15dab14..854f689b1a6f 100644 --- a/sc/qa/unit/filters-test.cxx +++ b/sc/qa/unit/filters-test.cxx @@ -59,17 +59,7 @@ public: void testCVEs(); //ods, xls, xlsx filter tests - void testRangeNameODS(); // only test ods here, xls and xlsx in subsequent_filters-test - void testContentODS(); - void testContentXLS(); - void testContentXLSX(); - void testContentXLSXStrict(); // strict OOXML - void testContentLotus123(); void testContentofz9704(); - void testContentDIF(); - void testContentXLSB(); - void testContentXLS_XML(); - void testContentGnumeric(); void testSharedFormulaXLS(); void testSharedFormulaXLSX(); void testSharedFormulaRefUpdateXLSX(); @@ -88,17 +78,7 @@ public: CPPUNIT_TEST_SUITE(ScFiltersTest); CPPUNIT_TEST(testCVEs); - CPPUNIT_TEST(testRangeNameODS); - CPPUNIT_TEST(testContentODS); - CPPUNIT_TEST(testContentXLS); - CPPUNIT_TEST(testContentXLSX); - CPPUNIT_TEST(testContentXLSXStrict); - CPPUNIT_TEST(testContentLotus123); CPPUNIT_TEST(testContentofz9704); - CPPUNIT_TEST(testContentDIF); - CPPUNIT_TEST(testContentXLSB); - CPPUNIT_TEST(testContentXLS_XML); - CPPUNIT_TEST(testContentGnumeric); CPPUNIT_TEST(testSharedFormulaXLS); CPPUNIT_TEST(testSharedFormulaXLSX); CPPUNIT_TEST(testSharedFormulaRefUpdateXLSX); @@ -162,147 +142,6 @@ void ScFiltersTest::testCVEs() #endif } -namespace { - -void testRangeNameImpl(const ScDocument& rDoc) -{ - //check one range data per sheet and one global more detailed - //add some more checks here - ScRangeData* pRangeData = rDoc.GetRangeName()->findByUpperName(OUString("GLOBAL1")); - CPPUNIT_ASSERT_MESSAGE("range name Global1 not found", pRangeData); - double aValue = rDoc.GetValue(1,0,0); - ASSERT_DOUBLES_EQUAL_MESSAGE("range name Global1 should reference Sheet1.A1", 1.0, aValue); - pRangeData = rDoc.GetRangeName(0)->findByUpperName(OUString("LOCAL1")); - CPPUNIT_ASSERT_MESSAGE("range name Sheet1.Local1 not found", pRangeData); - aValue = rDoc.GetValue(1,2,0); - ASSERT_DOUBLES_EQUAL_MESSAGE("range name Sheet1.Local1 should reference Sheet1.A3", 3.0, aValue); - pRangeData = rDoc.GetRangeName(1)->findByUpperName(OUString("LOCAL2")); - CPPUNIT_ASSERT_MESSAGE("range name Sheet2.Local2 not found", pRangeData); - //check for correct results for the remaining formulas - aValue = rDoc.GetValue(1,1,0); - ASSERT_DOUBLES_EQUAL_MESSAGE("=global2 should be 2", 2.0, aValue); - aValue = rDoc.GetValue(1,3,0); - ASSERT_DOUBLES_EQUAL_MESSAGE("=local2 should be 4", 4.0, aValue); - aValue = rDoc.GetValue(2,0,0); - ASSERT_DOUBLES_EQUAL_MESSAGE("=SUM(global3) should be 10", 10.0, aValue); -} - -} - -void ScFiltersTest::testRangeNameODS() -{ - ScDocShellRef xDocSh = loadDoc(u"named-ranges-global.", FORMAT_ODS); - - xDocSh->DoHardRecalc(); - - ScDocument& rDoc = xDocSh->GetDocument(); - testRangeNameImpl(rDoc); - - OUString aCSVPath; - createCSVPath( "rangeExp_Sheet2.", aCSVPath ); - testFile( aCSVPath, rDoc, 1); - xDocSh->DoClose(); -} - -namespace { - -void testContentImpl(ScDocument& rDoc, sal_Int32 nFormat ) //same code for ods, xls, xlsx -{ - double fValue; - //check value import - fValue = rDoc.GetValue(0,0,0); - ASSERT_DOUBLES_EQUAL_MESSAGE("value not imported correctly", 1.0, fValue); - fValue = rDoc.GetValue(0,1,0); - ASSERT_DOUBLES_EQUAL_MESSAGE("value not imported correctly", 2.0, fValue); - OUString aString = rDoc.GetString(1, 0, 0); - - //check string import - CPPUNIT_ASSERT_EQUAL_MESSAGE("string imported not correctly", OUString("String1"), aString); - aString = rDoc.GetString(1, 1, 0); - CPPUNIT_ASSERT_EQUAL_MESSAGE("string not imported correctly", OUString("String2"), aString); - - //check basic formula import - // in case of DIF it just contains values - fValue = rDoc.GetValue(2,0,0); - ASSERT_DOUBLES_EQUAL_MESSAGE("=2*3", 6.0, fValue); - fValue = rDoc.GetValue(2,1,0); - ASSERT_DOUBLES_EQUAL_MESSAGE("=2+3", 5.0, fValue); - fValue = rDoc.GetValue(2,2,0); - ASSERT_DOUBLES_EQUAL_MESSAGE("=2-3", -1.0, fValue); - fValue = rDoc.GetValue(2,3,0); - ASSERT_DOUBLES_EQUAL_MESSAGE("=C1+C2", 11.0, fValue); - - //check merged cells import - if (nFormat != FORMAT_LOTUS123 && nFormat != FORMAT_DIF && nFormat != FORMAT_XLS_XML - && nFormat != FORMAT_GNUMERIC) - { - SCCOL nCol = 4; - SCROW nRow = 1; - rDoc.ExtendMerge(4, 1, nCol, nRow, 0); - CPPUNIT_ASSERT_EQUAL_MESSAGE("merged cells are not imported", SCCOL(5), nCol); - CPPUNIT_ASSERT_EQUAL_MESSAGE("merged cells are not imported", SCROW(2), nRow); - - //check notes import - ScAddress aAddress(7, 2, 0); - ScPostIt* pNote = rDoc.GetNote(aAddress); - CPPUNIT_ASSERT_MESSAGE("note not imported", pNote); - CPPUNIT_ASSERT_EQUAL_MESSAGE("note text not imported correctly", OUString("Test"), pNote->GetText() ); - } - - //add additional checks here -} - -} - -void ScFiltersTest::testContentODS() -{ - ScDocShellRef xDocSh = loadDoc(u"universal-content.", FORMAT_ODS); - xDocSh->DoHardRecalc(); - - ScDocument& rDoc = xDocSh->GetDocument(); - testContentImpl(rDoc, FORMAT_ODS); - xDocSh->DoClose(); -} - -void ScFiltersTest::testContentXLS() -{ - ScDocShellRef xDocSh = loadDoc(u"universal-content.", FORMAT_XLS); - xDocSh->DoHardRecalc(); - - ScDocument& rDoc = xDocSh->GetDocument(); - testContentImpl(rDoc, FORMAT_XLS); - xDocSh->DoClose(); -} - -void ScFiltersTest::testContentXLSX() -{ - ScDocShellRef xDocSh = loadDoc(u"universal-content.", FORMAT_XLSX); - xDocSh->DoHardRecalc(); - - ScDocument& rDoc = xDocSh->GetDocument(); - testContentImpl(rDoc, FORMAT_XLSX); - xDocSh->DoClose(); -} - -void ScFiltersTest::testContentXLSXStrict() -{ - ScDocShellRef xDocSh = loadDoc(u"universal-content-strict.", FORMAT_XLSX); - xDocSh->DoHardRecalc(); - - ScDocument& rDoc = xDocSh->GetDocument(); - testContentImpl(rDoc, FORMAT_XLSX); - xDocSh->DoClose(); -} - -void ScFiltersTest::testContentLotus123() -{ - ScDocShellRef xDocSh = loadDoc(u"universal-content.", FORMAT_LOTUS123); - xDocSh->DoHardRecalc(); - - ScDocument& rDoc = xDocSh->GetDocument(); - testContentImpl(rDoc, FORMAT_LOTUS123); - xDocSh->DoClose(); -} void ScFiltersTest::testContentofz9704() { @@ -312,41 +151,6 @@ void ScFiltersTest::testContentofz9704() TestImportWKS(aFileStream); } -void ScFiltersTest::testContentDIF() -{ - ScDocShellRef xDocSh = loadDoc(u"universal-content.", FORMAT_DIF); - - xDocSh->DoClose(); -} - -void ScFiltersTest::testContentXLSB() -{ - ScDocShellRef xDocSh = loadDoc(u"universal-content.", FORMAT_XLSB); - xDocSh->DoHardRecalc(); - - ScDocument& rDoc = xDocSh->GetDocument(); - testContentImpl(rDoc, FORMAT_XLSB); - xDocSh->DoClose(); -} - -void ScFiltersTest::testContentXLS_XML() -{ - ScDocShellRef xDocSh = loadDoc(u"universal-content.", FORMAT_XLS_XML); - - ScDocument& rDoc = xDocSh->GetDocument(); - testContentImpl(rDoc, FORMAT_XLS_XML); - xDocSh->DoClose(); -} - -void ScFiltersTest::testContentGnumeric() -{ - ScDocShellRef xDocSh = loadDoc(u"universal-content.", FORMAT_GNUMERIC); - - ScDocument& rDoc = xDocSh->GetDocument(); - testContentImpl(rDoc, FORMAT_GNUMERIC); - xDocSh->DoClose(); -} - void ScFiltersTest::testSharedFormulaXLS() { ScDocShellRef xDocSh = loadDoc(u"shared-formula/basic.", FORMAT_XLS); diff --git a/sc/qa/unit/subsequent_filters_test.cxx b/sc/qa/unit/subsequent_filters_test.cxx index e39fe0fd3431..6874b7223076 100644 --- a/sc/qa/unit/subsequent_filters_test.cxx +++ b/sc/qa/unit/subsequent_filters_test.cxx @@ -44,6 +44,7 @@ #include <stlpool.hxx> #include <detfunc.hxx> #include <cellmergeoption.hxx> +#include <postit.hxx> #include <sortparam.hxx> #include <undomanager.hxx> @@ -71,6 +72,15 @@ public: ScFiltersTest(); //ods, xls, xlsx filter tests + void testContentODS(); + void testContentXLS(); + void testContentXLSX(); + void testContentXLSXStrict(); // strict OOXML + void testContentLotus123(); + void testContentDIF(); + void testContentXLSB(); + void testContentXLS_XML(); + void testContentGnumeric(); void testCondFormatOperatorsSameRangeXLSX(); void testTdf150452(); void testTdf119292(); @@ -87,6 +97,7 @@ public: void testRangeNameXLS(); void testRangeNameLocalXLS(); void testRangeNameXLSX(); + void testRangeNameODS(); void testHyperlinksXLSX(); void testHardRecalcODS(); void testFunctionsODS(); @@ -180,6 +191,15 @@ public: void testTdf144758_DBDataDefaultOrientation(); CPPUNIT_TEST_SUITE(ScFiltersTest); + CPPUNIT_TEST(testContentODS); + CPPUNIT_TEST(testContentXLS); + CPPUNIT_TEST(testContentXLSX); + CPPUNIT_TEST(testContentXLSXStrict); + CPPUNIT_TEST(testContentLotus123); + CPPUNIT_TEST(testContentDIF); + CPPUNIT_TEST(testContentXLSB); + CPPUNIT_TEST(testContentXLS_XML); + CPPUNIT_TEST(testContentGnumeric); CPPUNIT_TEST(testCondFormatOperatorsSameRangeXLSX); CPPUNIT_TEST(testTdf150452); CPPUNIT_TEST(testTdf119292); @@ -196,6 +216,7 @@ public: CPPUNIT_TEST(testRangeNameXLS); CPPUNIT_TEST(testRangeNameLocalXLS); CPPUNIT_TEST(testRangeNameXLSX); + CPPUNIT_TEST(testRangeNameODS); CPPUNIT_TEST(testHyperlinksXLSX); CPPUNIT_TEST(testHardRecalcODS); CPPUNIT_TEST(testFunctionsODS); @@ -320,6 +341,133 @@ void testRangeNameImpl(const ScDocument& rDoc) CPPUNIT_ASSERT_EQUAL_MESSAGE( "formula Global5 should reference Global6 ( which is evaluated as local1 )", 5.0, aValue); } + +void testContentImpl(ScDocument& rDoc, bool bCheckMergedCells) +{ + double fValue; + //check value import + fValue = rDoc.GetValue(0, 0, 0); + ASSERT_DOUBLES_EQUAL_MESSAGE("value not imported correctly", 1.0, fValue); + fValue = rDoc.GetValue(0, 1, 0); + ASSERT_DOUBLES_EQUAL_MESSAGE("value not imported correctly", 2.0, fValue); + OUString aString = rDoc.GetString(1, 0, 0); + + //check string import + CPPUNIT_ASSERT_EQUAL_MESSAGE("string imported not correctly", OUString("String1"), aString); + aString = rDoc.GetString(1, 1, 0); + CPPUNIT_ASSERT_EQUAL_MESSAGE("string not imported correctly", OUString("String2"), aString); + + //check basic formula import + // in case of DIF it just contains values + fValue = rDoc.GetValue(2, 0, 0); + ASSERT_DOUBLES_EQUAL_MESSAGE("=2*3", 6.0, fValue); + fValue = rDoc.GetValue(2, 1, 0); + ASSERT_DOUBLES_EQUAL_MESSAGE("=2+3", 5.0, fValue); + fValue = rDoc.GetValue(2, 2, 0); + ASSERT_DOUBLES_EQUAL_MESSAGE("=2-3", -1.0, fValue); + fValue = rDoc.GetValue(2, 3, 0); + ASSERT_DOUBLES_EQUAL_MESSAGE("=C1+C2", 11.0, fValue); + + //check merged cells import + if (bCheckMergedCells) + { + SCCOL nCol = 4; + SCROW nRow = 1; + rDoc.ExtendMerge(4, 1, nCol, nRow, 0); + CPPUNIT_ASSERT_EQUAL_MESSAGE("merged cells are not imported", SCCOL(5), nCol); + CPPUNIT_ASSERT_EQUAL_MESSAGE("merged cells are not imported", SCROW(2), nRow); + + //check notes import + ScAddress aAddress(7, 2, 0); + ScPostIt* pNote = rDoc.GetNote(aAddress); + CPPUNIT_ASSERT_MESSAGE("note not imported", pNote); + CPPUNIT_ASSERT_EQUAL_MESSAGE("note text not imported correctly", OUString("Test"), + pNote->GetText()); + } + + //add additional checks here +} +} + +void ScFiltersTest::testContentODS() +{ + createScDoc("ods/universal-content.ods"); + ScDocShell* pDocSh = getScDocShell(); + pDocSh->DoHardRecalc(); + + testContentImpl(*getScDoc(), true); +} + +void ScFiltersTest::testContentXLS() +{ + createScDoc("xls/universal-content.xls"); + ScDocShell* pDocSh = getScDocShell(); + pDocSh->DoHardRecalc(); + + testContentImpl(*getScDoc(), true); +} + +void ScFiltersTest::testContentXLSX() +{ + createScDoc("xlsx/universal-content.xlsx"); + ScDocShell* pDocSh = getScDocShell(); + pDocSh->DoHardRecalc(); + + testContentImpl(*getScDoc(), true); +} + +void ScFiltersTest::testContentXLSXStrict() +{ + createScDoc("xlsx/universal-content-strict.xlsx"); + ScDocShell* pDocSh = getScDocShell(); + pDocSh->DoHardRecalc(); + + testContentImpl(*getScDoc(), true); +} + +void ScFiltersTest::testContentLotus123() +{ + createScDoc("123/universal-content.123"); + ScDocShell* pDocSh = getScDocShell(); + pDocSh->DoHardRecalc(); + + testContentImpl(*getScDoc(), false); +} + +void ScFiltersTest::testContentDIF() +{ + createScDoc("dif/universal-content.dif"); + ScDocShell* pDocSh = getScDocShell(); + pDocSh->DoHardRecalc(); + + testContentImpl(*getScDoc(), false); +} + +void ScFiltersTest::testContentXLSB() +{ + createScDoc("xlsb/universal-content.xlsb"); + ScDocShell* pDocSh = getScDocShell(); + pDocSh->DoHardRecalc(); + + testContentImpl(*getScDoc(), true); +} + +void ScFiltersTest::testContentXLS_XML() +{ + createScDoc("xml/universal-content.xml"); + ScDocShell* pDocSh = getScDocShell(); + pDocSh->DoHardRecalc(); + + testContentImpl(*getScDoc(), false); +} + +void ScFiltersTest::testContentGnumeric() +{ + createScDoc("gnumeric/universal-content.gnumeric"); + ScDocShell* pDocSh = getScDocShell(); + pDocSh->DoHardRecalc(); + + testContentImpl(*getScDoc(), false); } void ScFiltersTest::testCondFormatOperatorsSameRangeXLSX() @@ -684,6 +832,20 @@ void ScFiltersTest::testRangeNameXLSX() testRangeNameImpl(*pDoc); } +void ScFiltersTest::testRangeNameODS() +{ + createScDoc("ods/named-ranges-global.ods"); + + ScDocShell* pDocSh = getScDocShell(); + pDocSh->DoHardRecalc(); + + ScDocument* pDoc = getScDoc(); + testRangeNameImpl(*pDoc); + + OUString aCSVPath = createFilePath(u"contentCSV/rangeExp_Sheet2.csv"); + testFile(aCSVPath, *pDoc, 1); +} + void ScFiltersTest::testHyperlinksXLSX() { createScDoc("xlsx/hyperlinks.xlsx"); |