summaryrefslogtreecommitdiff
path: root/android/PhoneticStringUtilsTest.cpp
diff options
context:
space:
mode:
authorDaisuke Miyakawa <dmiyakawa@google.com>2009-05-18 23:55:56 -0700
committerThe Android Open Source Project <initial-contribution@android.com>2009-05-18 23:55:56 -0700
commitf890a25e8f49ca1c1880cfa494af925b17db4ca3 (patch)
treec4678417264476ca784a6ad3c1bd063cc92a5d82 /android/PhoneticStringUtilsTest.cpp
parent9ddb5ca32747bf2bfae7d6fd1bc6fcd6da293a25 (diff)
parentd28cdc45c5e3f29f8904759293c813ad0a58329e (diff)
am d28cdc45: Hand merge from cupcake_dcm from donut, part 1.
Merge commit 'd28cdc45c5e3f29f8904759293c813ad0a58329e' * commit 'd28cdc45c5e3f29f8904759293c813ad0a58329e': Hand merge from cupcake_dcm from donut, part 1.
Diffstat (limited to 'android/PhoneticStringUtilsTest.cpp')
-rw-r--r--android/PhoneticStringUtilsTest.cpp48
1 files changed, 47 insertions, 1 deletions
diff --git a/android/PhoneticStringUtilsTest.cpp b/android/PhoneticStringUtilsTest.cpp
index 0541007..e74f67f 100644
--- a/android/PhoneticStringUtilsTest.cpp
+++ b/android/PhoneticStringUtilsTest.cpp
@@ -36,6 +36,7 @@ class TestExecutor {
void testGetPhoneticallySortableCodePointSimpleCompare();
void testGetUtf8FromCodePoint();
void testGetPhoneticallySortableString();
+ void testGetNormalizedString();
// Note: When adding a test, do not forget to add it to DoOneTest().
@@ -71,6 +72,7 @@ bool TestExecutor::DoAllTests() {
DoOneTest(&TestExecutor::testGetPhoneticallySortableCodePointSimpleCompare);
DoOneTest(&TestExecutor::testGetUtf8FromCodePoint);
DoOneTest(&TestExecutor::testGetPhoneticallySortableString);
+ DoOneTest(&TestExecutor::testGetNormalizedString);
printf("Test total: %d\nSuccess: %d\nFailure: %d\n",
m_total_count, m_success_count, m_total_count - m_success_count);
@@ -232,7 +234,7 @@ void TestExecutor::testGetPhoneticallySortableCodePointKana() {
}
void TestExecutor::testGetPhoneticallySortableCodePointWhitespaceOnly() {
- printf("testGetPhoneticallySortableCodePointWhitespaceOnly");
+ printf("testGetPhoneticallySortableCodePointWhitespaceOnly()\n");
// Halfwidth space
int result = GetPhoneticallySortableCodePoint(0x0020, 0x0061, NULL);
ASSERT_EQ_VALUE(result, -1);
@@ -358,6 +360,7 @@ void TestExecutor::testGetUtf8FromCodePoint() {
})
void TestExecutor::testGetPhoneticallySortableString() {
+ printf("testGetPhoneticallySortableString()\n");
char *dst;
size_t len;
@@ -373,6 +376,49 @@ void TestExecutor::testGetPhoneticallySortableString() {
EXPECT_EQ_UTF8_UTF8(" \t", "\xF0\x9F\xBF\xBD");
}
+#undef EXPECT_EQ_UTF8_UTF8
+
+#define EXPECT_EQ_UTF8_UTF8(src, expected) \
+ ({ \
+ if (!GetNormalizedString(src, &dst, &len)) { \
+ printf("GetPhoneticallySortableString() returned false.\n"); \
+ m_success = false; \
+ } else { \
+ if (strcmp(dst, expected) != 0) { \
+ for (const char *ch = dst; *ch != '\0'; ++ch) { \
+ printf("0x%X ", *ch); \
+ } \
+ printf("!= "); \
+ for (const char *ch = expected; *ch != '\0'; ++ch) { \
+ printf("0x%X ", *ch); \
+ } \
+ printf("\n"); \
+ m_success = false; \
+ } \
+ free(dst); \
+ } \
+ })
+
+void TestExecutor::testGetNormalizedString() {
+ printf("testGetNormalizedString()\n");
+ char *dst;
+ size_t len;
+
+ // halfwidth alphabets/symbols -> keep it as is.
+ EXPECT_EQ_UTF8_UTF8("ABCDEFGHIJKLMNOPQRSTUVWXYZ!\"#$%^&'()",
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ!\"#$%^&'()");
+ EXPECT_EQ_UTF8_UTF8("abcdefghijklmnopqrstuvwxyz[]{}\\@/",
+ "abcdefghijklmnopqrstuvwxyz[]{}\\@/");
+
+ // halfwidth/fullwidth-katakana -> hiragana
+ EXPECT_EQ_UTF8_UTF8(
+ "\xE3\x81\x82\xE3\x82\xA4\xE3\x81\x86\xEF\xBD\xB4\xE3\x82\xAA",
+ "\xE3\x81\x82\xE3\x81\x84\xE3\x81\x86\xE3\x81\x88\xE3\x81\x8A");
+
+ // whitespace -> keep it as is.
+ EXPECT_EQ_UTF8_UTF8(" \t", " \t");
+}
+
int main() {
TestExecutor executor;
if(executor.DoAllTests()) {