summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@collabora.com>2014-05-06 12:22:13 -0400
committerKohei Yoshida <kohei.yoshida@collabora.com>2014-05-06 12:24:20 -0400
commit5971a8f1cee915e762784e970f0eb10f2baf0f71 (patch)
tree490f4d3f34c0b78e8f1bce0fe839500ac46d8e95
parent5de854b4fa125b3e560723410750467ec3de22a1 (diff)
fdo#77944: Write test for this.
Change-Id: I0dae7533121d5501b35c289bd48ef8d139e37d3e
-rw-r--r--sc/qa/unit/helper/qahelper.cxx4
-rw-r--r--sc/qa/unit/ucalc.cxx48
-rw-r--r--sc/qa/unit/ucalc.hxx2
3 files changed, 54 insertions, 0 deletions
diff --git a/sc/qa/unit/helper/qahelper.cxx b/sc/qa/unit/helper/qahelper.cxx
index 776955fc2f47..e97329f394a3 100644
--- a/sc/qa/unit/helper/qahelper.cxx
+++ b/sc/qa/unit/helper/qahelper.cxx
@@ -404,7 +404,11 @@ ScTokenArray* getTokens(ScDocument& rDoc, const ScAddress& rPos)
{
ScFormulaCell* pCell = rDoc.GetFormulaCell(rPos);
if (!pCell)
+ {
+ OUString aStr = rPos.Format(SCA_VALID);
+ cerr << aStr << " is not a formula cell." << endl;
return NULL;
+ }
return pCell->GetCode();
}
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index ace06b2b8058..97e652126820 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -3772,6 +3772,54 @@ void Test::testCopyPasteSkipEmptyConditionalFormatting()
m_pDoc->DeleteTab(0);
}
+void Test::testCutPasteRefUndo()
+{
+ // Testing scenario: A2 references B2, and B2 gets cut and pasted onto C2,
+ // which updates A2's formula to reference C2. Then the paste action gets
+ // undone, which should also undo A2's formula to reference back to B2.
+
+ sc::AutoCalcSwitch aACSwitch(*m_pDoc, true); // turn on auto calc.
+
+ m_pDoc->InsertTab(0, "Test");
+
+ // A2 references B2.
+ m_pDoc->SetString(ScAddress(0,1,0), "=B2");
+
+ ScMarkData aMark;
+ aMark.SelectOneTable(0);
+
+ // Set up clip document for cutting of B2.
+ ScDocument aClipDoc(SCDOCMODE_CLIP);
+ aClipDoc.ResetClip(m_pDoc, &aMark);
+ ScClipParam aParam(ScAddress(1,1,0), true);
+ aClipDoc.SetClipParam(aParam);
+ aClipDoc.SetValue(ScAddress(1,1,0), 12.0);
+
+ // Set up undo document for reference update.
+ ScDocument* pUndoDoc = new ScDocument(SCDOCMODE_UNDO);
+ pUndoDoc->InitUndo(m_pDoc, 0, 0);
+
+ // Do the pasting of 12 into C2. This should update A2 to reference C2.
+ m_pDoc->CopyFromClip(ScAddress(2,1,0), aMark, IDF_CONTENTS, pUndoDoc, &aClipDoc, true, false);
+ CPPUNIT_ASSERT_EQUAL(12.0, m_pDoc->GetValue(0,1,0));
+
+ if (!checkFormula(*m_pDoc, ScAddress(0,1,0), "C2"))
+ CPPUNIT_FAIL("A2 should be referencing C2.");
+
+ // At this point, the ref undo document should contain a formula cell at A2 that references B2.
+ if (!checkFormula(*pUndoDoc, ScAddress(0,1,0), "B2"))
+ CPPUNIT_FAIL("A2 in the undo document should be referencing B2.");
+
+ ScUndoPaste aUndo(&getDocShell(), ScRange(ScAddress(2,1,0)), aMark, pUndoDoc, NULL, IDF_CONTENTS, NULL, false, NULL);
+ aUndo.Undo();
+
+ // Now A2 should be referencing B2 once again.
+ if (!checkFormula(*m_pDoc, ScAddress(0,1,0), "B2"))
+ CPPUNIT_FAIL("A2 should be referencing B2 after undo.");
+
+ m_pDoc->DeleteTab(0);
+}
+
void Test::testUndoCut()
{
m_pDoc->InsertTab(0, "Test");
diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx
index 2a256a18d4d8..f812630558f4 100644
--- a/sc/qa/unit/ucalc.hxx
+++ b/sc/qa/unit/ucalc.hxx
@@ -261,6 +261,7 @@ public:
void testCopyPasteMultiRange();
void testCopyPasteSkipEmpty();
void testCopyPasteSkipEmptyConditionalFormatting();
+ void testCutPasteRefUndo();
void testUndoCut();
void testMoveBlock();
void testCopyPasteRelativeFormula();
@@ -449,6 +450,7 @@ public:
CPPUNIT_TEST(testCopyPasteMultiRange);
CPPUNIT_TEST(testCopyPasteSkipEmpty);
//CPPUNIT_TEST(testCopyPasteSkipEmptyConditionalFormatting);
+ CPPUNIT_TEST(testCutPasteRefUndo);
CPPUNIT_TEST(testUndoCut);
CPPUNIT_TEST(testMoveBlock);
CPPUNIT_TEST(testCopyPasteRelativeFormula);