summaryrefslogtreecommitdiff
path: root/svl
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@collabora.com>2013-10-02 11:29:42 -0400
committerKohei Yoshida <kohei.yoshida@collabora.com>2013-10-04 19:15:22 -0400
commit4d076d4ceeb05061b6b0699c19af9ba5ed0fcd00 (patch)
tree1cca2e9da7b436a91addc3590d5a209e61129be7 /svl
parent5d3ea0cde3f4c61832c48281e75dabd22621a893 (diff)
Write some rudimentary tests for the new shared string pool class.
Change-Id: Ie66de46d69f664839aa0a2d056cd3b8df4d4989b
Diffstat (limited to 'svl')
-rw-r--r--svl/qa/unit/svl.cxx40
-rw-r--r--svl/source/misc/stringpool.cxx12
2 files changed, 51 insertions, 1 deletions
diff --git a/svl/qa/unit/svl.cxx b/svl/qa/unit/svl.cxx
index 8d46ecff46e8..f41ab737783d 100644
--- a/svl/qa/unit/svl.cxx
+++ b/svl/qa/unit/svl.cxx
@@ -33,6 +33,8 @@
#include "svl/zforlist.hxx"
#include "svl/zformat.hxx"
+#include "svl/stringpool.hxx"
+#include "unotools/syslocale.hxx"
#define DEBUG_UNIT_TEST 0
@@ -65,11 +67,13 @@ public:
virtual void tearDown();
void testNumberFormat();
+ void testStringPool();
void testFdo60915();
void testI116701();
CPPUNIT_TEST_SUITE(Test);
CPPUNIT_TEST(testNumberFormat);
+ CPPUNIT_TEST(testStringPool);
CPPUNIT_TEST(testFdo60915);
CPPUNIT_TEST(testI116701);
CPPUNIT_TEST_SUITE_END();
@@ -288,6 +292,42 @@ void Test::testNumberFormat()
}
}
+void Test::testStringPool()
+{
+ SvtSysLocale aSysLocale;
+ svl::StringPool aPool(aSysLocale.GetCharClassPtr());
+
+ const rtl_uString* p1 = aPool.intern("Andy");
+ const rtl_uString* p2 = aPool.intern("Andy");
+ CPPUNIT_ASSERT_EQUAL(p1, p2);
+
+ p2 = aPool.intern("Bruce");
+ CPPUNIT_ASSERT_MESSAGE("They must differ.", p1 != p2);
+
+ OUString aAndy("Andy");
+ p2 = aPool.getIdentifier(aAndy);
+ CPPUNIT_ASSERT_EQUAL(p1, p2);
+
+ // Test case insensitive string ID's.
+ OUString aAndyLower("andy"), aAndyUpper("ANDY");
+ p1 = aPool.getIdentifier("Andy");
+ CPPUNIT_ASSERT_MESSAGE("This shouldn't be NULL.", p1);
+ p2 = aPool.intern(aAndyLower);
+ CPPUNIT_ASSERT_MESSAGE("They must differ.", p1 != p2);
+ p2 = aPool.intern(aAndyUpper);
+ CPPUNIT_ASSERT_MESSAGE("They must differ.", p1 != p2);
+
+ p1 = aPool.getIdentifierIgnoreCase("Andy");
+ CPPUNIT_ASSERT_MESSAGE("This shouldn't be NULL.", p1);
+ p2 = aPool.getIdentifierIgnoreCase("andy");
+ CPPUNIT_ASSERT_MESSAGE("This shouldn't be NULL.", p2);
+ CPPUNIT_ASSERT_EQUAL(p1, p2);
+
+ p2 = aPool.getIdentifierIgnoreCase("ANDY");
+ CPPUNIT_ASSERT_MESSAGE("This shouldn't be NULL.", p2);
+ CPPUNIT_ASSERT_EQUAL(p1, p2);
+}
+
void Test::checkPreviewString(SvNumberFormatter& aFormatter,
const OUString& sCode,
double fPreviewNumber,
diff --git a/svl/source/misc/stringpool.cxx b/svl/source/misc/stringpool.cxx
index 46462d1e7a59..1181538e4ecf 100644
--- a/svl/source/misc/stringpool.cxx
+++ b/svl/source/misc/stringpool.cxx
@@ -13,7 +13,7 @@
namespace svl {
StringPool::StringPool() : mpCharClass(NULL) {}
-StringPool::StringPool( CharClass* pCharClass ) : mpCharClass(pCharClass) {}
+StringPool::StringPool( const CharClass* pCharClass ) : mpCharClass(pCharClass) {}
rtl_uString* StringPool::intern( const OUString& rStr )
{
@@ -52,6 +52,16 @@ const rtl_uString* StringPool::getIdentifier( const OUString& rStr ) const
return (it == maStrPool.end()) ? NULL : it->pData;
}
+const rtl_uString* StringPool::getIdentifierIgnoreCase( const OUString& rStr ) const
+{
+ if (!mpCharClass)
+ return NULL;
+
+ OUString aUpper = mpCharClass->uppercase(rStr);
+ StrHashType::iterator it = maStrPoolUpper.find(aUpper);
+ return (it == maStrPool.end()) ? NULL : it->pData;
+}
+
StringPool::InsertResultType StringPool::findOrInsert( StrHashType& rPool, const OUString& rStr ) const
{
StrHashType::iterator it = rPool.find(rStr);