summaryrefslogtreecommitdiff
path: root/sw/qa
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2011-11-03 11:00:38 +0000
committerCaolán McNamara <caolanm@redhat.com>2011-11-03 12:18:17 +0000
commit12db5315fca413ae66e88c4cd8212ee3b01667b7 (patch)
tree2e8abe3a62ee41a39b3a7aeaf261923f02bc41f6 /sw/qa
parent56d5a48099165dabb72eb3a2655c2eb503684f1c (diff)
Follow UAX-29 and present user-perceived character counts
Not a count of code-units, nor a count of code-points, but try and follow http://unicode.org/reports/tr29/ and present the grapheme count. Add a few representative tests to try and avoid gotchas.
Diffstat (limited to 'sw/qa')
-rw-r--r--sw/qa/core/swdoc-test.cxx40
1 files changed, 32 insertions, 8 deletions
diff --git a/sw/qa/core/swdoc-test.cxx b/sw/qa/core/swdoc-test.cxx
index 3d27fa071d39..d6f145f0d9bf 100644
--- a/sw/qa/core/swdoc-test.cxx
+++ b/sw/qa/core/swdoc-test.cxx
@@ -41,19 +41,20 @@
#include <sfx2/docfile.hxx>
#include <sfx2/sfxmodelfactory.hxx>
-#include "init.hxx"
-#include "swtypes.hxx"
-#include "docstat.hxx"
+#include "breakit.hxx"
#include "doc.hxx"
-#include "ndtxt.hxx"
#include "docsh.hxx"
-#include "shellres.hxx"
+#include "docstat.hxx"
#include "docufld.hxx"
#include "fmtanchr.hxx"
-#include "swscanner.hxx"
+#include "init.hxx"
+#include "ndtxt.hxx"
+#include "shellio.hxx"
+#include "shellres.hxx"
#include "swcrsr.hxx"
+#include "swscanner.hxx"
#include "swmodule.hxx"
-#include "shellio.hxx"
+#include "swtypes.hxx"
SO2_DECL_REF(SwDocShell)
SO2_IMPL_REF(SwDocShell)
@@ -73,14 +74,15 @@ public:
void testFileNameFields();
void testDocStat();
void testSwScanner();
+ void testUserPerceivedCharCount();
void testGraphicAnchorDeletion();
CPPUNIT_TEST_SUITE(SwDocTest);
CPPUNIT_TEST(randomTest);
CPPUNIT_TEST(testPageDescName);
CPPUNIT_TEST(testFileNameFields);
- CPPUNIT_TEST(testDocStat);
CPPUNIT_TEST(testSwScanner);
+ CPPUNIT_TEST(testUserPerceivedCharCount);
CPPUNIT_TEST(testGraphicAnchorDeletion);
CPPUNIT_TEST_SUITE_END();
@@ -189,6 +191,28 @@ void SwDocTest::testDocStat()
CPPUNIT_ASSERT_MESSAGE("And cache is updated too", m_pDoc->GetDocStat().nChar == nLen);
}
+//For UI character counts we should follow UAX#29 and display the user
+//perceived characters, not the number of codepoints, nor the number of code
+//units http://unicode.org/reports/tr29/
+void SwDocTest::testUserPerceivedCharCount()
+{
+ SwBreakIt *pBreakIter = SwBreakIt::Get();
+
+ //Grapheme example, two different unicode code-points perceived by the user as a single
+ //glyph
+ const sal_Unicode ALEF_QAMATS [] = { 0x05D0, 0x05B8 };
+ ::rtl::OUString sALEF_QAMATS(ALEF_QAMATS, SAL_N_ELEMENTS(ALEF_QAMATS));
+ sal_Int32 nGraphemeCount = pBreakIter->getGraphemeCount(sALEF_QAMATS);
+ CPPUNIT_ASSERT_MESSAGE("Grapheme Count should be 1", nGraphemeCount == 1);
+
+ //Surrogate pair example, one single unicode code-point (U+1D11E)
+ //represented as two code units in UTF-8
+ const sal_Unicode GCLEF[] = { 0xD834, 0xDD1E };
+ ::rtl::OUString sGCLEF(GCLEF, SAL_N_ELEMENTS(GCLEF));
+ sal_Int32 nCount = pBreakIter->getGraphemeCount(sGCLEF);
+ CPPUNIT_ASSERT_MESSAGE("Surrogate Pair should be counted as single character", nCount == 1);
+}
+
//See https://bugs.freedesktop.org/show_bug.cgi?id=40449 for motivation
void SwDocTest::testSwScanner()
{