summaryrefslogtreecommitdiff
path: root/sc/qa/unit
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@gmail.com>2013-07-09 00:40:50 -0400
committerKohei Yoshida <kohei.yoshida@gmail.com>2013-07-11 00:25:33 -0400
commit2021738377a21bb984716fe028f1f17706f12574 (patch)
tree2547857d3ea3b278b13207674d3a48a8d46e8e3c /sc/qa/unit
parentaa1f551c35068817ffca64ef9b5cf0a1eca36595 (diff)
Add test for formula grouping during copy and paste.
Change-Id: I19604b753801073366058527c19020cc5db812d0
Diffstat (limited to 'sc/qa/unit')
-rw-r--r--sc/qa/unit/ucalc.cxx51
-rw-r--r--sc/qa/unit/ucalc.hxx16
-rw-r--r--sc/qa/unit/ucalc_sharedformula.cxx42
3 files changed, 85 insertions, 24 deletions
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index 49bd3ca2bb36..78005fe80bc0 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -87,6 +87,17 @@ struct TestImpl
ScDocShellRef m_xDocShell;
};
+FormulaGrammarSwitch::FormulaGrammarSwitch(ScDocument* pDoc, formula::FormulaGrammar::Grammar eGrammar) :
+ mpDoc(pDoc), meOldGrammar(pDoc->GetGrammar())
+{
+ mpDoc->SetGrammar(eGrammar);
+}
+
+FormulaGrammarSwitch::~FormulaGrammarSwitch()
+{
+ mpDoc->SetGrammar(meOldGrammar);
+}
+
void printRange(ScDocument* pDoc, const ScRange& rRange, const char* pCaption)
{
SCROW nRow1 = rRange.aStart.Row(), nRow2 = rRange.aEnd.Row();
@@ -129,26 +140,6 @@ ScRange insertRangeData(ScDocument* pDoc, const ScAddress& rPos, const char* aDa
return aRange;
}
-/**
- * Temporarily set formula grammar.
- */
-class FormulaGrammarSwitch
-{
- ScDocument* mpDoc;
- formula::FormulaGrammar::Grammar meOldGrammar;
-public:
- FormulaGrammarSwitch(ScDocument* pDoc, formula::FormulaGrammar::Grammar eGrammar) :
- mpDoc(pDoc), meOldGrammar(pDoc->GetGrammar())
- {
- mpDoc->SetGrammar(eGrammar);
- }
-
- ~FormulaGrammarSwitch()
- {
- mpDoc->SetGrammar(meOldGrammar);
- }
-};
-
class MeasureTimeSwitch
{
double& mrDiff;
@@ -5761,11 +5752,8 @@ void Test::testCopyPaste()
//copy Sheet1.A1:C1 to Sheet2.A2:C2
ScRange aRange(0,0,0,2,0,0);
- ScClipParam aClipParam(aRange, false);
- ScMarkData aMark;
- aMark.SetMarkArea(aRange);
ScDocument aClipDoc(SCDOCMODE_CLIP);
- m_pDoc->CopyToClip(aClipParam, &aClipDoc, &aMark);
+ copyToClip(m_pDoc, aRange, &aClipDoc);
sal_uInt16 nFlags = IDF_ALL;
aRange = ScRange(0,1,1,2,1,1);//target: Sheet2.A2:C2
@@ -6954,6 +6942,21 @@ void Test::clearRange(ScDocument* pDoc, const ScRange& rRange)
rRange.aEnd.Col(), rRange.aEnd.Row(), aMarkData, IDF_CONTENTS);
}
+void Test::copyToClip(ScDocument* pSrcDoc, const ScRange& rRange, ScDocument* pClipDoc)
+{
+ ScClipParam aClipParam(rRange, false);
+ ScMarkData aMark;
+ aMark.SetMarkArea(rRange);
+ pSrcDoc->CopyToClip(aClipParam, pClipDoc, &aMark);
+}
+
+void Test::pasteFromClip(ScDocument* pDestDoc, const ScRange& rDestRange, ScDocument* pClipDoc)
+{
+ ScMarkData aMark;
+ aMark.SetMarkArea(rDestRange);
+ pDestDoc->CopyFromClip(rDestRange, aMark, IDF_ALL, NULL, pClipDoc);
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(Test);
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx
index 2d7a41ae1a2d..9530614abf24 100644
--- a/sc/qa/unit/ucalc.hxx
+++ b/sc/qa/unit/ucalc.hxx
@@ -14,11 +14,25 @@
struct TestImpl;
+/**
+ * Temporarily set formula grammar.
+ */
+class FormulaGrammarSwitch
+{
+ ScDocument* mpDoc;
+ formula::FormulaGrammar::Grammar meOldGrammar;
+public:
+ FormulaGrammarSwitch(ScDocument* pDoc, formula::FormulaGrammar::Grammar eGrammar);
+ ~FormulaGrammarSwitch();
+};
+
class Test : public test::BootstrapFixture
{
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);
Test();
~Test();
@@ -162,6 +176,7 @@ public:
void testUpdateReference();
void testSearchCells();
void testSharedFormulas();
+ void testSharedFormulasCopyPaste();
void testFormulaPosition();
/**
@@ -280,6 +295,7 @@ public:
CPPUNIT_TEST(testUpdateReference);
CPPUNIT_TEST(testSearchCells);
CPPUNIT_TEST(testSharedFormulas);
+ CPPUNIT_TEST(testSharedFormulasCopyPaste);
CPPUNIT_TEST(testFormulaPosition);
CPPUNIT_TEST(testJumpToPrecedentsDependents);
CPPUNIT_TEST(testSetBackgroundColor);
diff --git a/sc/qa/unit/ucalc_sharedformula.cxx b/sc/qa/unit/ucalc_sharedformula.cxx
index 59aa7a4e9a02..035f4ea9076f 100644
--- a/sc/qa/unit/ucalc_sharedformula.cxx
+++ b/sc/qa/unit/ucalc_sharedformula.cxx
@@ -12,6 +12,9 @@
#include "formulacell.hxx"
#include "cellvalue.hxx"
#include "docsh.hxx"
+#include "clipparam.hxx"
+
+#include "formula/grammar.hxx"
void Test::testSharedFormulas()
{
@@ -227,4 +230,43 @@ void Test::testSharedFormulas()
m_pDoc->DeleteTab(0);
}
+void Test::testSharedFormulasCopyPaste()
+{
+ m_pDoc->InsertTab(0, "Test");
+ FormulaGrammarSwitch aFGSwitch(m_pDoc, formula::FormulaGrammar::GRAM_ENGLISH_XL_R1C1);
+
+ // Fill formula cells B1:B10.
+ for (SCROW i = 0; i <= 9; ++i)
+ m_pDoc->SetString(1, i, 0, "=RC[-1]");
+
+ ScAddress aPos(1, 8, 0); // B9
+ ScFormulaCell* pFC = m_pDoc->GetFormulaCell(aPos);
+ CPPUNIT_ASSERT_MESSAGE("B9 should be a formula cell.", pFC);
+ CPPUNIT_ASSERT_EQUAL(0, pFC->GetSharedTopRow());
+ CPPUNIT_ASSERT_EQUAL(10, pFC->GetSharedLength());
+
+ // Copy formulas in B6:B9 to the clipboard doc.
+ ScRange aSrcRange(1,5,0,1,8,0); // B6:B9
+ ScDocument aClipDoc(SCDOCMODE_CLIP);
+ copyToClip(m_pDoc, aSrcRange, &aClipDoc);
+ pFC = aClipDoc.GetFormulaCell(aPos);
+ CPPUNIT_ASSERT_MESSAGE("B9 in the clip doc should be a formula cell.", pFC);
+ CPPUNIT_ASSERT_EQUAL(5, pFC->GetSharedTopRow());
+ CPPUNIT_ASSERT_EQUAL(4, pFC->GetSharedLength());
+
+ // Paste them to C2:C10.
+ ScRange aDestRange(2,1,0,2,9,0);
+ OUString aRS;
+ aDestRange.Format(aRS, SCR_ABS);
+ pasteFromClip(m_pDoc, aDestRange, &aClipDoc);
+ aPos.SetCol(2);
+ aPos.SetRow(1);
+ pFC = m_pDoc->GetFormulaCell(aPos);
+ CPPUNIT_ASSERT_MESSAGE("C2 should be a formula cell.", pFC);
+ CPPUNIT_ASSERT_EQUAL(1, pFC->GetSharedTopRow());
+ CPPUNIT_ASSERT_EQUAL(9, pFC->GetSharedLength());
+
+ m_pDoc->DeleteTab(0);
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */