diff options
author | Kohei Yoshida <kohei.yoshida@collabora.com> | 2014-10-26 14:43:47 -0700 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@collabora.com> | 2014-10-26 14:45:59 -0700 |
commit | ae5ac4807cab26de2a149162576d2ef927cc8326 (patch) | |
tree | fe6a91bc79d88a2ce03229198a3a85ab5f53864d /sc | |
parent | 10fc138307afb4b39baddb0d56eb8e986e5d29ea (diff) |
fdo#85215: Write test for this.
Change-Id: Ibe959201541ce6ad84540eba93ac9235dca91f40
Diffstat (limited to 'sc')
-rw-r--r-- | sc/qa/unit/ucalc.hxx | 2 | ||||
-rw-r--r-- | sc/qa/unit/ucalc_sort.cxx | 108 |
2 files changed, 110 insertions, 0 deletions
diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx index 472779cdc675..9eaa7092b0f3 100644 --- a/sc/qa/unit/ucalc.hxx +++ b/sc/qa/unit/ucalc.hxx @@ -364,6 +364,7 @@ public: void testSortRefUpdate3(); void testSortRefUpdate4(); void testSortRefUpdate5(); + void testSortRefUpdate6(); void testSortOutOfPlaceResult(); void testSortPartialFormulaGroup(); @@ -555,6 +556,7 @@ public: CPPUNIT_TEST(testSortRefUpdate3); CPPUNIT_TEST(testSortRefUpdate4); CPPUNIT_TEST(testSortRefUpdate5); + CPPUNIT_TEST(testSortRefUpdate6); CPPUNIT_TEST(testSortOutOfPlaceResult); CPPUNIT_TEST(testSortPartialFormulaGroup); CPPUNIT_TEST(testShiftCells); diff --git a/sc/qa/unit/ucalc_sort.cxx b/sc/qa/unit/ucalc_sort.cxx index ce6b9b3304bf..d0997c350131 100644 --- a/sc/qa/unit/ucalc_sort.cxx +++ b/sc/qa/unit/ucalc_sort.cxx @@ -1329,6 +1329,114 @@ void Test::testSortRefUpdate5() m_pDoc->DeleteTab(0); } +void Test::testSortRefUpdate6() +{ + SortRefNoUpdateSetter aUpdateSet; + + sc::AutoCalcSwitch aACSwitch(*m_pDoc, true); // turn auto calc on. + m_pDoc->InsertTab(0, "Sort"); + + const char* aData[][3] = { + { "Order", "Value", "1" }, + { "9", "1", "=C1+B2" }, + { "1", "2", "=C2+B3" }, + { "8", "3", "=C3+B4" }, + }; + + ScAddress aPos(0,0,0); + ScRange aDataRange = insertRangeData(m_pDoc, aPos, aData, SAL_N_ELEMENTS(aData)); + CPPUNIT_ASSERT(aDataRange.aStart == aPos); + + { + // Expected output table content. 0 = empty cell + const char* aOutputCheck[][3] = { + { "Order", "Value", "1" }, + { "9", "1", "2" }, + { "1", "2", "4" }, + { "8", "3", "7" }, + }; + + bool bSuccess = checkOutput<3>(m_pDoc, aDataRange, aOutputCheck, "Initial value"); + CPPUNIT_ASSERT_MESSAGE("Table output check failed", bSuccess); + } + + ScDBDocFunc aFunc(getDocShell()); + + // Sort A1:C4. + m_pDoc->SetAnonymousDBData( + 0, new ScDBData(STR_DB_LOCAL_NONAME, 0, 0, 0, 2, 3)); + + // Sort A1:A6 by column A (with a row header). + ScSortParam aSortData; + aSortData.nCol1 = 0; + aSortData.nCol2 = 2; + aSortData.nRow1 = 0; + aSortData.nRow2 = 3; + aSortData.bHasHeader = 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[][3] = { + { "Order", "Value", "1" }, + { "1", "2", "3" }, + { "8", "3", "6" }, + { "9", "1", "7" }, + }; + + bool bSuccess = checkOutput<3>(m_pDoc, aDataRange, aOutputCheck, "Sorted without reference update"); + CPPUNIT_ASSERT_MESSAGE("Table output check failed", bSuccess); + } + + // Make sure that the formulas in C2:C4 are not adjusted. + if (!checkFormula(*m_pDoc, ScAddress(2,1,0), "C1+B2")) + CPPUNIT_FAIL("Wrong formula!"); + if (!checkFormula(*m_pDoc, ScAddress(2,2,0), "C2+B3")) + CPPUNIT_FAIL("Wrong formula!"); + if (!checkFormula(*m_pDoc, ScAddress(2,3,0), "C3+B4")) + CPPUNIT_FAIL("Wrong formula!"); + + // Undo and check. + SfxUndoManager* pUndoMgr = m_pDoc->GetUndoManager(); + CPPUNIT_ASSERT(pUndoMgr); + + pUndoMgr->Undo(); + + { + // Expected output table content. 0 = empty cell + const char* aOutputCheck[][3] = { + { "Order", "Value", "1" }, + { "9", "1", "2" }, + { "1", "2", "4" }, + { "8", "3", "7" }, + }; + + bool bSuccess = checkOutput<3>(m_pDoc, aDataRange, aOutputCheck, "After undo"); + CPPUNIT_ASSERT_MESSAGE("Table output check failed", bSuccess); + } + + // Redo and check. + pUndoMgr->Redo(); + { + // Expected output table content. 0 = empty cell + const char* aOutputCheck[][3] = { + { "Order", "Value", "1" }, + { "1", "2", "3" }, + { "8", "3", "6" }, + { "9", "1", "7" }, + }; + + bool bSuccess = checkOutput<3>(m_pDoc, aDataRange, aOutputCheck, "Sorted without reference update"); + CPPUNIT_ASSERT_MESSAGE("Table output check failed", bSuccess); + } + + m_pDoc->DeleteTab(0); +} + void Test::testSortOutOfPlaceResult() { m_pDoc->InsertTab(0, "Sort"); |