From 4f5c97849b8d4aa4a6698e9528e39570a6d47a7a Mon Sep 17 00:00:00 2001 From: Eike Rathke Date: Mon, 2 May 2016 19:14:38 +0200 Subject: unit test for tdf#99417 track formula cells for BROADCAST_BROADCASTERS Change-Id: I82cd43774388a426b4c7dc536952dc3f9584cf9e --- sc/qa/unit/ucalc.hxx | 2 ++ sc/qa/unit/ucalc_sort.cxx | 76 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx index 6896c8e6e0e9..028c342419b6 100644 --- a/sc/qa/unit/ucalc.hxx +++ b/sc/qa/unit/ucalc.hxx @@ -423,6 +423,7 @@ public: void testSortRefUpdate5(); void testSortRefUpdate6(); void testSortBroadcaster(); + void testSortBroadcastBroadcaster(); void testSortOutOfPlaceResult(); void testSortPartialFormulaGroup(); @@ -687,6 +688,7 @@ public: CPPUNIT_TEST(testSortRefUpdate5); CPPUNIT_TEST(testSortRefUpdate6); CPPUNIT_TEST(testSortBroadcaster); + CPPUNIT_TEST(testSortBroadcastBroadcaster); 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 b47b3a3f1c03..59293ba21a92 100644 --- a/sc/qa/unit/ucalc_sort.cxx +++ b/sc/qa/unit/ucalc_sort.cxx @@ -1695,6 +1695,82 @@ void Test::testSortBroadcaster() m_pDoc->DeleteTab(0); } +// tdf#99417 check that formulas are tracked that *only* indirectly depend on +// sorted data and no other broadcasting than BroadcastBroadcasters is +// involved (for which this test can not be included in testSortBroadcaster()). +void Test::testSortBroadcastBroadcaster() +{ + SortRefNoUpdateSetter aUpdateSet; + + sc::AutoCalcSwitch aACSwitch(*m_pDoc, true); // turn auto calc on. + m_pDoc->InsertTab(0, "Sort"); + + { + const char* aData[][3] = { + { "1", "=A1", "=B1" }, + { "2", "=A2", "=B2" }, + }; + + ScAddress aPos(0,0,0); + ScRange aDataRange = insertRangeData(m_pDoc, aPos, aData, SAL_N_ELEMENTS(aData)); + CPPUNIT_ASSERT_EQUAL(aPos, aDataRange.aStart); + + { + // Expected output table content. 0 = empty cell + const char* aOutputCheck[][3] = { + { "1", "1", "1" }, + { "2", "2", "2" }, + }; + + bool bSuccess = checkOutput<3>(m_pDoc, aDataRange, aOutputCheck, "Initial value"); + CPPUNIT_ASSERT_MESSAGE("Table output check failed", bSuccess); + } + + // Sort A1:A2. + m_pDoc->SetAnonymousDBData( + 0, new ScDBData(STR_DB_LOCAL_NONAME, 0, 0, 0, 0, 1)); + + ScDBDocFunc aFunc(getDocShell()); + + // Sort A1:A2 by column A descending. + ScSortParam aSortData; + aSortData.nCol1 = 0; + aSortData.nCol2 = 0; + aSortData.nRow1 = 0; + aSortData.nRow2 = 1; + aSortData.bHasHeader = false; + aSortData.bByRow = true; + aSortData.maKeyState[0].bDoSort = true; + aSortData.maKeyState[0].nField = 0; + aSortData.maKeyState[0].bAscending = false; + bool bSorted = aFunc.Sort(0, aSortData, true, true, true); + CPPUNIT_ASSERT(bSorted); + + { + // Expected output table content. 0 = empty cell + const char* aOutputCheck[][3] = { + { "2", "2", "2" }, + { "1", "1", "1" }, + }; + + 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 B1:C2 are not adjusted. + if (!checkFormula(*m_pDoc, ScAddress(1,0,0), "A1")) + CPPUNIT_FAIL("Wrong formula!"); + if (!checkFormula(*m_pDoc, ScAddress(1,1,0), "A2")) + CPPUNIT_FAIL("Wrong formula!"); + if (!checkFormula(*m_pDoc, ScAddress(2,0,0), "B1")) + CPPUNIT_FAIL("Wrong formula!"); + if (!checkFormula(*m_pDoc, ScAddress(2,1,0), "B2")) + CPPUNIT_FAIL("Wrong formula!"); + } + + m_pDoc->DeleteTab(0); +} + void Test::testSortOutOfPlaceResult() { m_pDoc->InsertTab(0, "Sort"); -- cgit v1.2.3