summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@suse.com>2012-01-11 22:00:50 -0500
committerKohei Yoshida <kohei.yoshida@suse.com>2012-01-11 22:00:50 -0500
commitc99e8165043041d1989c7d9ad47e89b40af00a56 (patch)
treeb66794b61c3bde8fb5d4b868f1a33a38fadc0c7c /sc
parent10a5404fd0fc2da42ba5b293363704af081ae308 (diff)
Test code for sheet source data cache relocation.
Diffstat (limited to 'sc')
-rw-r--r--sc/inc/dpobject.hxx3
-rw-r--r--sc/qa/unit/ucalc.cxx12
-rw-r--r--sc/source/core/data/dpobject.cxx17
3 files changed, 27 insertions, 5 deletions
diff --git a/sc/inc/dpobject.hxx b/sc/inc/dpobject.hxx
index 48e43eb60e67..dc2094484a20 100644
--- a/sc/inc/dpobject.hxx
+++ b/sc/inc/dpobject.hxx
@@ -266,6 +266,7 @@ public:
ScDocument* mpDoc;
public:
SheetCaches(ScDocument* pDoc);
+ bool hasCache(const ScRange& rRange) const;
const ScDPCache* getCache(const ScRange& rRange);
void updateReference(
@@ -286,7 +287,7 @@ public:
ScDocument* mpDoc;
public:
NameCaches(ScDocument* pDoc);
- const ScDPCache* getCache(const rtl::OUString& rName) const;
+ bool hasCache(const rtl::OUString& rName) const;
const ScDPCache* getCache(const ::rtl::OUString& rName, const ScRange& rRange);
private:
void removeCache(const ::rtl::OUString& rName);
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index ebb368a748a3..419ce6307ed7 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -1386,6 +1386,16 @@ void Test::testDataPilot()
CPPUNIT_ASSERT_MESSAGE("Table output check failed", bSuccess);
}
+ CPPUNIT_ASSERT_MESSAGE("Cache should be here.", pDPs->GetSheetCaches().hasCache(aSrcRange));
+
+ // Swap the two sheets.
+ m_pDoc->MoveTab(1, 0);
+ CPPUNIT_ASSERT_MESSAGE("Cache should have moved.", !pDPs->GetSheetCaches().hasCache(aSrcRange));
+ aSrcRange.aStart.SetTab(1);
+ aSrcRange.aEnd.SetTab(1);
+ CPPUNIT_ASSERT_MESSAGE("Cache should be here.", pDPs->GetSheetCaches().hasCache(aSrcRange));
+
+
pDPs->FreeTable(pDPObj2);
CPPUNIT_ASSERT_MESSAGE("There shouldn't be any data pilot table stored with the document.",
pDPs->GetCount() == 0);
@@ -1671,7 +1681,7 @@ void Test::testDataPilotNamedSource()
CPPUNIT_ASSERT_MESSAGE("Named source range has been altered unexpectedly!",
pDesc->GetRangeName().equals(aRangeName));
- CPPUNIT_ASSERT_MESSAGE("Cache should exist.", pDPs->GetNameCaches().getCache(aRangeName) != NULL);
+ CPPUNIT_ASSERT_MESSAGE("Cache should exist.", pDPs->GetNameCaches().hasCache(aRangeName));
pDPs->FreeTable(pDPObj);
CPPUNIT_ASSERT_MESSAGE("There should be no more tables.", pDPs->GetCount() == 0);
diff --git a/sc/source/core/data/dpobject.cxx b/sc/source/core/data/dpobject.cxx
index d384cd99b471..063c02adb5f3 100644
--- a/sc/source/core/data/dpobject.cxx
+++ b/sc/source/core/data/dpobject.cxx
@@ -2471,6 +2471,18 @@ struct FindInvalidRange : public std::unary_function<ScRange, bool>
}
+bool ScDPCollection::SheetCaches::hasCache(const ScRange& rRange) const
+{
+ RangeIndexType::const_iterator it = std::find(maRanges.begin(), maRanges.end(), rRange);
+ if (it == maRanges.end())
+ return false;
+
+ // Already cached.
+ size_t nIndex = std::distance(maRanges.begin(), it);
+ CachesType::const_iterator itCache = maCaches.find(nIndex);
+ return itCache != maCaches.end();
+}
+
const ScDPCache* ScDPCollection::SheetCaches::getCache(const ScRange& rRange)
{
RangeIndexType::iterator it = std::find(maRanges.begin(), maRanges.end(), rRange);
@@ -2565,10 +2577,9 @@ void ScDPCollection::SheetCaches::removeCache(const ScRange& rRange)
ScDPCollection::NameCaches::NameCaches(ScDocument* pDoc) : mpDoc(pDoc) {}
-const ScDPCache* ScDPCollection::NameCaches::getCache(const OUString& rName) const
+bool ScDPCollection::NameCaches::hasCache(const OUString& rName) const
{
- CachesType::const_iterator itr = maCaches.find(rName);
- return itr != maCaches.end() ? itr->second : NULL;
+ return maCaches.count(rName) != 0;
}
const ScDPCache* ScDPCollection::NameCaches::getCache(const OUString& rName, const ScRange& rRange)