[Libreoffice-commits] core.git: 2 commits - sc/inc sc/qa sc/source
Eike Rathke
erack at redhat.com
Thu Mar 31 21:36:15 UTC 2016
sc/inc/document.hxx | 13 ++++++
sc/qa/unit/ucalc.hxx | 1
sc/qa/unit/ucalc_formula.cxx | 83 +++++++++++++++++++++++++++++++++++++++
sc/source/core/data/documen3.cxx | 10 ++++
4 files changed, 107 insertions(+)
New commits:
commit 3d88efbe9ed1c42f2e8ccd2e71724f0cb96d3c3e
Author: Eike Rathke <erack at redhat.com>
Date: Thu Mar 31 23:34:01 2016 +0200
unit test for copying nested names during copying sheet
Change-Id: Id165e7e2ce229949b919424338a4938e15aaab4d
diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx
index d284597..1f469b1 100644
--- a/sc/qa/unit/ucalc.hxx
+++ b/sc/qa/unit/ucalc.hxx
@@ -151,6 +151,7 @@ public:
void testFormulaRefUpdateNameExpandRef();
void testFormulaRefUpdateNameDeleteRow();
void testFormulaRefUpdateNameCopySheet();
+ void testFormulaRefUpdateNameCopySheetCheckTab( SCTAB Tab, bool bCheckNames );
void testFormulaRefUpdateNameDelete();
void testFormulaRefUpdateValidity();
void testMultipleOperations();
diff --git a/sc/qa/unit/ucalc_formula.cxx b/sc/qa/unit/ucalc_formula.cxx
index 6c1ac90..634576f 100644
--- a/sc/qa/unit/ucalc_formula.cxx
+++ b/sc/qa/unit/ucalc_formula.cxx
@@ -3216,6 +3216,89 @@ void Test::testFormulaRefUpdateNameCopySheet()
m_pDoc->DeleteTab(2);
m_pDoc->DeleteTab(1);
m_pDoc->DeleteTab(0);
+ m_pDoc->SetRangeName(nullptr);
+
+ // Test nested names during copying sheet.
+
+ m_pDoc->InsertTab(0, "Test2");
+ ScAddress aPos(0,0,0);
+ bInserted = m_pDoc->InsertNewRangeName( "global", aPos, "$Test2.$A$1");
+ CPPUNIT_ASSERT(bInserted);
+ bInserted = m_pDoc->InsertNewRangeName( aPos.Tab(), "local", aPos, "$Test2.$A$2");
+ CPPUNIT_ASSERT(bInserted);
+ bInserted = m_pDoc->InsertNewRangeName( "global_global", aPos, "global*100");
+ CPPUNIT_ASSERT(bInserted);
+ bInserted = m_pDoc->InsertNewRangeName( "global_local", aPos, "local*1000");
+ CPPUNIT_ASSERT(bInserted);
+ bInserted = m_pDoc->InsertNewRangeName( aPos.Tab(), "local_global", aPos, "global*10000");
+ CPPUNIT_ASSERT(bInserted);
+ bInserted = m_pDoc->InsertNewRangeName( aPos.Tab(), "local_local", aPos, "local*100000");
+ CPPUNIT_ASSERT(bInserted);
+
+ m_pDoc->SetString(aPos, "=SHEET()");
+ aPos.IncRow();
+ m_pDoc->SetString(aPos, "=A1*10+SHEET()");
+ aPos.IncRow();
+ m_pDoc->SetString(aPos, "=global_global");
+ aPos.IncRow();
+ m_pDoc->SetString(aPos, "=global_local");
+ aPos.IncRow();
+ m_pDoc->SetString(aPos, "=local_global");
+ aPos.IncRow();
+ m_pDoc->SetString(aPos, "=local_local");
+
+ testFormulaRefUpdateNameCopySheetCheckTab( 0, false);
+
+ // Copy sheet after.
+ m_pDoc->CopyTab(0, 1);
+ testFormulaRefUpdateNameCopySheetCheckTab( 0, false);
+ testFormulaRefUpdateNameCopySheetCheckTab( 1, true);
+
+ // Copy sheet before, shifting following now two sheets.
+ m_pDoc->CopyTab(1, 0);
+ testFormulaRefUpdateNameCopySheetCheckTab( 0, true);
+ testFormulaRefUpdateNameCopySheetCheckTab( 1, false);
+ testFormulaRefUpdateNameCopySheetCheckTab( 2, true);
+
+ m_pDoc->DeleteTab(2);
+ m_pDoc->DeleteTab(1);
+ m_pDoc->DeleteTab(0);
+}
+
+void Test::testFormulaRefUpdateNameCopySheetCheckTab( SCTAB nTab, bool bCheckNames )
+{
+ if (bCheckNames)
+ {
+ const ScRangeData* pName;
+ pName = m_pDoc->GetRangeName(nTab)->findByUpperName("GLOBAL");
+ CPPUNIT_ASSERT_MESSAGE("Sheet-local name GLOBAL should exist", pName);
+ pName = m_pDoc->GetRangeName(nTab)->findByUpperName("LOCAL");
+ CPPUNIT_ASSERT_MESSAGE("Sheet-local name LOCAL should exist", pName);
+ pName = m_pDoc->GetRangeName(nTab)->findByUpperName("GLOBAL_GLOBAL");
+ CPPUNIT_ASSERT_MESSAGE("Sheet-local name GLOBAL_GLOBAL should exist", pName);
+ pName = m_pDoc->GetRangeName(nTab)->findByUpperName("GLOBAL_LOCAL");
+ CPPUNIT_ASSERT_MESSAGE("Sheet-local name GLOBAL_LOCAL should exist", pName);
+ pName = m_pDoc->GetRangeName(nTab)->findByUpperName("LOCAL_GLOBAL");
+ CPPUNIT_ASSERT_MESSAGE("Sheet-local name LOCAL_GLOBAL should exist", pName);
+ pName = m_pDoc->GetRangeName(nTab)->findByUpperName("LOCAL_LOCAL");
+ CPPUNIT_ASSERT_MESSAGE("Sheet-local name LOCAL_LOCAL should exist", pName);
+ }
+
+ ScAddress aPos(0,0,0);
+ aPos.SetRow(0);
+ aPos.SetTab(nTab);
+ int nSheet = nTab + 1;
+ CPPUNIT_ASSERT_EQUAL( 1.0 * nSheet, m_pDoc->GetValue(aPos));
+ aPos.IncRow();
+ CPPUNIT_ASSERT_EQUAL( 11.0 * nSheet, m_pDoc->GetValue(aPos));
+ aPos.IncRow();
+ CPPUNIT_ASSERT_EQUAL( 100.0 * nSheet, m_pDoc->GetValue(aPos));
+ aPos.IncRow();
+ CPPUNIT_ASSERT_EQUAL( 11000.0 * nSheet, m_pDoc->GetValue(aPos));
+ aPos.IncRow();
+ CPPUNIT_ASSERT_EQUAL( 10000.0 * nSheet, m_pDoc->GetValue(aPos));
+ aPos.IncRow();
+ CPPUNIT_ASSERT_EQUAL( 1100000.0 * nSheet, m_pDoc->GetValue(aPos));
}
void Test::testFormulaRefUpdateNameDelete()
commit 58f4f2491b4f1705ad7064131203b0854485fc43
Author: Eike Rathke <erack at redhat.com>
Date: Thu Mar 31 22:22:12 2016 +0200
add ScDocument::InsertNewRangeName() for sheet-local scope
Change-Id: Id7e13a31a092e83c9c7cf6334cced45a28000f98
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index 8caca17..4502a26 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -569,6 +569,19 @@ public:
*/
bool InsertNewRangeName( const OUString& rName, const ScAddress& rPos, const OUString& rExpr );
+ /**
+ * Insert a new named expression to a sheet-local scope.
+ *
+ * @param nTab sheet for local scope.
+ * @param rName name for the expression.
+ * @param rPos base position.
+ * @param rExpr formula expression to be associated with the name. The
+ * current grammar is used to compile this expression.
+ *
+ * @return true if inserted successfully, false otherwise.
+ */
+ bool InsertNewRangeName( SCTAB nTab, const OUString& rName, const ScAddress& rPos, const OUString& rExpr );
+
SCTAB GetMaxTableNumber() { return static_cast<SCTAB>(maTabs.size()) - 1; }
ScRangePairList* GetColNameRanges() { return &xColNameRanges; }
diff --git a/sc/source/core/data/documen3.cxx b/sc/source/core/data/documen3.cxx
index bbc0c42..c6ae38f 100644
--- a/sc/source/core/data/documen3.cxx
+++ b/sc/source/core/data/documen3.cxx
@@ -222,6 +222,16 @@ bool ScDocument::InsertNewRangeName( const OUString& rName, const ScAddress& rPo
return pGlobalNames->insert(pName);
}
+bool ScDocument::InsertNewRangeName( SCTAB nTab, const OUString& rName, const ScAddress& rPos, const OUString& rExpr )
+{
+ ScRangeName* pLocalNames = GetRangeName(nTab);
+ if (!pLocalNames)
+ return false;
+
+ ScRangeData* pName = new ScRangeData(this, rName, rExpr, rPos, ScRangeData::Type::Name, GetGrammar());
+ return pLocalNames->insert(pName);
+}
+
const ScRangeData* ScDocument::GetRangeAtBlock( const ScRange& rBlock, OUString* pName ) const
{
const ScRangeData* pData = nullptr;
More information about the Libreoffice-commits
mailing list