summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@collabora.com>2014-02-18 22:11:10 -0500
committerKohei Yoshida <kohei.yoshida@collabora.com>2014-02-18 22:59:41 -0500
commit891817922121765cef65ae73ebf7fdc524083d20 (patch)
tree975891972cd4fe044efdd062147e8a545e0d3035
parentb9bd3229e0e03f853a8607b0ab613c6dfbd5e9ac (diff)
fdo#72491: Add test for this.
Change-Id: Ic37402cb950783b080e5f185b98b19aea62efa7e
-rw-r--r--sc/qa/unit/ucalc.cxx87
-rw-r--r--sc/qa/unit/ucalc.hxx9
2 files changed, 75 insertions, 21 deletions
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index c7c9ba51cd17..ed84bf251c1e 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -1729,9 +1729,7 @@ void Test::testFuncParam()
void Test::testNamedRange()
{
- struct {
- const char* pName; const char* pExpr; sal_uInt16 nIndex;
- } aNames[] = {
+ RangeNameDef aNames[] = {
{ "Divisor", "$Sheet1.$A$1:$A$1048576", 1 },
{ "MyRange1", "$Sheet1.$A$1:$A$100", 2 },
{ "MyRange2", "$Sheet1.$B$1:$B$100", 3 },
@@ -1742,31 +1740,22 @@ void Test::testNamedRange()
m_pDoc->SetValue (0, 0, 0, 101);
- ScAddress aA1(0, 0, 0);
- ScRangeName* pNewRanges = new ScRangeName();
- for (size_t i = 0; i < SAL_N_ELEMENTS(aNames); ++i)
- {
- ScRangeData* pNew = new ScRangeData(
- m_pDoc,
- OUString::createFromAscii(aNames[i].pName),
- OUString::createFromAscii(aNames[i].pExpr),
- aA1, 0, formula::FormulaGrammar::GRAM_ENGLISH);
- pNew->SetIndex(aNames[i].nIndex);
- bool bSuccess = pNewRanges->insert(pNew);
- CPPUNIT_ASSERT_MESSAGE ("insertion failed", bSuccess);
- }
+ bool bSuccess = insertRangeNames(m_pDoc, aNames, aNames + SAL_N_ELEMENTS(aNames));
+ CPPUNIT_ASSERT_MESSAGE("Failed to insert range names.", bSuccess);
+
+ ScRangeName* pNewRanges = m_pDoc->GetRangeName();
+ CPPUNIT_ASSERT(pNewRanges);
// Make sure the index lookup does the right thing.
for (size_t i = 0; i < SAL_N_ELEMENTS(aNames); ++i)
{
- const ScRangeData* p = pNewRanges->findByIndex(aNames[i].nIndex);
+ const ScRangeData* p = pNewRanges->findByIndex(aNames[i].mnIndex);
CPPUNIT_ASSERT_MESSAGE("lookup of range name by index failed.", p);
OUString aName = p->GetName();
- CPPUNIT_ASSERT_MESSAGE("wrong range name is retrieved.", aName.equalsAscii(aNames[i].pName));
+ CPPUNIT_ASSERT_MESSAGE("wrong range name is retrieved.", aName.equalsAscii(aNames[i].mpName));
}
// Test usage in formula expression.
- m_pDoc->SetRangeName(pNewRanges);
m_pDoc->SetString (1, 0, 0, OUString("=A1/Divisor"));
m_pDoc->CalcAll();
@@ -1780,16 +1769,48 @@ void Test::testNamedRange()
// Make sure the index lookup still works.
for (size_t i = 0; i < SAL_N_ELEMENTS(aNames); ++i)
{
- const ScRangeData* p = pCopiedRanges->findByIndex(aNames[i].nIndex);
+ const ScRangeData* p = pCopiedRanges->findByIndex(aNames[i].mnIndex);
CPPUNIT_ASSERT_MESSAGE("lookup of range name by index failed with the copied instance.", p);
OUString aName = p->GetName();
- CPPUNIT_ASSERT_MESSAGE("wrong range name is retrieved with the copied instance.", aName.equalsAscii(aNames[i].pName));
+ CPPUNIT_ASSERT_MESSAGE("wrong range name is retrieved with the copied instance.", aName.equalsAscii(aNames[i].mpName));
}
m_pDoc->SetRangeName(NULL); // Delete the names.
m_pDoc->DeleteTab(0);
}
+void Test::testInsertNameList()
+{
+ m_pDoc->InsertTab(0, "Test");
+
+ RangeNameDef aNames[] = {
+ { "MyRange1", "$Test.$A$1:$A$100", 1 },
+ { "MyRange2", "$Test.$B$1:$B$100", 2 },
+ { "MyRange3", "$Test.$C$1:$C$100", 3 }
+ };
+
+ bool bSuccess = insertRangeNames(m_pDoc, aNames, aNames + SAL_N_ELEMENTS(aNames));
+ CPPUNIT_ASSERT_MESSAGE("Failed to insert range names.", bSuccess);
+
+ ScDocFunc& rDocFunc = getDocShell().GetDocFunc();
+ ScAddress aPos(1,1,0);
+ rDocFunc.InsertNameList(aPos, true);
+
+ for (size_t i = 0; i < SAL_N_ELEMENTS(aNames); ++i, aPos.IncRow())
+ {
+ OUString aName = m_pDoc->GetString(aPos);
+ CPPUNIT_ASSERT_EQUAL(OUString::createFromAscii(aNames[i].mpName), aName);
+ ScAddress aExprPos = aPos;
+ aExprPos.IncCol();
+ OUString aExpr = m_pDoc->GetString(aExprPos);
+ OUString aExpected = "=";
+ aExpected += OUString::createFromAscii(aNames[i].mpExpr);
+ CPPUNIT_ASSERT_EQUAL(aExpected, aExpr);
+ }
+
+ m_pDoc->DeleteTab(0);
+}
+
void Test::testCSV()
{
const int English = 0, European = 1;
@@ -5845,6 +5866,30 @@ void Test::testMixData()
m_pDoc->DeleteTab(0);
}
+bool Test::insertRangeNames(ScDocument* pDoc, const RangeNameDef* p, const RangeNameDef* pEnd)
+{
+ ScAddress aA1(0, 0, 0);
+ ScRangeName* pNewRanges = new ScRangeName();
+ for (; p != pEnd; ++p)
+ {
+ ScRangeData* pNew = new ScRangeData(
+ pDoc,
+ OUString::createFromAscii(p->mpName),
+ OUString::createFromAscii(p->mpExpr),
+ aA1, 0, formula::FormulaGrammar::GRAM_ENGLISH);
+ pNew->SetIndex(p->mnIndex);
+ bool bSuccess = pNewRanges->insert(pNew);
+ if (!bSuccess)
+ {
+ cerr << "Insertion failed." << endl;
+ return false;
+ }
+ }
+
+ pDoc->SetRangeName(pNewRanges);
+ return true;
+}
+
void Test::printRange(ScDocument* pDoc, const ScRange& rRange, const char* pCaption)
{
SCROW nRow1 = rRange.aStart.Row(), nRow2 = rRange.aEnd.Row();
diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx
index 01cb9083e3e8..c40469a35bf5 100644
--- a/sc/qa/unit/ucalc.hxx
+++ b/sc/qa/unit/ucalc.hxx
@@ -31,7 +31,14 @@ public:
class Test : public test::BootstrapFixture
{
public:
+ struct RangeNameDef
+ {
+ const char* mpName;
+ const char* mpExpr;
+ sal_uInt16 mnIndex;
+ };
+ static bool insertRangeNames(ScDocument* pDoc, const RangeNameDef* p, const RangeNameDef* pEnd);
static void printRange(ScDocument* pDoc, const ScRange& rRange, const char* pCaption);
static void clearRange(ScDocument* pDoc, const ScRange& rRange);
static void copyToClip(ScDocument* pSrcDoc, const ScRange& rRange, ScDocument* pClipDoc);
@@ -160,6 +167,7 @@ public:
void testFuncParam();
void testNamedRange();
+ void testInsertNameList();
void testCSV();
void testMatrix();
void testEnterMixedMatrix();
@@ -377,6 +385,7 @@ public:
CPPUNIT_TEST(testCellBroadcaster);
CPPUNIT_TEST(testFuncParam);
CPPUNIT_TEST(testNamedRange);
+ CPPUNIT_TEST(testInsertNameList);
CPPUNIT_TEST(testCSV);
CPPUNIT_TEST(testMatrix);
CPPUNIT_TEST(testEnterMixedMatrix);