summaryrefslogtreecommitdiff
path: root/sc/qa
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@gmail.com>2013-07-09 23:04:50 -0400
committerKohei Yoshida <kohei.yoshida@gmail.com>2013-07-11 00:25:34 -0400
commitb1ccc1bf6632d1341f648f7d6e6e90f49701a9c0 (patch)
treedb6e974f58496c993fb3783e7e953f38a3b82081 /sc/qa
parent4e10b2e26f4ac5e2a5ff28e2e3a1eedbf5f8ca61 (diff)
Add test for formula grouping during undo.
Change-Id: Ifab98b1eedf4420ed5b609e0684422c8aae0d33c
Diffstat (limited to 'sc/qa')
-rw-r--r--sc/qa/unit/ucalc.cxx26
-rw-r--r--sc/qa/unit/ucalc.hxx2
-rw-r--r--sc/qa/unit/ucalc_sharedformula.cxx38
3 files changed, 57 insertions, 9 deletions
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index 78005fe80bc0..06c5b83c85fd 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -5755,16 +5755,13 @@ void Test::testCopyPaste()
ScDocument aClipDoc(SCDOCMODE_CLIP);
copyToClip(m_pDoc, aRange, &aClipDoc);
- sal_uInt16 nFlags = IDF_ALL;
aRange = ScRange(0,1,1,2,1,1);//target: Sheet2.A2:C2
ScDocument* pUndoDoc = new ScDocument(SCDOCMODE_UNDO);
pUndoDoc->InitUndo(m_pDoc, 1, 1, true, true);
- ScMarkData aMarkData2;
- aMarkData2.SetMarkArea(aRange);
- ScRefUndoData* pRefUndoData= new ScRefUndoData(m_pDoc);
- ScUndoPaste aUndo(
- &getDocShell(), aRange, aMarkData2, pUndoDoc, NULL, IDF_ALL, pRefUndoData, false);
- m_pDoc->CopyFromClip(aRange, aMarkData2, nFlags, NULL, &aClipDoc);
+ boost::scoped_ptr<ScUndoPaste> pUndo(createUndoPaste(getDocShell(), aRange, pUndoDoc));
+ ScMarkData aMark;
+ aMark.SetMarkArea(aRange);
+ m_pDoc->CopyFromClip(aRange, aMark, IDF_ALL, NULL, &aClipDoc);
//check values after copying
OUString aString;
@@ -5786,13 +5783,13 @@ void Test::testCopyPaste()
//check undo and redo
- aUndo.Undo();
+ pUndo->Undo();
fValue = m_pDoc->GetValue(ScAddress(1,1,1));
ASSERT_DOUBLES_EQUAL_MESSAGE("after undo formula should return nothing", fValue, 0);
aString = m_pDoc->GetString(2, 1, 1);
CPPUNIT_ASSERT_MESSAGE("after undo string should be removed", aString.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("")));
- aUndo.Redo();
+ pUndo->Redo();
fValue = m_pDoc->GetValue(ScAddress(1,1,1));
ASSERT_DOUBLES_EQUAL_MESSAGE("formula should return 2 after redo", fValue, 2);
aString = m_pDoc->GetString(2, 1, 1);
@@ -6957,6 +6954,17 @@ void Test::pasteFromClip(ScDocument* pDestDoc, const ScRange& rDestRange, ScDocu
pDestDoc->CopyFromClip(rDestRange, aMark, IDF_ALL, NULL, pClipDoc);
}
+ScUndoPaste* Test::createUndoPaste(ScDocShell& rDocSh, const ScRange& rRange, ScDocument* pUndoDoc)
+{
+ ScDocument* pDoc = rDocSh.GetDocument();
+ ScMarkData aMarkData;
+ aMarkData.SetMarkArea(rRange);
+ ScRefUndoData* pRefUndoData = new ScRefUndoData(pDoc);
+
+ return new ScUndoPaste(
+ &rDocSh, rRange, aMarkData, pUndoDoc, NULL, IDF_ALL, pRefUndoData, false);
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(Test);
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx
index 9530614abf24..04896833a0cc 100644
--- a/sc/qa/unit/ucalc.hxx
+++ b/sc/qa/unit/ucalc.hxx
@@ -13,6 +13,7 @@
#include "helper/qahelper.hxx"
struct TestImpl;
+class ScUndoPaste;
/**
* Temporarily set formula grammar.
@@ -33,6 +34,7 @@ public:
static void clearRange(ScDocument* pDoc, const ScRange& rRange);
static void copyToClip(ScDocument* pSrcDoc, const ScRange& rRange, ScDocument* pClipDoc);
static void pasteFromClip(ScDocument* pDestDoc, const ScRange& rDestRange, ScDocument* pClipDoc);
+ static ScUndoPaste* createUndoPaste(ScDocShell& rDocSh, const ScRange& rRange, ScDocument* pUndoDoc);
Test();
~Test();
diff --git a/sc/qa/unit/ucalc_sharedformula.cxx b/sc/qa/unit/ucalc_sharedformula.cxx
index 035f4ea9076f..2c49a165631d 100644
--- a/sc/qa/unit/ucalc_sharedformula.cxx
+++ b/sc/qa/unit/ucalc_sharedformula.cxx
@@ -13,6 +13,7 @@
#include "cellvalue.hxx"
#include "docsh.hxx"
#include "clipparam.hxx"
+#include "undoblk.hxx"
#include "formula/grammar.hxx"
@@ -266,6 +267,43 @@ void Test::testSharedFormulasCopyPaste()
CPPUNIT_ASSERT_EQUAL(1, pFC->GetSharedTopRow());
CPPUNIT_ASSERT_EQUAL(9, pFC->GetSharedLength());
+ ScRange aRange(1,0,0,1,9,0); // B1:B10
+ ScDocument* pUndoDoc = new ScDocument(SCDOCMODE_UNDO);
+ pUndoDoc->InitUndo(m_pDoc, 0, 0, true, true);
+ m_pDoc->CopyToDocument(aRange, IDF_CONTENTS, false, pUndoDoc);
+ boost::scoped_ptr<ScUndoPaste> pUndo(createUndoPaste(*m_xDocShRef, aRange, pUndoDoc));
+
+ // First, make sure the formula cells are shared in the undo document.
+ aPos.SetCol(1);
+ for (SCROW i = 0; i <= 9; ++i)
+ {
+ aPos.SetRow(i);
+ pFC = pUndoDoc->GetFormulaCell(aPos);
+ CPPUNIT_ASSERT_MESSAGE("Must be a formula cell.", pFC);
+ CPPUNIT_ASSERT_EQUAL(0, pFC->GetSharedTopRow());
+ CPPUNIT_ASSERT_EQUAL(10, pFC->GetSharedLength());
+ }
+
+ // Overwrite B1:B10.
+ for (SCROW i = 0; i <= 9; ++i)
+ m_pDoc->SetValue(ScAddress(1,i,0), i*10);
+
+ for (SCROW i = 0; i <= 9; ++i)
+ CPPUNIT_ASSERT_MESSAGE("Numeric cell was expected.", m_pDoc->GetCellType(ScAddress(1,i,0)) == CELLTYPE_VALUE);
+
+ // Undo the action to fill B1:B10 with formula cells again.
+ pUndo->Undo();
+
+ aPos.SetCol(1);
+ for (SCROW i = 0; i <= 9; ++i)
+ {
+ aPos.SetRow(i);
+ pFC = m_pDoc->GetFormulaCell(aPos);
+ CPPUNIT_ASSERT_MESSAGE("This should be a formula cell.", pFC);
+ CPPUNIT_ASSERT_EQUAL(0, pFC->GetSharedTopRow());
+ CPPUNIT_ASSERT_EQUAL(10, pFC->GetSharedLength());
+ }
+
m_pDoc->DeleteTab(0);
}