summaryrefslogtreecommitdiff
path: root/sc/qa
diff options
context:
space:
mode:
Diffstat (limited to 'sc/qa')
-rw-r--r--sc/qa/unit/helper/qahelper.cxx2
-rw-r--r--sc/qa/unit/ucalc.hxx2
-rw-r--r--sc/qa/unit/ucalc_sharedformula.cxx81
3 files changed, 84 insertions, 1 deletions
diff --git a/sc/qa/unit/helper/qahelper.cxx b/sc/qa/unit/helper/qahelper.cxx
index 7666c34db042..773b7791f36b 100644
--- a/sc/qa/unit/helper/qahelper.cxx
+++ b/sc/qa/unit/helper/qahelper.cxx
@@ -420,7 +420,7 @@ bool checkFormula(ScDocument& rDoc, const ScAddress& rPos, const char* pExpected
return false;
}
- OUString aFormula = toString(rDoc, rPos, *pCode);
+ OUString aFormula = toString(rDoc, rPos, *pCode, rDoc.GetGrammar());
if (aFormula != OUString::createFromAscii(pExpected))
{
cerr << "Formula '" << pExpected << "' expected, but '" << aFormula << "' found" << endl;
diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx
index 1f6f20201cf1..1dbfbbc023c4 100644
--- a/sc/qa/unit/ucalc.hxx
+++ b/sc/qa/unit/ucalc.hxx
@@ -246,6 +246,7 @@ public:
void testSharedFormulasRefUpdate();
void testSharedFormulasRefUpdateRange();
void testSharedFormulasDeleteRows();
+ void testSharedFormulasRefUpdateMoveSheets();
void testSharedFormulasCopyPaste();
void testFormulaPosition();
@@ -396,6 +397,7 @@ public:
CPPUNIT_TEST(testSharedFormulasRefUpdate);
CPPUNIT_TEST(testSharedFormulasRefUpdateRange);
CPPUNIT_TEST(testSharedFormulasDeleteRows);
+ CPPUNIT_TEST(testSharedFormulasRefUpdateMoveSheets);
CPPUNIT_TEST(testSharedFormulasCopyPaste);
CPPUNIT_TEST(testFormulaPosition);
CPPUNIT_TEST(testJumpToPrecedentsDependents);
diff --git a/sc/qa/unit/ucalc_sharedformula.cxx b/sc/qa/unit/ucalc_sharedformula.cxx
index b1bdea21fdd8..b4ce117f9cd3 100644
--- a/sc/qa/unit/ucalc_sharedformula.cxx
+++ b/sc/qa/unit/ucalc_sharedformula.cxx
@@ -515,7 +515,88 @@ void Test::testSharedFormulasDeleteRows()
CPPUNIT_ASSERT_MESSAGE("1,6 must be a shared formula cell.", pFC && pFC->IsShared());
CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(6), pFC->GetSharedTopRow());
CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(8), pFC->GetSharedLength());
+}
+
+void Test::testSharedFormulasRefUpdateMoveSheets()
+{
+ m_pDoc->InsertTab(0, "Sheet1");
+ m_pDoc->InsertTab(1, "Sheet2");
+ m_pDoc->InsertTab(2, "Sheet3");
+
+ sc::AutoCalcSwitch aACSwitch(*m_pDoc, true); // make sure auto calc is on.
+
+ // Switch to R1C1 for ease of repeated formula insertions.
+ FormulaGrammarSwitch aFGSwitch(m_pDoc, formula::FormulaGrammar::GRAM_ENGLISH_XL_R1C1);
+
+ // Fill numbers in A1:A8 on Sheet2.
+ for (SCROW i = 0; i <= 7; ++i)
+ m_pDoc->SetValue(ScAddress(0,i,1), i+1);
+
+ // Fill formula cells A1:A8 on Sheet1, to refer to the same cell address on Sheet2.
+ for (SCROW i = 0; i <= 7; ++i)
+ m_pDoc->SetString(ScAddress(0,i,0), "=Sheet2!RC");
+
+ // Check the results.
+ for (SCROW i = 0; i <= 7; ++i)
+ CPPUNIT_ASSERT_EQUAL(static_cast<double>(i+1), m_pDoc->GetValue(ScAddress(0,i,0)));
+
+ // Move Sheet3 to the leftmost position before Sheet1.
+ m_pDoc->MoveTab(2, 0);
+
+ // Check sheet names.
+ std::vector<OUString> aTabNames = m_pDoc->GetAllTableNames();
+ CPPUNIT_ASSERT_MESSAGE("There should be at least 3 sheets.", aTabNames.size() >= 3);
+ CPPUNIT_ASSERT_EQUAL(OUString("Sheet3"), aTabNames[0]);
+ CPPUNIT_ASSERT_EQUAL(OUString("Sheet1"), aTabNames[1]);
+ CPPUNIT_ASSERT_EQUAL(OUString("Sheet2"), aTabNames[2]);
+
+ // Check the results again on Sheet1.
+ for (SCROW i = 0; i <= 7; ++i)
+ {
+ CPPUNIT_ASSERT_EQUAL(static_cast<double>(i+1), m_pDoc->GetValue(ScAddress(0,i,1)));
+ if (!checkFormula(*m_pDoc, ScAddress(0,i,1), "Sheet2!RC"))
+ CPPUNIT_FAIL("Wrong formula expression.");
+ }
+
+ // Insert a new sheet at the left end.
+ m_pDoc->InsertTab(0, "Sheet4");
+
+ // Check sheet names.
+ aTabNames = m_pDoc->GetAllTableNames();
+ CPPUNIT_ASSERT_MESSAGE("There should be at least 4 sheets.", aTabNames.size() >= 4);
+ CPPUNIT_ASSERT_EQUAL(OUString("Sheet4"), aTabNames[0]);
+ CPPUNIT_ASSERT_EQUAL(OUString("Sheet3"), aTabNames[1]);
+ CPPUNIT_ASSERT_EQUAL(OUString("Sheet1"), aTabNames[2]);
+ CPPUNIT_ASSERT_EQUAL(OUString("Sheet2"), aTabNames[3]);
+
+ // Check the results again on Sheet1.
+ for (SCROW i = 0; i <= 7; ++i)
+ {
+ CPPUNIT_ASSERT_EQUAL(static_cast<double>(i+1), m_pDoc->GetValue(ScAddress(0,i,2)));
+ if (!checkFormula(*m_pDoc, ScAddress(0,i,2), "Sheet2!RC"))
+ CPPUNIT_FAIL("Wrong formula expression.");
+ }
+
+ // Delete Sheet4.
+ m_pDoc->DeleteTab(0);
+
+ // Check sheet names.
+ aTabNames = m_pDoc->GetAllTableNames();
+ CPPUNIT_ASSERT_MESSAGE("There should be at least 3 sheets.", aTabNames.size() >= 3);
+ CPPUNIT_ASSERT_EQUAL(OUString("Sheet3"), aTabNames[0]);
+ CPPUNIT_ASSERT_EQUAL(OUString("Sheet1"), aTabNames[1]);
+ CPPUNIT_ASSERT_EQUAL(OUString("Sheet2"), aTabNames[2]);
+
+ // Check the results again on Sheet1.
+ for (SCROW i = 0; i <= 7; ++i)
+ {
+ CPPUNIT_ASSERT_EQUAL(static_cast<double>(i+1), m_pDoc->GetValue(ScAddress(0,i,1)));
+ if (!checkFormula(*m_pDoc, ScAddress(0,i,1), "Sheet2!RC"))
+ CPPUNIT_FAIL("Wrong formula expression.");
+ }
+ m_pDoc->DeleteTab(2);
+ m_pDoc->DeleteTab(1);
m_pDoc->DeleteTab(0);
}