diff options
author | Kohei Yoshida <kohei.yoshida@collabora.com> | 2013-10-03 14:24:28 -0400 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@collabora.com> | 2013-10-04 19:15:24 -0400 |
commit | 875f47cb5a20e2ce6ed54d88fd5bbf1d6128a47d (patch) | |
tree | d052055b297e3c8de85390a85482202349731976 /sc/qa | |
parent | f6ec66727379fef56f0972e2a6181e39ab6d4ec1 (diff) |
Add methods to turn cell strings into numeric IDs for comparison.
Both in case sensitive and case insensitive comparisons.
Change-Id: I356a655273f0f37157810c86e1cf3f87ea2afa09
Diffstat (limited to 'sc/qa')
-rw-r--r-- | sc/qa/unit/ucalc.cxx | 80 | ||||
-rw-r--r-- | sc/qa/unit/ucalc.hxx | 2 |
2 files changed, 82 insertions, 0 deletions
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx index 8d2266e0e80c..ba9a78e5c546 100644 --- a/sc/qa/unit/ucalc.cxx +++ b/sc/qa/unit/ucalc.cxx @@ -63,6 +63,7 @@ #include <svx/svdocirc.hxx> #include <svx/svdopath.hxx> #include "svl/srchitem.hxx" +#include "svl/stringpool.hxx" #include <sfx2/docfile.hxx> @@ -458,6 +459,85 @@ void Test::testCollator() CPPUNIT_ASSERT_MESSAGE("these strings are supposed to be different!", nRes != 0); } +void Test::testCellStringPool() +{ + m_pDoc->InsertTab(0, "foo"); + + // Strings that are identical. + m_pDoc->SetString(ScAddress(0,0,0), "Andy"); // A1 + m_pDoc->SetString(ScAddress(0,1,0), "Andy"); // A2 + m_pDoc->SetString(ScAddress(0,2,0), "Bruce"); // A3 + m_pDoc->SetString(ScAddress(0,3,0), "andy"); // A4 + m_pDoc->SetString(ScAddress(0,4,0), "BRUCE"); // A5 + + sal_uIntPtr nId1 = m_pDoc->GetCellStringID(ScAddress(0,0,0)); + sal_uIntPtr nId2 = m_pDoc->GetCellStringID(ScAddress(0,1,0)); + CPPUNIT_ASSERT_MESSAGE("Failed to get a valid string ID.", nId1); + CPPUNIT_ASSERT_MESSAGE("Failed to get a valid string ID.", nId2); + CPPUNIT_ASSERT_EQUAL(nId1, nId2); + + nId2 = m_pDoc->GetCellStringID(ScAddress(0,2,0)); + CPPUNIT_ASSERT_MESSAGE("They must differ", nId1 != nId2); + + nId2 = m_pDoc->GetCellStringID(ScAddress(0,3,0)); + CPPUNIT_ASSERT_MESSAGE("They must differ", nId1 != nId2); + + nId2 = m_pDoc->GetCellStringID(ScAddress(0,4,0)); + CPPUNIT_ASSERT_MESSAGE("They must differ", nId1 != nId2); + + // A3 and A5 should differ but should be equal case-insensitively. + nId1 = m_pDoc->GetCellStringID(ScAddress(0,2,0)); + nId2 = m_pDoc->GetCellStringID(ScAddress(0,4,0)); + CPPUNIT_ASSERT_MESSAGE("They must differ", nId1 != nId2); + + nId1 = m_pDoc->GetCellStringIDIgnoreCase(ScAddress(0,2,0)); + nId2 = m_pDoc->GetCellStringIDIgnoreCase(ScAddress(0,4,0)); + CPPUNIT_ASSERT_MESSAGE("They must be equal when cases are ignored.", nId1 == nId2); + + // A2 and A4 should be equal when ignoring cases. + nId1 = m_pDoc->GetCellStringIDIgnoreCase(ScAddress(0,1,0)); + nId2 = m_pDoc->GetCellStringIDIgnoreCase(ScAddress(0,3,0)); + CPPUNIT_ASSERT_MESSAGE("They must be equal when cases are ignored.", nId1 == nId2); + + // Check the string counts after purging. Purging shouldn't remove any strings in this case. + svl::StringPool& rPool = m_pDoc->GetCellStringPool(); + rPool.purge(); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(4), rPool.getCount()); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), rPool.getCountIgnoreCase()); + + // Clear A1 and purge again. + clearRange(m_pDoc, ScAddress(0,0,0)); + rPool.purge(); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(4), rPool.getCount()); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), rPool.getCountIgnoreCase()); + + // Clear A2 and purge again. + clearRange(m_pDoc, ScAddress(0,1,0)); + rPool.purge(); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), rPool.getCount()); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), rPool.getCountIgnoreCase()); + + // Clear A3 and purge again. + clearRange(m_pDoc, ScAddress(0,2,0)); + rPool.purge(); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), rPool.getCount()); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), rPool.getCountIgnoreCase()); + + // Clear A4 and purge again. + clearRange(m_pDoc, ScAddress(0,3,0)); + rPool.purge(); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), rPool.getCount()); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), rPool.getCountIgnoreCase()); + + // Clear A5 and the pool should be completely empty. + clearRange(m_pDoc, ScAddress(0,4,0)); + rPool.purge(); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), rPool.getCount()); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), rPool.getCountIgnoreCase()); + + m_pDoc->DeleteTab(0); +} + void Test::testRangeList() { m_pDoc->InsertTab(0, "foo"); diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx index d01714ee700e..d1ba668e52c8 100644 --- a/sc/qa/unit/ucalc.hxx +++ b/sc/qa/unit/ucalc.hxx @@ -80,6 +80,7 @@ public: */ void testPerf(); void testCollator(); + void testCellStringPool(); void testRangeList(); void testInput(); @@ -284,6 +285,7 @@ public: CPPUNIT_TEST(testPerf); #endif CPPUNIT_TEST(testCollator); + CPPUNIT_TEST(testCellStringPool); CPPUNIT_TEST(testRangeList); CPPUNIT_TEST(testInput); CPPUNIT_TEST(testFormulaHashAndTag); |