summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2016-04-08 14:59:09 +0100
committerEike Rathke <erack@redhat.com>2016-04-08 15:02:36 +0100
commit7dda56143f17f9b85bcc9630f2fad12b65541fc2 (patch)
tree3de69abbe0dba6f170d7687802e31e7b19089097
parent40c3e906c6617a6b2a6fcab0c3879c19919b75e8 (diff)
unit test for replacing fragments of shared formula groups, tdf#97897
Change-Id: If17b0f812c33f338e7ff5af381c1ed17b9965eba
-rw-r--r--sc/qa/unit/ucalc.hxx2
-rw-r--r--sc/qa/unit/ucalc_sharedformula.cxx156
2 files changed, 158 insertions, 0 deletions
diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx
index 1f469b1640d9..9c930169041f 100644
--- a/sc/qa/unit/ucalc.hxx
+++ b/sc/qa/unit/ucalc.hxx
@@ -360,6 +360,7 @@ public:
void testSharedFormulaAbsCellListener();
void testSharedFormulaUnshareAreaListeners();
void testSharedFormulaListenerDeleteArea();
+ void testSharedFormulaUpdateOnReplacement();
void testFormulaPosition();
void testFormulaWizardSubformula();
@@ -654,6 +655,7 @@ public:
CPPUNIT_TEST(testSharedFormulaAbsCellListener);
CPPUNIT_TEST(testSharedFormulaUnshareAreaListeners);
CPPUNIT_TEST(testSharedFormulaListenerDeleteArea);
+ CPPUNIT_TEST(testSharedFormulaUpdateOnReplacement);
CPPUNIT_TEST(testFormulaPosition);
CPPUNIT_TEST(testFormulaWizardSubformula);
CPPUNIT_TEST(testMixData);
diff --git a/sc/qa/unit/ucalc_sharedformula.cxx b/sc/qa/unit/ucalc_sharedformula.cxx
index 8ae2cf9ed83e..15db4f6a11c4 100644
--- a/sc/qa/unit/ucalc_sharedformula.cxx
+++ b/sc/qa/unit/ucalc_sharedformula.cxx
@@ -1800,4 +1800,160 @@ void Test::testSharedFormulaListenerDeleteArea()
m_pDoc->DeleteTab(0);
}
+void Test::testSharedFormulaUpdateOnReplacement()
+{
+ sc::AutoCalcSwitch aACSwitch(*m_pDoc, true); // turn on auto calc.
+
+ m_pDoc->InsertTab(0, "Test");
+
+ const char* pData[][1] = {
+ { "1" },
+ { "=SUM($A$1:$A1)" },
+ { "=SUM($A$1:$A2)" },
+ { "=SUM($A$1:$A3)" },
+ { "=SUM($A$1:$A4)" },
+ { "=SUM($A$1:$A5)" },
+ { "=SUM($A$1:$A6)" },
+ { "=SUM($A$1:$A7)" }
+ };
+
+ insertRangeData(m_pDoc, ScAddress(0,0,0), pData, SAL_N_ELEMENTS(pData));
+
+ // Check that A2:A8 is a formula group.
+ const ScFormulaCell* pFC = m_pDoc->GetFormulaCell(ScAddress(0,1,0));
+ CPPUNIT_ASSERT(pFC);
+ CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(1), pFC->GetSharedTopRow());
+ CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(7), pFC->GetSharedLength());
+
+ { // Check initial results.
+ ScAddress aPos(0,0,0);
+ const double fResult[] = { 1.0, 1.0, 2.0, 4.0, 8.0, 16.0, 32.0, 64.0 };
+ for (SCROW nRow = 1; nRow < 8; ++nRow)
+ {
+ aPos.SetRow(nRow);
+ CPPUNIT_ASSERT_EQUAL( fResult[nRow], m_pDoc->GetValue( aPos));
+ }
+ }
+
+ // Set up an undo object for deleting A4.
+ ScRange aUndoRange(0,3,0,0,3,0);
+ ScMarkData aMark;
+ aMark.SelectOneTable(0);
+ aMark.SetMultiMarkArea(aUndoRange);
+ std::unique_ptr<ScDocument> pUndoDoc(new ScDocument(SCDOCMODE_UNDO));
+ pUndoDoc->InitUndo(m_pDoc, 0, 0);
+ m_pDoc->CopyToDocument(aUndoRange, InsertDeleteFlags::CONTENTS, false, pUndoDoc.get(), &aMark);
+ ScUndoDeleteContents aUndo(&getDocShell(), aMark, aUndoRange, std::move(pUndoDoc), false, InsertDeleteFlags::CONTENTS, true);
+
+ // Delete A4.
+ clearRange(m_pDoc, aUndoRange);
+
+ // Check that A2:A3 and A5:A8 are formula groups.
+ pFC = m_pDoc->GetFormulaCell(ScAddress(0,1,0));
+ CPPUNIT_ASSERT(pFC);
+ CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(1), pFC->GetSharedTopRow());
+ CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(2), pFC->GetSharedLength());
+ pFC = m_pDoc->GetFormulaCell(ScAddress(0,4,0));
+ CPPUNIT_ASSERT(pFC);
+ CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(4), pFC->GetSharedTopRow());
+ CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(4), pFC->GetSharedLength());
+
+ { // Check results of A4 deleted.
+ ScAddress aPos(0,0,0);
+ const double fResult[] = { 1.0, 1.0, 2.0, 0.0, 4.0, 8.0, 16.0, 32.0 };
+ for (SCROW nRow = 1; nRow < 8; ++nRow)
+ {
+ aPos.SetRow(nRow);
+ CPPUNIT_ASSERT_EQUAL( fResult[nRow], m_pDoc->GetValue( aPos));
+ }
+ }
+
+ // Restore A4.
+ aUndo.Undo();
+
+ // Check that A2:A8 is a formula group.
+ pFC = m_pDoc->GetFormulaCell(ScAddress(0,1,0));
+ CPPUNIT_ASSERT(pFC);
+ CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(1), pFC->GetSharedTopRow());
+ CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(7), pFC->GetSharedLength());
+
+ { // Check initial results.
+ ScAddress aPos(0,0,0);
+ const double fResult[] = { 1.0, 1.0, 2.0, 4.0, 8.0, 16.0, 32.0, 64.0 };
+ for (SCROW nRow = 1; nRow < 8; ++nRow)
+ {
+ aPos.SetRow(nRow);
+ CPPUNIT_ASSERT_EQUAL( fResult[nRow], m_pDoc->GetValue( aPos));
+ }
+ }
+
+ // Delete A4 using selection.
+ m_pDoc->DeleteSelection(InsertDeleteFlags::ALL, aMark);
+
+ // Check that A2:A3 and A5:A8 are formula groups.
+ pFC = m_pDoc->GetFormulaCell(ScAddress(0,1,0));
+ CPPUNIT_ASSERT(pFC);
+ CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(1), pFC->GetSharedTopRow());
+ CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(2), pFC->GetSharedLength());
+ pFC = m_pDoc->GetFormulaCell(ScAddress(0,4,0));
+ CPPUNIT_ASSERT(pFC);
+ CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(4), pFC->GetSharedTopRow());
+ CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(4), pFC->GetSharedLength());
+
+ { // Check results of A4 deleted.
+ ScAddress aPos(0,0,0);
+ const double fResult[] = { 1.0, 1.0, 2.0, 0.0, 4.0, 8.0, 16.0, 32.0 };
+ for (SCROW nRow = 1; nRow < 8; ++nRow)
+ {
+ aPos.SetRow(nRow);
+ CPPUNIT_ASSERT_EQUAL( fResult[nRow], m_pDoc->GetValue( aPos));
+ }
+ }
+
+ // Restore A4.
+ aUndo.Undo();
+
+ // Check that A2:A8 is a formula group.
+ pFC = m_pDoc->GetFormulaCell(ScAddress(0,1,0));
+ CPPUNIT_ASSERT(pFC);
+ CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(1), pFC->GetSharedTopRow());
+ CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(7), pFC->GetSharedLength());
+
+ { // Check initial results.
+ ScAddress aPos(0,0,0);
+ const double fResult[] = { 1.0, 1.0, 2.0, 4.0, 8.0, 16.0, 32.0, 64.0 };
+ for (SCROW nRow = 1; nRow < 8; ++nRow)
+ {
+ aPos.SetRow(nRow);
+ CPPUNIT_ASSERT_EQUAL( fResult[nRow], m_pDoc->GetValue( aPos));
+ }
+ }
+
+ // Replace A4 with 0.
+ m_pDoc->SetString( ScAddress(0,3,0), "0");
+
+ // Check that A2:A3 and A5:A8 are formula groups.
+ pFC = m_pDoc->GetFormulaCell(ScAddress(0,1,0));
+ CPPUNIT_ASSERT(pFC);
+ CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(1), pFC->GetSharedTopRow());
+ CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(2), pFC->GetSharedLength());
+ pFC = m_pDoc->GetFormulaCell(ScAddress(0,4,0));
+ CPPUNIT_ASSERT(pFC);
+ CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(4), pFC->GetSharedTopRow());
+ CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(4), pFC->GetSharedLength());
+
+ { // Check results of A4 set to zero.
+ ScAddress aPos(0,0,0);
+ const double fResult[] = { 1.0, 1.0, 2.0, 0.0, 4.0, 8.0, 16.0, 32.0 };
+ for (SCROW nRow = 1; nRow < 8; ++nRow)
+ {
+ aPos.SetRow(nRow);
+ CPPUNIT_ASSERT_EQUAL( fResult[nRow], m_pDoc->GetValue( aPos));
+ }
+ }
+
+ m_pDoc->DeleteTab(0);
+}
+
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */