summaryrefslogtreecommitdiff
path: root/sc/qa
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@gmail.com>2012-10-30 14:21:36 -0400
committerKohei Yoshida <kohei.yoshida@gmail.com>2012-10-30 14:28:58 -0400
commit08dee0ce8d5d49b3ff2e993bfa44cf49c0c643e0 (patch)
treeaaba9a226c1a2129163c634c558f74abffa2bafb /sc/qa
parent8cd13f7e04e920e3d6e1fddf88f61dac08894e06 (diff)
Another test case for column formula arrays.
We will later handle this use case using shared formulas. Change-Id: I6403ae4adddc865d0418290e1549a91ef4eeb318
Diffstat (limited to 'sc/qa')
-rw-r--r--sc/qa/unit/ucalc.cxx52
1 files changed, 52 insertions, 0 deletions
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index 890c6bf3c145..45d84ff43e85 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -334,6 +334,9 @@ ScRange insertRangeData(ScDocument* pDoc, const ScAddress& rPos, const char* aDa
return aRange;
}
+/**
+ * Temporarily switch on/off auto calculation mode.
+ */
class AutoCalcSwitch
{
ScDocument* mpDoc;
@@ -350,6 +353,26 @@ public:
}
};
+/**
+ * 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);
+ }
+};
+
Test::Test()
: m_pDoc(0)
{
@@ -1147,6 +1170,35 @@ void Test::testFormulaDepTracking()
m_pDoc->GetValue(1, 1, 0, val);
CPPUNIT_ASSERT_MESSAGE("Failed to recalculate on single value change.", rtl::math::approxEqual(val, 12.0));
+ clearRange(m_pDoc, ScRange(0, 0, 0, 10, 10, 0));
+
+ // Now, column-based dependency tracking. We now switch to the R1C1
+ // syntax which is easier to use for repeated relative references.
+
+ FormulaGrammarSwitch aFGSwitch(m_pDoc, formula::FormulaGrammar::GRAM_ENGLISH_XL_R1C1);
+
+ val = 0.0;
+ for (SCROW nRow = 1; nRow <= 9; ++nRow)
+ {
+ // Static value in column 1.
+ m_pDoc->SetValue(0, nRow, 0, ++val);
+
+ // Formula in column 2 that references cell to the left.
+ m_pDoc->SetString(1, nRow, 0, "=RC[-1]");
+
+ // Formula in column 3 that references cell to the left.
+ m_pDoc->SetString(2, nRow, 0, "=RC[-1]*2");
+ }
+
+ // Check formula values.
+ val = 0.0;
+ for (SCROW nRow = 1; nRow <= 9; ++nRow)
+ {
+ ++val;
+ CPPUNIT_ASSERT_MESSAGE("Unexpected formula value.", m_pDoc->GetValue(1, nRow, 0) == val);
+ CPPUNIT_ASSERT_MESSAGE("Unexpected formula value.", m_pDoc->GetValue(2, nRow, 0) == val*2.0);
+ }
+
m_pDoc->DeleteTab(0);
}