1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /********************************************************************
5 * Copyright (c) 1997-2009, International Business Machines Corporation and
6 * others. All Rights Reserved.
7 ********************************************************************/
8 /********************************************************************************
12 * Modification History:
14 * Madhu Katragadda Ported for C API
15 * synwee Added TestBase, TestPlainDakutenHandakuten,
16 * TestSmallLarge, TestKatakanaHiragana,
18 *********************************************************************************/
20 * CollationKannaTest is a third level test class. This tests the locale
21 * specific primary, secondary and tertiary rules. For example, the ignorable
22 * character '-' in string "black-bird". The en_US locale uses the default
23 * collation rules as its sorting sequence.
28 #include "unicode/utypes.h"
30 #if !UCONFIG_NO_COLLATION
32 #include "unicode/ucol.h"
33 #include "unicode/uloc.h"
38 #include "unicode/ustring.h"
41 static UCollator
*myCollation
;
42 const static UChar testSourceCases
[][MAX_TOKEN_LEN
] = {
46 {0x3042, 0x3042, 0x0000},
47 {0x30A2, 0x30FC, 0x0000},
48 {0x30A2, 0x30FC, 0x30C8, 0x0000} /* 6 */
51 const static UChar testTargetCases
[][MAX_TOKEN_LEN
] = {
54 {0x3042, 0x3042, 0x0000},
55 {0x30A2, 0x30FC, 0x0000},
56 {0x30A2, 0x30FC, 0x30C8, 0x0000},
57 {0x3042, 0x3042, 0x3068, 0x0000} /* 6 */
60 const static UCollationResult results
[] = {
62 UCOL_EQUAL
, /*UCOL_LESS*/ /* Katakanas and Hiraganas are equal on tertiary level(ICU 2.0)*/
64 UCOL_GREATER
, /*UCOL_LESS*/ /* Prolonged sound mark sorts BEFORE equivalent vowel (ICU 2.0)*/
66 UCOL_LESS
, /*UCOL_GREATER*/ /* Prolonged sound mark sorts BEFORE equivalent vowel (ICU 2.0)*//* 6 */
69 const static UChar testBaseCases
[][MAX_TOKEN_LEN
] = {
71 {0x30AB, 0x30AD, 0x0000},
73 {0x30AD, 0x30AD, 0x0000}
76 const static UChar testPlainDakutenHandakutenCases
[][MAX_TOKEN_LEN
] = {
77 {0x30CF, 0x30AB, 0x0000},
78 {0x30D0, 0x30AB, 0x0000},
79 {0x30CF, 0x30AD, 0x0000},
80 {0x30D0, 0x30AD, 0x0000}
83 const static UChar testSmallLargeCases
[][MAX_TOKEN_LEN
] = {
84 {0x30C3, 0x30CF, 0x0000},
85 {0x30C4, 0x30CF, 0x0000},
86 {0x30C3, 0x30D0, 0x0000},
87 {0x30C4, 0x30D0, 0x0000}
90 const static UChar testKatakanaHiraganaCases
[][MAX_TOKEN_LEN
] = {
91 {0x3042, 0x30C3, 0x0000},
92 {0x30A2, 0x30C3, 0x0000},
93 {0x3042, 0x30C4, 0x0000},
94 {0x30A2, 0x30C4, 0x0000}
97 const static UChar testChooonKigooCases
[][MAX_TOKEN_LEN
] = {
98 /*0*/ {0x30AB, 0x30FC, 0x3042, 0x0000},
99 /*1*/ {0x30AB, 0x30FC, 0x30A2, 0x0000},
100 /*2*/ {0x30AB, 0x30A4, 0x3042, 0x0000},
101 /*3*/ {0x30AB, 0x30A4, 0x30A2, 0x0000},
102 /*6*/ {0x30AD, 0x30FC, 0x3042, 0x0000}, /* Prolonged sound mark sorts BEFORE equivalent vowel (ICU 2.0)*/
103 /*7*/ {0x30AD, 0x30FC, 0x30A2, 0x0000}, /* Prolonged sound mark sorts BEFORE equivalent vowel (ICU 2.0)*/
104 /*4*/ {0x30AD, 0x30A4, 0x3042, 0x0000},
105 /*5*/ {0x30AD, 0x30A4, 0x30A2, 0x0000},
108 void addKannaCollTest(TestNode
** root
)
110 addTest(root
, &TestTertiary
, "tscoll/cjacoll/TestTertiary");
111 addTest(root
, &TestBase
, "tscoll/cjacoll/TestBase");
112 addTest(root
, &TestPlainDakutenHandakuten
, "tscoll/cjacoll/TestPlainDakutenHandakuten");
113 addTest(root
, &TestSmallLarge
, "tscoll/cjacoll/TestSmallLarge");
114 addTest(root
, &TestKatakanaHiragana
, "tscoll/cjacoll/TestKatakanaHiragana");
115 addTest(root
, &TestChooonKigoo
, "tscoll/cjacoll/TestChooonKigoo");
118 static void TestTertiary( )
121 UErrorCode status
= U_ZERO_ERROR
;
122 myCollation
= ucol_open("ja_JP", &status
);
123 if(U_FAILURE(status
)){
124 log_err_status(status
, "ERROR: in creation of rule based collator: %s\n", myErrorName(status
));
127 log_verbose("Testing Kanna(Japan) Collation with Tertiary strength\n");
128 ucol_setStrength(myCollation
, UCOL_TERTIARY
);
129 ucol_setAttribute(myCollation
, UCOL_CASE_LEVEL
, UCOL_ON
, &status
);
130 for (i
= 0; i
< 6 ; i
++)
132 doTest(myCollation
, testSourceCases
[i
], testTargetCases
[i
], results
[i
]);
134 ucol_close(myCollation
);
137 /* Testing base letters */
138 static void TestBase()
141 UErrorCode status
= U_ZERO_ERROR
;
142 myCollation
= ucol_open("ja_JP", &status
);
143 if (U_FAILURE(status
))
145 log_err_status(status
, "ERROR: in creation of rule based collator: %s\n",
146 myErrorName(status
));
150 log_verbose("Testing Japanese Base Characters Collation\n");
151 ucol_setStrength(myCollation
, UCOL_PRIMARY
);
152 for (i
= 0; i
< 3 ; i
++)
153 doTest(myCollation
, testBaseCases
[i
], testBaseCases
[i
+ 1], UCOL_LESS
);
155 ucol_close(myCollation
);
158 /* Testing plain, Daku-ten, Handaku-ten letters */
159 static void TestPlainDakutenHandakuten(void)
162 UErrorCode status
= U_ZERO_ERROR
;
163 myCollation
= ucol_open("ja_JP", &status
);
164 if (U_FAILURE(status
))
166 log_err_status(status
, "ERROR: in creation of rule based collator: %s\n",
167 myErrorName(status
));
171 log_verbose("Testing plain, Daku-ten, Handaku-ten letters Japanese Characters Collation\n");
172 ucol_setStrength(myCollation
, UCOL_SECONDARY
);
173 for (i
= 0; i
< 3 ; i
++)
174 doTest(myCollation
, testPlainDakutenHandakutenCases
[i
],
175 testPlainDakutenHandakutenCases
[i
+ 1], UCOL_LESS
);
177 ucol_close(myCollation
);
181 * Test Small, Large letters
183 static void TestSmallLarge(void)
186 UErrorCode status
= U_ZERO_ERROR
;
187 myCollation
= ucol_open("ja_JP", &status
);
188 if (U_FAILURE(status
))
190 log_err_status(status
, "ERROR: in creation of rule based collator: %s\n",
191 myErrorName(status
));
195 log_verbose("Testing Japanese Small and Large Characters Collation\n");
196 ucol_setStrength(myCollation
, UCOL_TERTIARY
);
197 ucol_setAttribute(myCollation
, UCOL_CASE_LEVEL
, UCOL_ON
, &status
);
198 for (i
= 0; i
< 3 ; i
++)
199 doTest(myCollation
, testSmallLargeCases
[i
], testSmallLargeCases
[i
+ 1],
202 ucol_close(myCollation
);
206 * Test Katakana, Hiragana letters
208 static void TestKatakanaHiragana(void)
211 UErrorCode status
= U_ZERO_ERROR
;
212 myCollation
= ucol_open("ja_JP", &status
);
213 if (U_FAILURE(status
))
215 log_err_status(status
, "ERROR: in creation of rule based collator: %s\n",
216 myErrorName(status
));
220 log_verbose("Testing Japanese Katakana, Hiragana Characters Collation\n");
221 ucol_setStrength(myCollation
, UCOL_QUATERNARY
);
222 ucol_setAttribute(myCollation
, UCOL_CASE_LEVEL
, UCOL_ON
, &status
);
223 for (i
= 0; i
< 3 ; i
++) {
224 doTest(myCollation
, testKatakanaHiraganaCases
[i
],
225 testKatakanaHiraganaCases
[i
+ 1], UCOL_LESS
);
228 ucol_close(myCollation
);
234 static void TestChooonKigoo(void)
237 UErrorCode status
= U_ZERO_ERROR
;
238 myCollation
= ucol_open("ja_JP", &status
);
239 if (U_FAILURE(status
))
241 log_err_status(status
, "ERROR: in creation of rule based collator: %s\n",
242 myErrorName(status
));
246 log_verbose("Testing Japanese Choo-on Kigoo Characters Collation\n");
247 ucol_setAttribute(myCollation
, UCOL_STRENGTH
, UCOL_QUATERNARY
, &status
);
248 ucol_setAttribute(myCollation
, UCOL_CASE_LEVEL
, UCOL_ON
, &status
);
249 for (i
= 0; i
< 7 ; i
++) {
250 doTest(myCollation
, testChooonKigooCases
[i
], testChooonKigooCases
[i
+ 1],
254 ucol_close(myCollation
);
257 #endif /* #if !UCONFIG_NO_COLLATION */