[Libreoffice-commits] core.git: 2 commits - sc/qa sc/source

Kohei Yoshida kohei.yoshida at collabora.com
Tue May 6 09:24:08 PDT 2014


 sc/qa/unit/helper/qahelper.cxx      |    4 +++
 sc/qa/unit/ucalc.cxx                |   48 ++++++++++++++++++++++++++++++++++++
 sc/qa/unit/ucalc.hxx                |    2 +
 sc/source/core/data/formulacell.cxx |    2 -
 4 files changed, 55 insertions(+), 1 deletion(-)

New commits:
commit 67563fd55b230eb68fef705ff645af7dab73af73
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Tue May 6 12:22:53 2014 -0400

    fdo#77944: Put updated formula cells into undo document.
    
    Change-Id: Ib9d6a73d485878bfe6c2a1875936025eb4d0a30a

diff --git a/sc/source/core/data/formulacell.cxx b/sc/source/core/data/formulacell.cxx
index d7cef22..a233fe5 100644
--- a/sc/source/core/data/formulacell.cxx
+++ b/sc/source/core/data/formulacell.cxx
@@ -2871,7 +2871,7 @@ bool ScFormulaCell::UpdateReferenceOnMove(
          (bValChanged && bHasRelName ) || bOnRefMove)
         bNeedDirty = true;
 
-    if (pUndoDoc && (bValChanged || bOnRefMove))
+    if (pUndoDoc && (bValChanged || bRefModified || bOnRefMove))
         setOldCodeToUndo(pUndoDoc, aUndoPos, pOldCode.get(), eTempGrammar, cMatrixFlag);
 
     bValChanged = false;
commit 5971a8f1cee915e762784e970f0eb10f2baf0f71
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Tue May 6 12:22:13 2014 -0400

    fdo#77944: Write test for this.
    
    Change-Id: I0dae7533121d5501b35c289bd48ef8d139e37d3e

diff --git a/sc/qa/unit/helper/qahelper.cxx b/sc/qa/unit/helper/qahelper.cxx
index 776955f..e97329f 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 ace06b2..97e6521 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 2a256a1..f812630 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);


More information about the Libreoffice-commits mailing list