[Libreoffice-commits] .: sc/inc sc/qa sc/source

Kohei Yoshida kohei at kemper.freedesktop.org
Wed Jan 11 19:01:42 PST 2012


 sc/inc/dpobject.hxx              |    3 ++-
 sc/qa/unit/ucalc.cxx             |   12 +++++++++++-
 sc/source/core/data/dpobject.cxx |   17 ++++++++++++++---
 3 files changed, 27 insertions(+), 5 deletions(-)

New commits:
commit ca73d85cc813a2a95fbbba35be6de6dc5ff2967f
Author: Kohei Yoshida <kohei.yoshida at suse.com>
Date:   Wed Jan 11 22:00:50 2012 -0500

    Test code for sheet source data cache relocation.

diff --git a/sc/inc/dpobject.hxx b/sc/inc/dpobject.hxx
index 48e43eb..dc20944 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 ac683a0..b9e3013 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 d384cd9..063c02a 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)


More information about the Libreoffice-commits mailing list