diff options
author | Kohei Yoshida <kohei.yoshida@suse.com> | 2012-01-11 22:00:50 -0500 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@suse.com> | 2012-01-11 22:01:57 -0500 |
commit | ca73d85cc813a2a95fbbba35be6de6dc5ff2967f (patch) | |
tree | 6ddc74fc53a5aced2e0c20f7360e9015f15c5233 | |
parent | 278c91304cbfb66b05cd39c16282bde944758093 (diff) |
Test code for sheet source data cache relocation.
-rw-r--r-- | sc/inc/dpobject.hxx | 3 | ||||
-rw-r--r-- | sc/qa/unit/ucalc.cxx | 12 | ||||
-rw-r--r-- | sc/source/core/data/dpobject.cxx | 17 |
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 ac683a0e01a4..b9e3013f2133 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) |