sc/qa/unit/ucalc.hxx | 2 sc/qa/unit/ucalc_sharedformula.cxx | 87 +++++++++++++++++++++++++++++++++++++ sc/source/core/tool/token.cxx | 19 ++++++++ 3 files changed, 108 insertions(+)
New commits: commit dd7787ed75e33b65ebee2a6c0aa152efded6f1b8 Author: Kohei Yoshida <kohei.yosh...@collabora.com> Date: Mon Mar 10 20:39:01 2014 -0400 fdo#75815: Adjust external references here too. Adjusting external references are much simpler than adjusting internal ones since we don't need to worry about deleted references etc. Change-Id: I82111e383e1fc6976ef08c1438c3dd916a249af6 diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx index eee7c9d2..8057224 100644 --- a/sc/source/core/tool/token.cxx +++ b/sc/source/core/tool/token.cxx @@ -2751,6 +2751,25 @@ sc::RefUpdateResult ScTokenArray::AdjustReferenceOnShift( const sc::RefUpdateCon rRef.SetRange(aAbs, aNewPos); } break; + case svExternalSingleRef: + { + // For external reference, just reset the reference with + // respect to the new cell position. + ScToken* pToken = static_cast<ScToken*>(*p); + ScSingleRefData& rRef = pToken->GetSingleRef(); + ScAddress aAbs = rRef.toAbs(rOldPos); + rRef.SetAddress(aAbs, aNewPos); + } + break; + case svExternalDoubleRef: + { + // Same as above. + ScToken* pToken = static_cast<ScToken*>(*p); + ScComplexRefData& rRef = pToken->GetDoubleRef(); + ScRange aAbs = rRef.toAbs(rOldPos); + rRef.SetRange(aAbs, aNewPos); + } + break; case svIndex: { const formula::FormulaToken* pToken = *p; commit 149b580900214c477f8eaf9dd51342796d27b296 Author: Kohei Yoshida <kohei.yosh...@collabora.com> Date: Mon Mar 10 19:27:21 2014 -0400 fdo#75815: Write test for this first. Change-Id: I2a5a1964dc6496aa4db15c9e8644692b460d0527 diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx index 7c40fb8..58dc083 100644 --- a/sc/qa/unit/ucalc.hxx +++ b/sc/qa/unit/ucalc.hxx @@ -262,6 +262,7 @@ public: void testSharedFormulas(); void testSharedFormulasRefUpdate(); void testSharedFormulasRefUpdateRange(); + void testSharedFormulasRefUpdateExternal(); void testSharedFormulasDeleteRows(); void testSharedFormulasDeleteColumns(); void testSharedFormulasRefUpdateMoveSheets(); @@ -435,6 +436,7 @@ public: CPPUNIT_TEST(testSharedFormulas); CPPUNIT_TEST(testSharedFormulasRefUpdate); CPPUNIT_TEST(testSharedFormulasRefUpdateRange); + CPPUNIT_TEST(testSharedFormulasRefUpdateExternal); CPPUNIT_TEST(testSharedFormulasDeleteRows); CPPUNIT_TEST(testSharedFormulasDeleteColumns); CPPUNIT_TEST(testSharedFormulasRefUpdateMoveSheets); diff --git a/sc/qa/unit/ucalc_sharedformula.cxx b/sc/qa/unit/ucalc_sharedformula.cxx index ae1ad58..98d087d 100644 --- a/sc/qa/unit/ucalc_sharedformula.cxx +++ b/sc/qa/unit/ucalc_sharedformula.cxx @@ -449,6 +449,93 @@ void Test::testSharedFormulasRefUpdateRange() m_pDoc->DeleteTab(0); } +void Test::testSharedFormulasRefUpdateExternal() +{ + sc::AutoCalcSwitch aACSwitch(*m_pDoc, true); // turn on auto calc. + m_pDoc->InsertTab(0, "Formula"); + + // Launch an external document shell. + ScDocShellRef xExtDocSh = new ScDocShell; + OUString aExtDocName("file:///extdata.fake"); + + SfxMedium* pMed = new SfxMedium(aExtDocName, STREAM_STD_READWRITE); + xExtDocSh->DoInitNew(pMed); + ScDocument* pExtDoc = xExtDocSh->GetDocument(); + + // Populate A1:A3. + pExtDoc->InsertTab(0, "Data"); + pExtDoc->SetString(ScAddress(0,0,0), "A"); + pExtDoc->SetString(ScAddress(0,1,0), "B"); + pExtDoc->SetString(ScAddress(0,2,0), "C"); + + // Insert formula cells in A7:A10 of the host document, referencing A1:A3 + // of the external document. + m_pDoc->SetString(ScAddress(0,6,0), "='file:///extdata.fake'#$Data.A1"); + m_pDoc->SetString(ScAddress(0,7,0), "='file:///extdata.fake'#$Data.A2"); + m_pDoc->SetString(ScAddress(0,8,0), "='file:///extdata.fake'#$Data.A3"); + m_pDoc->SetString(ScAddress(0,9,0), "=COUNTA('file:///extdata.fake'#$Data.A1:A3)"); + + // Check the formula results. + CPPUNIT_ASSERT_EQUAL(OUString("A"), m_pDoc->GetString(ScAddress(0,6,0))); + CPPUNIT_ASSERT_EQUAL(OUString("B"), m_pDoc->GetString(ScAddress(0,7,0))); + CPPUNIT_ASSERT_EQUAL(OUString("C"), m_pDoc->GetString(ScAddress(0,8,0))); + CPPUNIT_ASSERT_EQUAL(3.0, m_pDoc->GetValue(ScAddress(0,9,0))); + + // Check the formulas too. + if (!checkFormula(*m_pDoc, ScAddress(0,6,0), "'file:///extdata.fake'#$Data.A1")) + CPPUNIT_FAIL("Wrong formula!"); + if (!checkFormula(*m_pDoc, ScAddress(0,7,0), "'file:///extdata.fake'#$Data.A2")) + CPPUNIT_FAIL("Wrong formula!"); + if (!checkFormula(*m_pDoc, ScAddress(0,8,0), "'file:///extdata.fake'#$Data.A3")) + CPPUNIT_FAIL("Wrong formula!"); + if (!checkFormula(*m_pDoc, ScAddress(0,9,0), "COUNTA('file:///extdata.fake'#$Data.A1:A3)")) + CPPUNIT_FAIL("Wrong formula!"); + + // Delete rows 1 and 2. This should not change the references in the formula cells below. + ScDocFunc& rDocFunc = getDocShell().GetDocFunc(); + ScMarkData aMark; + aMark.SelectOneTable(0); + rDocFunc.DeleteCells(ScRange(0,0,0,MAXCOL,1,0), &aMark, DEL_CELLSUP, true, true); + + // Check the shifted formula cells now in A5:A8. + if (!checkFormula(*m_pDoc, ScAddress(0,4,0), "'file:///extdata.fake'#$Data.A1")) + CPPUNIT_FAIL("Wrong formula!"); + if (!checkFormula(*m_pDoc, ScAddress(0,5,0), "'file:///extdata.fake'#$Data.A2")) + CPPUNIT_FAIL("Wrong formula!"); + if (!checkFormula(*m_pDoc, ScAddress(0,6,0), "'file:///extdata.fake'#$Data.A3")) + CPPUNIT_FAIL("Wrong formula!"); + if (!checkFormula(*m_pDoc, ScAddress(0,7,0), "COUNTA('file:///extdata.fake'#$Data.A1:A3)")) + CPPUNIT_FAIL("Wrong formula!"); + + // Undo and check the formulas again. + SfxUndoManager* pUndoMgr = m_pDoc->GetUndoManager(); + CPPUNIT_ASSERT(pUndoMgr); + pUndoMgr->Undo(); + if (!checkFormula(*m_pDoc, ScAddress(0,6,0), "'file:///extdata.fake'#$Data.A1")) + CPPUNIT_FAIL("Wrong formula!"); + if (!checkFormula(*m_pDoc, ScAddress(0,7,0), "'file:///extdata.fake'#$Data.A2")) + CPPUNIT_FAIL("Wrong formula!"); + if (!checkFormula(*m_pDoc, ScAddress(0,8,0), "'file:///extdata.fake'#$Data.A3")) + CPPUNIT_FAIL("Wrong formula!"); + if (!checkFormula(*m_pDoc, ScAddress(0,9,0), "COUNTA('file:///extdata.fake'#$Data.A1:A3)")) + CPPUNIT_FAIL("Wrong formula!"); + + // Redo the row deletion and check the formulas again. + pUndoMgr->Redo(); + if (!checkFormula(*m_pDoc, ScAddress(0,4,0), "'file:///extdata.fake'#$Data.A1")) + CPPUNIT_FAIL("Wrong formula!"); + if (!checkFormula(*m_pDoc, ScAddress(0,5,0), "'file:///extdata.fake'#$Data.A2")) + CPPUNIT_FAIL("Wrong formula!"); + if (!checkFormula(*m_pDoc, ScAddress(0,6,0), "'file:///extdata.fake'#$Data.A3")) + CPPUNIT_FAIL("Wrong formula!"); + if (!checkFormula(*m_pDoc, ScAddress(0,7,0), "COUNTA('file:///extdata.fake'#$Data.A1:A3)")) + CPPUNIT_FAIL("Wrong formula!"); + + xExtDocSh->DoClose(); + + m_pDoc->DeleteTab(0); +} + void Test::testSharedFormulasDeleteRows() { m_pDoc->InsertTab(0, "Test"); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits