Kaydet (Commit) ca73d85c authored tarafından Kohei Yoshida's avatar Kohei Yoshida

Test code for sheet source data cache relocation.

üst 278c9130
...@@ -266,6 +266,7 @@ public: ...@@ -266,6 +266,7 @@ public:
ScDocument* mpDoc; ScDocument* mpDoc;
public: public:
SheetCaches(ScDocument* pDoc); SheetCaches(ScDocument* pDoc);
bool hasCache(const ScRange& rRange) const;
const ScDPCache* getCache(const ScRange& rRange); const ScDPCache* getCache(const ScRange& rRange);
void updateReference( void updateReference(
...@@ -286,7 +287,7 @@ public: ...@@ -286,7 +287,7 @@ public:
ScDocument* mpDoc; ScDocument* mpDoc;
public: public:
NameCaches(ScDocument* pDoc); 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); const ScDPCache* getCache(const ::rtl::OUString& rName, const ScRange& rRange);
private: private:
void removeCache(const ::rtl::OUString& rName); void removeCache(const ::rtl::OUString& rName);
......
...@@ -1386,6 +1386,16 @@ void Test::testDataPilot() ...@@ -1386,6 +1386,16 @@ void Test::testDataPilot()
CPPUNIT_ASSERT_MESSAGE("Table output check failed", bSuccess); 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); pDPs->FreeTable(pDPObj2);
CPPUNIT_ASSERT_MESSAGE("There shouldn't be any data pilot table stored with the document.", CPPUNIT_ASSERT_MESSAGE("There shouldn't be any data pilot table stored with the document.",
pDPs->GetCount() == 0); pDPs->GetCount() == 0);
...@@ -1671,7 +1681,7 @@ void Test::testDataPilotNamedSource() ...@@ -1671,7 +1681,7 @@ void Test::testDataPilotNamedSource()
CPPUNIT_ASSERT_MESSAGE("Named source range has been altered unexpectedly!", CPPUNIT_ASSERT_MESSAGE("Named source range has been altered unexpectedly!",
pDesc->GetRangeName().equals(aRangeName)); 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); pDPs->FreeTable(pDPObj);
CPPUNIT_ASSERT_MESSAGE("There should be no more tables.", pDPs->GetCount() == 0); CPPUNIT_ASSERT_MESSAGE("There should be no more tables.", pDPs->GetCount() == 0);
......
...@@ -2471,6 +2471,18 @@ struct FindInvalidRange : public std::unary_function<ScRange, bool> ...@@ -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) const ScDPCache* ScDPCollection::SheetCaches::getCache(const ScRange& rRange)
{ {
RangeIndexType::iterator it = std::find(maRanges.begin(), maRanges.end(), rRange); RangeIndexType::iterator it = std::find(maRanges.begin(), maRanges.end(), rRange);
...@@ -2565,10 +2577,9 @@ void ScDPCollection::SheetCaches::removeCache(const ScRange& rRange) ...@@ -2565,10 +2577,9 @@ void ScDPCollection::SheetCaches::removeCache(const ScRange& rRange)
ScDPCollection::NameCaches::NameCaches(ScDocument* pDoc) : mpDoc(pDoc) {} 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 maCaches.count(rName) != 0;
return itr != maCaches.end() ? itr->second : NULL;
} }
const ScDPCache* ScDPCollection::NameCaches::getCache(const OUString& rName, const ScRange& rRange) const ScDPCache* ScDPCollection::NameCaches::getCache(const OUString& rName, const ScRange& rRange)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment