[Libreoffice-commits] core.git: Branch 'private/kohei/calc-shared-string' - 2 commits - svl/qa svl/source

Kohei Yoshida kohei.yoshida at collabora.com
Wed Oct 2 16:18:56 PDT 2013


 svl/qa/unit/svl.cxx            |   46 ++++++++++++++++++++++++++++++++++++++++-
 svl/source/misc/stringpool.cxx |    2 -
 2 files changed, 46 insertions(+), 2 deletions(-)

New commits:
commit c786fbb543b429d45c47ca526153d949a62b44a7
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Wed Oct 2 19:11:28 2013 -0400

    A little more test on shared string pool's life cycle management.
    
    Change-Id: Ic676dd875c27ce60a0707903d7f22207764829e0

diff --git a/svl/qa/unit/svl.cxx b/svl/qa/unit/svl.cxx
index 90f4c44..11a52e6 100644
--- a/svl/qa/unit/svl.cxx
+++ b/svl/qa/unit/svl.cxx
@@ -36,6 +36,8 @@
 #include "svl/stringpool.hxx"
 #include "unotools/syslocale.hxx"
 
+#include <boost/scoped_ptr.hpp>
+
 #define DEBUG_UNIT_TEST 1
 
 #if DEBUG_UNIT_TEST
@@ -353,6 +355,48 @@ void Test::testStringPoolPurge()
     aPool.purge();
     CPPUNIT_ASSERT_MESSAGE("Wrong string count.", aPool.getCount() == 0);
     CPPUNIT_ASSERT_MESSAGE("Wrong case insensitive string count.", aPool.getCountIgnoreCase() == 0);
+
+    // Now, create string objects on the heap.
+    boost::scoped_ptr<OUString> pStr1(new OUString("Andy"));
+    boost::scoped_ptr<OUString> pStr2(new OUString("andy"));
+    boost::scoped_ptr<OUString> pStr3(new OUString("ANDY"));
+    boost::scoped_ptr<OUString> pStr4(new OUString("Bruce"));
+    aPool.intern(*pStr1);
+    aPool.intern(*pStr2);
+    aPool.intern(*pStr3);
+    aPool.intern(*pStr4);
+
+    CPPUNIT_ASSERT_MESSAGE("Wrong string count.", aPool.getCount() == 4);
+    CPPUNIT_ASSERT_MESSAGE("Wrong case insensitive string count.", aPool.getCountIgnoreCase() == 2);
+
+    // This shouldn't purge anything.
+    aPool.purge();
+    CPPUNIT_ASSERT_MESSAGE("Wrong string count.", aPool.getCount() == 4);
+    CPPUNIT_ASSERT_MESSAGE("Wrong case insensitive string count.", aPool.getCountIgnoreCase() == 2);
+
+    // Delete one heap string object, and purge. That should purge one string.
+    pStr1.reset();
+    aPool.purge();
+    CPPUNIT_ASSERT_MESSAGE("Wrong string count.", aPool.getCount() == 3);
+    CPPUNIT_ASSERT_MESSAGE("Wrong case insensitive string count.", aPool.getCountIgnoreCase() == 2);
+
+    // Ditto...
+    pStr3.reset();
+    aPool.purge();
+    CPPUNIT_ASSERT_MESSAGE("Wrong string count.", aPool.getCount() == 2);
+    CPPUNIT_ASSERT_MESSAGE("Wrong case insensitive string count.", aPool.getCountIgnoreCase() == 2);
+
+    // Again.
+    pStr2.reset();
+    aPool.purge();
+    CPPUNIT_ASSERT_MESSAGE("Wrong string count.", aPool.getCount() == 1);
+    CPPUNIT_ASSERT_MESSAGE("Wrong case insensitive string count.", aPool.getCountIgnoreCase() == 1);
+
+    // Delete 'Bruce' and purge.
+    pStr4.reset();
+    aPool.purge();
+    CPPUNIT_ASSERT_MESSAGE("Wrong string count.", aPool.getCount() == 0);
+    CPPUNIT_ASSERT_MESSAGE("Wrong case insensitive string count.", aPool.getCountIgnoreCase() == 0);
 }
 
 void Test::checkPreviewString(SvNumberFormatter& aFormatter,
commit b6145444f30a26b271c35cf509049d6d4baaaaeb
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Wed Oct 2 18:54:28 2013 -0400

    No need to intern strings here; all OUString's are ref-counted.
    
    Calling intern() simply moves it to a global hash storage.  Now
    the test passes.
    
    Change-Id: I0a93420abce1c3adaaa61d469dff5f359dd5ada4

diff --git a/svl/qa/unit/svl.cxx b/svl/qa/unit/svl.cxx
index 26cad83..90f4c44 100644
--- a/svl/qa/unit/svl.cxx
+++ b/svl/qa/unit/svl.cxx
@@ -75,7 +75,7 @@ public:
     CPPUNIT_TEST_SUITE(Test);
     CPPUNIT_TEST(testNumberFormat);
     CPPUNIT_TEST(testStringPool);
-//  CPPUNIT_TEST(testStringPoolPurge); // FIXME: String pool's life cycle needs more work.
+    CPPUNIT_TEST(testStringPoolPurge);
     CPPUNIT_TEST(testFdo60915);
     CPPUNIT_TEST(testI116701);
     CPPUNIT_TEST_SUITE_END();
diff --git a/svl/source/misc/stringpool.cxx b/svl/source/misc/stringpool.cxx
index f4d9996..4760348 100644
--- a/svl/source/misc/stringpool.cxx
+++ b/svl/source/misc/stringpool.cxx
@@ -128,7 +128,7 @@ StringPool::InsertResultType StringPool::findOrInsert( StrHashType& rPool, const
     if (it == rPool.end())
     {
         // Not yet in the pool.
-        std::pair<StrHashType::iterator, bool> r = rPool.insert(rStr.intern());
+        std::pair<StrHashType::iterator, bool> r = rPool.insert(rStr);
         if (!r.second)
             // Insertion failed.
             return InsertResultType(rPool.end(), false);


More information about the Libreoffice-commits mailing list