summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@suse.com>2012-01-12 21:49:24 -0500
committerKohei Yoshida <kohei.yoshida@suse.com>2012-01-12 21:51:53 -0500
commit6d7fcd016e661c07b664b6c9b454c42c02537f10 (patch)
treeb5c7e91b63b222a346d384e0a764d47b0a3d902d /sc
parent65d58adcec970306ac641f49f56404b6be0e1462 (diff)
Test the new logic of our pivot data cache life cycle.
Diffstat (limited to 'sc')
-rw-r--r--sc/inc/dpobject.hxx4
-rw-r--r--sc/qa/unit/ucalc.cxx25
-rw-r--r--sc/source/core/data/dpobject.cxx25
3 files changed, 50 insertions, 4 deletions
diff --git a/sc/inc/dpobject.hxx b/sc/inc/dpobject.hxx
index 685f7d2947b7..47c1999a005b 100644
--- a/sc/inc/dpobject.hxx
+++ b/sc/inc/dpobject.hxx
@@ -271,6 +271,7 @@ public:
SheetCaches(ScDocument* pDoc);
bool hasCache(const ScRange& rRange) const;
const ScDPCache* getCache(const ScRange& rRange);
+ size_t size() const;
void updateReference(
UpdateRefMode eMode, const ScRange& r, SCsCOL nDx, SCsROW nDy, SCsTAB nDz);
@@ -294,6 +295,7 @@ public:
NameCaches(ScDocument* pDoc);
bool hasCache(const rtl::OUString& rName) const;
const ScDPCache* getCache(const ::rtl::OUString& rName, const ScRange& rRange);
+ size_t size() const;
private:
void updateCache(const rtl::OUString& rName, const ScRange& rRange, std::set<ScDPObject*>& rRefs);
void removeCache(const ::rtl::OUString& rName);
@@ -329,6 +331,8 @@ public:
public:
DBCaches(ScDocument* pDoc);
const ScDPCache* getCache(sal_Int32 nSdbType, const ::rtl::OUString& rDBName, const ::rtl::OUString& rCommand);
+ size_t size() const;
+
private:
com::sun::star::uno::Reference<com::sun::star::sdbc::XRowSet> createRowSet(
sal_Int32 nSdbType, const ::rtl::OUString& rDBName, const ::rtl::OUString& rCommand);
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index d2ebcc27b535..9b862759c9e2 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -1323,6 +1323,7 @@ void Test::testDataPilot()
bSuccess = checkDPTableOutput<5>(m_pDoc, aOutRange, aOutputCheck, "DataPilot table output");
CPPUNIT_ASSERT_MESSAGE("Table output check failed", bSuccess);
}
+ CPPUNIT_ASSERT_MESSAGE("There should be only one data cache.", pDPs->GetSheetCaches().size() == 1);
// Update the cell values.
double aData2[] = { 100, 200, 300, 400, 500, 600 };
@@ -1361,15 +1362,22 @@ void Test::testDataPilot()
CPPUNIT_ASSERT_MESSAGE("Table output check failed", bSuccess);
}
+ CPPUNIT_ASSERT_MESSAGE("There should be only one data cache.", pDPs->GetSheetCaches().size() == 1);
+
// Free the first datapilot object after the 2nd one gets reloaded, to
// prevent the data cache from being deleted before the reload.
pDPs->FreeTable(pDPObj);
+ CPPUNIT_ASSERT_MESSAGE("There should be only one data cache.", pDPs->GetSheetCaches().size() == 1);
+
// This time clear the cache to refresh the data from the source range.
CPPUNIT_ASSERT_MESSAGE("This datapilot should be based on sheet data.", pDPObj2->IsSheetData());
std::set<ScDPObject*> aRefs;
sal_uLong nErrId = pDPs->ReloadCache(pDPObj2, aRefs);
- CPPUNIT_ASSERT_MESSAGE("Cache removal failed.", nErrId == 0);
+ CPPUNIT_ASSERT_MESSAGE("Cache reload failed.", nErrId == 0);
+ CPPUNIT_ASSERT_MESSAGE("Reloading a cache shouldn't remove any cache.",
+ pDPs->GetSheetCaches().size() == 1);
+
pDPObj2->ClearSource();
pDPObj2->Output(aOutRange.aStart);
@@ -1395,6 +1403,8 @@ void Test::testDataPilot()
// Swap the two sheets.
m_pDoc->MoveTab(1, 0);
+ CPPUNIT_ASSERT_MESSAGE("Swapping the sheets shouldn't remove the cache.",
+ pDPs->GetSheetCaches().size() == 1);
CPPUNIT_ASSERT_MESSAGE("Cache should have moved.", !pDPs->GetSheetCaches().hasCache(aSrcRange));
aSrcRange.aStart.SetTab(1);
aSrcRange.aEnd.SetTab(1);
@@ -1404,6 +1414,9 @@ void Test::testDataPilot()
CPPUNIT_ASSERT_MESSAGE("There shouldn't be any data pilot table stored with the document.",
pDPs->GetCount() == 0);
+ CPPUNIT_ASSERT_MESSAGE("There shouldn't be any more data cache.",
+ pDPs->GetSheetCaches().size() == 0);
+
m_pDoc->DeleteTab(1);
m_pDoc->DeleteTab(0);
}
@@ -1673,6 +1686,9 @@ void Test::testDataPilotNamedSource()
CPPUNIT_ASSERT_MESSAGE("Table output check failed", bSuccess);
}
+ CPPUNIT_ASSERT_MESSAGE("There should be one named range data cache.",
+ pDPs->GetNameCaches().size() == 1 && pDPs->GetSheetCaches().size() == 0);
+
// Move the table with pivot table to the left of the source data sheet.
m_pDoc->MoveTab(1, 0);
rtl::OUString aTabName;
@@ -1680,14 +1696,21 @@ void Test::testDataPilotNamedSource()
CPPUNIT_ASSERT_MESSAGE("Wrong sheet name.", aTabName.equalsAscii("Table"));
CPPUNIT_ASSERT_MESSAGE("Pivot table output is on the wrong sheet!",
pDPObj->GetOutRange().aStart.Tab() == 0);
+
+ CPPUNIT_ASSERT_MESSAGE("Moving the pivot table to another sheet shouldn't have changed the cache state.",
+ pDPs->GetNameCaches().size() == 1 && pDPs->GetSheetCaches().size() == 0);
+
const ScSheetSourceDesc* pDesc = pDPObj->GetSheetDesc();
CPPUNIT_ASSERT_MESSAGE("Sheet source description doesn't exist.", pDesc);
CPPUNIT_ASSERT_MESSAGE("Named source range has been altered unexpectedly!",
pDesc->GetRangeName().equals(aRangeName));
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);
+ CPPUNIT_ASSERT_MESSAGE("There shouldn't be any more cache stored.",
+ pDPs->GetNameCaches().size() == 0);
pNames->clear();
m_pDoc->DeleteTab(1);
diff --git a/sc/source/core/data/dpobject.cxx b/sc/source/core/data/dpobject.cxx
index bc26c48d61f1..3113f1b43de6 100644
--- a/sc/source/core/data/dpobject.cxx
+++ b/sc/source/core/data/dpobject.cxx
@@ -2499,8 +2499,10 @@ const ScDPCache* ScDPCollection::SheetCaches::getCache(const ScRange& rRange)
size_t nIndex = std::distance(maRanges.begin(), it);
CachesType::iterator itCache = maCaches.find(nIndex);
if (itCache == maCaches.end())
- // cache pool and index pool out-of-sync !!!
+ {
+ OSL_FAIL("Cache pool and index pool out-of-sync !!!");
return NULL;
+ }
return itCache->second;
}
@@ -2532,6 +2534,11 @@ const ScDPCache* ScDPCollection::SheetCaches::getCache(const ScRange& rRange)
return p;
}
+size_t ScDPCollection::SheetCaches::size() const
+{
+ return maCaches.size();
+}
+
void ScDPCollection::SheetCaches::updateReference(
UpdateRefMode eMode, const ScRange& r, SCsCOL nDx, SCsROW nDy, SCsTAB nDz)
{
@@ -2579,7 +2586,7 @@ void ScDPCollection::SheetCaches::updateCache(const ScRange& rRange, std::set<Sc
CachesType::iterator itCache = maCaches.find(nIndex);
if (itCache == maCaches.end())
{
- // Cache pool and index pool out-of-sync !!!
+ OSL_FAIL("Cache pool and index pool out-of-sync !!!");
rRefs.clear();
return;
}
@@ -2600,8 +2607,10 @@ void ScDPCollection::SheetCaches::removeCache(const ScRange& rRange)
size_t nIndex = std::distance(maRanges.begin(), it);
CachesType::iterator itCache = maCaches.find(nIndex);
if (itCache == maCaches.end())
- // Cache pool and index pool out-of-sync !!!
+ {
+ OSL_FAIL("Cache pool and index pool out-of-sync !!!");
return;
+ }
it->SetInvalid(); // Make this slot available for future caches.
maCaches.erase(itCache);
@@ -2646,6 +2655,11 @@ const ScDPCache* ScDPCollection::NameCaches::getCache(const OUString& rName, con
return p;
}
+size_t ScDPCollection::NameCaches::size() const
+{
+ return maCaches.size();
+}
+
void ScDPCollection::NameCaches::updateCache(const OUString& rName, const ScRange& rRange, std::set<ScDPObject*>& rRefs)
{
CachesType::iterator itr = maCaches.find(rName);
@@ -2715,6 +2729,11 @@ const ScDPCache* ScDPCollection::DBCaches::getCache(sal_Int32 nSdbType, const OU
return p;
}
+size_t ScDPCollection::DBCaches::size() const
+{
+ return maCaches.size();
+}
+
uno::Reference<sdbc::XRowSet> ScDPCollection::DBCaches::createRowSet(
sal_Int32 nSdbType, const ::rtl::OUString& rDBName, const ::rtl::OUString& rCommand)
{