diff options
author | Kohei Yoshida <kohei.yoshida@collabora.com> | 2014-01-27 20:22:48 -0500 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@collabora.com> | 2014-01-27 21:21:10 -0500 |
commit | fa11b0842a51b59eb131a084310c177235ebe487 (patch) | |
tree | e30a71ca5bf4a857882533264c5195311c5c5bb9 | |
parent | f571104ef38ba9f7f6073e22c2374add7aa73887 (diff) |
fdo#74014: Write unit test for this first.
Change-Id: I59fb04e2d7dc8148064564b900680e1b6e1b5e43
-rw-r--r-- | sc/qa/unit/ucalc.cxx | 53 | ||||
-rw-r--r-- | sc/qa/unit/ucalc.hxx | 2 |
2 files changed, 54 insertions, 1 deletions
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx index c4737cf10a3f..257afad05929 100644 --- a/sc/qa/unit/ucalc.cxx +++ b/sc/qa/unit/ucalc.cxx @@ -3537,7 +3537,6 @@ void Test::testCopyPasteAsLink() void Test::testCopyPasteTranspose() { - m_pDoc->InsertTab(0, OUString("Sheet1")); m_pDoc->InsertTab(1, OUString("Sheet2")); @@ -3602,6 +3601,58 @@ void Test::testCopyPasteTranspose() } +void Test::testUndoCut() +{ + m_pDoc->InsertTab(0, "Test"); + + sc::AutoCalcSwitch aACSwitch(*m_pDoc, true); // turn on auto calc. + + // Insert values into A1:A3. + m_pDoc->SetValue(ScAddress(0,0,0), 1.0); + m_pDoc->SetValue(ScAddress(0,1,0), 10.0); + m_pDoc->SetValue(ScAddress(0,2,0), 100.0); + + // SUM in A4. + m_pDoc->SetString(ScAddress(0,3,0), "=SUM(A1:A3)"); + CPPUNIT_ASSERT_EQUAL(111.0, m_pDoc->GetValue(0,3,0)); + + // Select A1:A3. + ScMarkData aMark; + ScRange aRange(0,0,0,0,2,0); + aMark.SetMarkArea(aRange); + aMark.MarkToMulti(); + + // Set up an undo object for cutting A1:A3. + ScDocument* pUndoDoc = new ScDocument(SCDOCMODE_UNDO); + pUndoDoc->InitUndo(m_pDoc, 0 ,0); + m_pDoc->CopyToDocument(aRange, IDF_ALL, false, pUndoDoc); + CPPUNIT_ASSERT_EQUAL( 1.0, pUndoDoc->GetValue(ScAddress(0,0,0))); + CPPUNIT_ASSERT_EQUAL( 10.0, pUndoDoc->GetValue(ScAddress(0,1,0))); + CPPUNIT_ASSERT_EQUAL(100.0, pUndoDoc->GetValue(ScAddress(0,2,0))); + ScUndoCut aUndo(&getDocShell(), aRange, aRange.aEnd, aMark, pUndoDoc); + + // "Cut" the selection. + m_pDoc->DeleteSelection(IDF_ALL, aMark); + CPPUNIT_ASSERT_EQUAL(0.0, m_pDoc->GetValue(0,3,0)); // The SUM should be zero after the "cut". + + // Undo it, and check the result. + aUndo.Undo(); + CPPUNIT_ASSERT_EQUAL( 1.0, m_pDoc->GetValue(ScAddress(0,0,0))); + CPPUNIT_ASSERT_EQUAL( 10.0, m_pDoc->GetValue(ScAddress(0,1,0))); + CPPUNIT_ASSERT_EQUAL(100.0, m_pDoc->GetValue(ScAddress(0,2,0))); + CPPUNIT_ASSERT_EQUAL(111.0, m_pDoc->GetValue(0,3,0)); // The SUM value should be back to the original. + + // Redo it and check. + aUndo.Redo(); + CPPUNIT_ASSERT_EQUAL(0.0, m_pDoc->GetValue(0,3,0)); + + // Undo again. + aUndo.Undo(); + CPPUNIT_ASSERT_EQUAL(111.0, m_pDoc->GetValue(0,3,0)); + + m_pDoc->DeleteTab(0); +} + void Test::testMoveBlock() { m_pDoc->InsertTab(0, "SheetNotes"); diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx index f6007ff3150f..52fb51f76f0d 100644 --- a/sc/qa/unit/ucalc.hxx +++ b/sc/qa/unit/ucalc.hxx @@ -238,6 +238,7 @@ public: void testCopyPaste(); void testCopyPasteAsLink(); void testCopyPasteTranspose(); + void testUndoCut(); void testMoveBlock(); void testCopyPasteRelativeFormula(); void testMergedCells(); @@ -390,6 +391,7 @@ public: CPPUNIT_TEST(testCopyPaste); CPPUNIT_TEST(testCopyPasteAsLink); CPPUNIT_TEST(testCopyPasteTranspose); + CPPUNIT_TEST(testUndoCut); CPPUNIT_TEST(testMoveBlock); CPPUNIT_TEST(testCopyPasteRelativeFormula); CPPUNIT_TEST(testMergedCells); |