diff options
author | Kohei Yoshida <kohei.yoshida@collabora.com> | 2014-05-01 01:14:06 -0400 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@collabora.com> | 2014-05-01 01:18:50 -0400 |
commit | 0e443b773454fa153827753812757d88eea932c5 (patch) | |
tree | 7935c2e71cc6c3fd7710d393024e0437d81a0013 | |
parent | 9a1196aae48162a456c7c56bf703a89972ade9b2 (diff) |
fdo#78079: Write test for this.
Change-Id: I3d3fc54cb433ec60d51341c3b4a077414a99a14c
-rw-r--r-- | sc/qa/unit/helper/qahelper.hxx | 37 | ||||
-rw-r--r-- | sc/qa/unit/ucalc.cxx | 74 | ||||
-rw-r--r-- | sc/qa/unit/ucalc.hxx | 2 | ||||
-rw-r--r-- | sc/qa/unit/ucalc_pivottable.cxx | 33 |
4 files changed, 114 insertions, 32 deletions
diff --git a/sc/qa/unit/helper/qahelper.hxx b/sc/qa/unit/helper/qahelper.hxx index a970f980c01f..0b93cc4f9f23 100644 --- a/sc/qa/unit/helper/qahelper.hxx +++ b/sc/qa/unit/helper/qahelper.hxx @@ -125,6 +125,43 @@ SCQAHELPER_DLLPUBLIC bool checkFormulaPosition(ScDocument& rDoc, const ScAddress SCQAHELPER_DLLPUBLIC bool checkFormulaPositions( ScDocument& rDoc, SCTAB nTab, SCCOL nCol, const SCROW* pRows, size_t nRowCount); +template<size_t _Size> +bool checkOutput(ScDocument* pDoc, const ScRange& aOutRange, const char* aOutputCheck[][_Size], const char* pCaption) +{ + bool bResult = true; + const ScAddress& s = aOutRange.aStart; + const ScAddress& e = aOutRange.aEnd; + SheetPrinter printer(e.Row() - s.Row() + 1, e.Col() - s.Col() + 1); + SCROW nOutRowSize = e.Row() - s.Row() + 1; + SCCOL nOutColSize = e.Col() - s.Col() + 1; + for (SCROW nRow = 0; nRow < nOutRowSize; ++nRow) + { + for (SCCOL nCol = 0; nCol < nOutColSize; ++nCol) + { + OUString aVal = pDoc->GetString(nCol + s.Col(), nRow + s.Row(), s.Tab()); + printer.set(nRow, nCol, aVal); + const char* p = aOutputCheck[nRow][nCol]; + if (p) + { + OUString aCheckVal = OUString::createFromAscii(p); + bool bEqual = aCheckVal.equals(aVal); + if (!bEqual) + { + cout << "Expected: " << aCheckVal << " Actual: " << aVal << endl; + bResult = false; + } + } + else if (!aVal.isEmpty()) + { + cout << "Empty cell expected" << endl; + bResult = false; + } + } + } + printer.print(pCaption); + return bResult; +} + SCQAHELPER_DLLPUBLIC void clearFormulaCellChangedFlag( ScDocument& rDoc, const ScRange& rRange ); /** diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx index 70e7f7b6a6c5..ace06b2b8058 100644 --- a/sc/qa/unit/ucalc.cxx +++ b/sc/qa/unit/ucalc.cxx @@ -4785,6 +4785,80 @@ void Test::testSort() m_pDoc->DeleteTab(0); } +void Test::testSortHorizontal() +{ + ScFormulaOptions aOptions; + aOptions.SetFormulaSepArg(";"); + aOptions.SetFormulaSepArrayCol(";"); + aOptions.SetFormulaSepArrayRow("|"); + getDocShell().SetFormulaOptions(aOptions); + + sc::AutoCalcSwitch aACSwitch(*m_pDoc, true); + m_pDoc->InsertTab(0, "Sort"); + + // Test case from fdo#78079. + + // 0 = empty cell + const char* aData[][4] = { + { "table", "has UNIQUE", "Publish to EC2", "flag" }, + { "w2gi.mobilehit", "Yes", "No", "=CONCATENATE(B2;\"-\";C2)" }, + { "w2gi.visitors", "No", "No", "=CONCATENATE(B3;\"-\";C3)" }, + { "w2gi.pagedimension", "Yes", "Yes", "=CONCATENATE(B4;\"-\";C4)" }, + }; + + // Insert raw data into A1:D4. + ScRange aDataRange = insertRangeData(m_pDoc, ScAddress(0,0,0), aData, SAL_N_ELEMENTS(aData)); + CPPUNIT_ASSERT_EQUAL(OUString("A1:D4"), aDataRange.Format(SCA_VALID)); + + // Check the formula values. + CPPUNIT_ASSERT_EQUAL(OUString("Yes-No"), m_pDoc->GetString(ScAddress(3,1,0))); + CPPUNIT_ASSERT_EQUAL(OUString("No-No"), m_pDoc->GetString(ScAddress(3,2,0))); + CPPUNIT_ASSERT_EQUAL(OUString("Yes-Yes"), m_pDoc->GetString(ScAddress(3,3,0))); + + // Define A1:D4 as sheet-local anonymous database range. + m_pDoc->SetAnonymousDBData( + 0, new ScDBData(STR_DB_LOCAL_NONAME, 0, 0, 0, 3, 3)); + + // Sort A1:D4 horizontally, ascending by row 1. + ScDBDocFunc aFunc(getDocShell()); + + ScSortParam aSortData; + aSortData.nCol1 = 0; + aSortData.nCol2 = 3; + aSortData.nRow1 = 0; + aSortData.nRow2 = 3; + aSortData.bHasHeader = true; + aSortData.bByRow = false; // Sort by column (in horizontal direction). + aSortData.bIncludePattern = true; + aSortData.maKeyState[0].bDoSort = true; + aSortData.maKeyState[0].nField = 0; + aSortData.maKeyState[0].bAscending = true; + bool bSorted = aFunc.Sort(0, aSortData, true, true, true); + CPPUNIT_ASSERT(bSorted); + + { + // Expected output table content. 0 = empty cell + const char* aOutputCheck[][4] = { + { "table", "flag", "has UNIQUE", "Publish to EC2" }, + { "w2gi.mobilehit", "Yes-No", "Yes", "No" }, + { "w2gi.visitors", "No-No", "No", "No" }, + { "w2gi.pagedimension", "Yes-Yes", "Yes", "Yes" }, + }; + + bool bSuccess = checkOutput<4>(m_pDoc, aDataRange, aOutputCheck, "Sorted by column with formula"); + CPPUNIT_ASSERT_MESSAGE("Table output check failed", bSuccess); + } + + if (!checkFormula(*m_pDoc, ScAddress(1,1,0), "CONCATENATE(C2;\"-\";D2)")) + CPPUNIT_FAIL("Wrong formula!"); + if (!checkFormula(*m_pDoc, ScAddress(1,2,0), "CONCATENATE(C3;\"-\";D3)")) + CPPUNIT_FAIL("Wrong formula!"); + if (!checkFormula(*m_pDoc, ScAddress(1,3,0), "CONCATENATE(C4;\"-\";D4)")) + CPPUNIT_FAIL("Wrong formula!"); + + m_pDoc->DeleteTab(0); +} + void Test::testSortInFormulaGroup() { static struct { diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx index c26a433160ec..2a256a18d4d8 100644 --- a/sc/qa/unit/ucalc.hxx +++ b/sc/qa/unit/ucalc.hxx @@ -322,6 +322,7 @@ public: void testFindAreaPosVertical(); void testFindAreaPosColRight(); void testSort(); + void testSortHorizontal(); void testSortWithFormulaRefs(); void testSortWithStrings(); void testSortInFormulaGroup(); @@ -478,6 +479,7 @@ public: CPPUNIT_TEST(testFindAreaPosVertical); CPPUNIT_TEST(testFindAreaPosColRight); CPPUNIT_TEST(testSort); + CPPUNIT_TEST(testSortHorizontal); CPPUNIT_TEST(testSortWithFormulaRefs); CPPUNIT_TEST(testSortWithStrings); CPPUNIT_TEST(testSortInFormulaGroup); diff --git a/sc/qa/unit/ucalc_pivottable.cxx b/sc/qa/unit/ucalc_pivottable.cxx index 85acd61acbab..5f742a1f98c0 100644 --- a/sc/qa/unit/ucalc_pivottable.cxx +++ b/sc/qa/unit/ucalc_pivottable.cxx @@ -74,38 +74,7 @@ ScRange insertDPSourceData(ScDocument* pDoc, DPFieldDef aFields[], size_t nField template<size_t _Size> bool checkDPTableOutput(ScDocument* pDoc, const ScRange& aOutRange, const char* aOutputCheck[][_Size], const char* pCaption) { - bool bResult = true; - const ScAddress& s = aOutRange.aStart; - const ScAddress& e = aOutRange.aEnd; - SheetPrinter printer(e.Row() - s.Row() + 1, e.Col() - s.Col() + 1); - SCROW nOutRowSize = e.Row() - s.Row() + 1; - SCCOL nOutColSize = e.Col() - s.Col() + 1; - for (SCROW nRow = 0; nRow < nOutRowSize; ++nRow) - { - for (SCCOL nCol = 0; nCol < nOutColSize; ++nCol) - { - OUString aVal = pDoc->GetString(nCol + s.Col(), nRow + s.Row(), s.Tab()); - printer.set(nRow, nCol, aVal); - const char* p = aOutputCheck[nRow][nCol]; - if (p) - { - OUString aCheckVal = OUString::createFromAscii(p); - bool bEqual = aCheckVal.equals(aVal); - if (!bEqual) - { - cout << "Expected: " << aCheckVal << " Actual: " << aVal << endl; - bResult = false; - } - } - else if (!aVal.isEmpty()) - { - cout << "Empty cell expected" << endl; - bResult = false; - } - } - } - printer.print(pCaption); - return bResult; + return checkOutput<_Size>(pDoc, aOutRange, aOutputCheck, pCaption); } ScDPObject* createDPFromSourceDesc( |