1 /********************************************************************
3 * Copyright (c) 1997-2001, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ********************************************************************/
6 /********************************************************************************
10 * Modification History:
12 * Madhu Katragadda Ported for C API
13 * synwee Added TestBase, TestPlainDakutenHandakuten,
14 * TestSmallLarge, TestKatakanaHiragana,
16 *********************************************************************************/
18 * CollationKannaTest is a third level test class. This tests the locale
19 * specific primary, secondary and tertiary rules. For example, the ignorable
20 * character '-' in string "black-bird". The en_US locale uses the default
21 * collation rules as its sorting sequence.
26 #include "unicode/utypes.h"
28 #if !UCONFIG_NO_COLLATION
30 #include "unicode/ucol.h"
31 #include "unicode/uloc.h"
36 #include "unicode/ustring.h"
39 static UCollator
*myCollation
;
40 const static UChar testSourceCases
[][MAX_TOKEN_LEN
] = {
44 {0x3042, 0x3042, 0x0000},
45 {0x30A2, 0x30FC, 0x0000},
46 {0x30A2, 0x30FC, 0x30C8, 0x0000} /* 6 */
49 const static UChar testTargetCases
[][MAX_TOKEN_LEN
] = {
52 {0x3042, 0x3042, 0x0000},
53 {0x30A2, 0x30FC, 0x0000},
54 {0x30A2, 0x30FC, 0x30C8, 0x0000},
55 {0x3042, 0x3042, 0x3068, 0x0000} /* 6 */
58 const static UCollationResult results
[] = {
60 UCOL_EQUAL
, /*UCOL_LESS*/ /* Katakanas and Hiraganas are equal on tertiary level(ICU 2.0)*/
62 UCOL_GREATER
, /*UCOL_LESS*/ /* Prolonged sound mark sorts BEFORE equivalent vowel (ICU 2.0)*/
64 UCOL_LESS
, /*UCOL_GREATER*/ /* Prolonged sound mark sorts BEFORE equivalent vowel (ICU 2.0)*//* 6 */
67 const static UChar testBaseCases
[][MAX_TOKEN_LEN
] = {
69 {0x30AB, 0x30AD, 0x0000},
71 {0x30AD, 0x30AD, 0x0000}
74 const static UChar testPlainDakutenHandakutenCases
[][MAX_TOKEN_LEN
] = {
75 {0x30CF, 0x30AB, 0x0000},
76 {0x30D0, 0x30AB, 0x0000},
77 {0x30CF, 0x30AD, 0x0000},
78 {0x30D0, 0x30AD, 0x0000}
81 const static UChar testSmallLargeCases
[][MAX_TOKEN_LEN
] = {
82 {0x30C3, 0x30CF, 0x0000},
83 {0x30C4, 0x30CF, 0x0000},
84 {0x30C3, 0x30D0, 0x0000},
85 {0x30C4, 0x30D0, 0x0000}
88 const static UChar testKatakanaHiraganaCases
[][MAX_TOKEN_LEN
] = {
89 {0x3042, 0x30C3, 0x0000},
90 {0x30A2, 0x30C3, 0x0000},
91 {0x3042, 0x30C4, 0x0000},
92 {0x30A2, 0x30C4, 0x0000}
95 const static UChar testChooonKigooCases
[][MAX_TOKEN_LEN
] = {
96 /*0*/ {0x30AB, 0x30FC, 0x3042, 0x0000},
97 /*1*/ {0x30AB, 0x30FC, 0x30A2, 0x0000},
98 /*2*/ {0x30AB, 0x30A4, 0x3042, 0x0000},
99 /*3*/ {0x30AB, 0x30A4, 0x30A2, 0x0000},
100 /*6*/ {0x30AD, 0x30FC, 0x3042, 0x0000}, /* Prolonged sound mark sorts BEFORE equivalent vowel (ICU 2.0)*/
101 /*7*/ {0x30AD, 0x30FC, 0x30A2, 0x0000}, /* Prolonged sound mark sorts BEFORE equivalent vowel (ICU 2.0)*/
102 /*4*/ {0x30AD, 0x30A4, 0x3042, 0x0000},
103 /*5*/ {0x30AD, 0x30A4, 0x30A2, 0x0000},
106 void addKannaCollTest(TestNode
** root
)
108 addTest(root
, &TestTertiary
, "tscoll/cjacoll/TestTertiary");
109 addTest(root
, &TestBase
, "tscoll/cjacoll/TestBase");
110 addTest(root
, &TestPlainDakutenHandakuten
, "tscoll/cjacoll/TestPlainDakutenHandakuten");
111 addTest(root
, &TestSmallLarge
, "tscoll/cjacoll/TestSmallLarge");
112 addTest(root
, &TestKatakanaHiragana
, "tscoll/cjacoll/TestKatakanaHiragana");
113 addTest(root
, &TestChooonKigoo
, "tscoll/cjacoll/TestChooonKigoo");
116 static void TestTertiary( )
119 UErrorCode status
= U_ZERO_ERROR
;
120 myCollation
= ucol_open("ja_JP", &status
);
121 if(U_FAILURE(status
)){
122 log_err("ERROR: in creation of rule based collator: %s\n", myErrorName(status
));
125 log_verbose("Testing Kanna(Japan) Collation with Tertiary strength\n");
126 ucol_setStrength(myCollation
, UCOL_TERTIARY
);
127 ucol_setAttribute(myCollation
, UCOL_CASE_LEVEL
, UCOL_ON
, &status
);
128 for (i
= 0; i
< 6 ; i
++)
130 doTest(myCollation
, testSourceCases
[i
], testTargetCases
[i
], results
[i
]);
132 ucol_close(myCollation
);
135 /* Testing base letters */
136 static void TestBase()
139 UErrorCode status
= U_ZERO_ERROR
;
140 myCollation
= ucol_open("ja_JP", &status
);
141 if (U_FAILURE(status
))
143 log_err("ERROR: in creation of rule based collator: %s\n",
144 myErrorName(status
));
148 log_verbose("Testing Japanese Base Characters Collation\n");
149 ucol_setStrength(myCollation
, UCOL_PRIMARY
);
150 for (i
= 0; i
< 3 ; i
++)
151 doTest(myCollation
, testBaseCases
[i
], testBaseCases
[i
+ 1], UCOL_LESS
);
153 ucol_close(myCollation
);
156 /* Testing plain, Daku-ten, Handaku-ten letters */
157 static void TestPlainDakutenHandakuten(void)
160 UErrorCode status
= U_ZERO_ERROR
;
161 myCollation
= ucol_open("ja_JP", &status
);
162 if (U_FAILURE(status
))
164 log_err("ERROR: in creation of rule based collator: %s\n",
165 myErrorName(status
));
169 log_verbose("Testing plain, Daku-ten, Handaku-ten letters Japanese Characters Collation\n");
170 ucol_setStrength(myCollation
, UCOL_SECONDARY
);
171 for (i
= 0; i
< 3 ; i
++)
172 doTest(myCollation
, testPlainDakutenHandakutenCases
[i
],
173 testPlainDakutenHandakutenCases
[i
+ 1], UCOL_LESS
);
175 ucol_close(myCollation
);
179 * Test Small, Large letters
181 static void TestSmallLarge(void)
184 UErrorCode status
= U_ZERO_ERROR
;
185 myCollation
= ucol_open("ja_JP", &status
);
186 if (U_FAILURE(status
))
188 log_err("ERROR: in creation of rule based collator: %s\n",
189 myErrorName(status
));
193 log_verbose("Testing Japanese Small and Large Characters Collation\n");
194 ucol_setStrength(myCollation
, UCOL_TERTIARY
);
195 ucol_setAttribute(myCollation
, UCOL_CASE_LEVEL
, UCOL_ON
, &status
);
196 for (i
= 0; i
< 3 ; i
++)
197 doTest(myCollation
, testSmallLargeCases
[i
], testSmallLargeCases
[i
+ 1],
200 ucol_close(myCollation
);
204 * Test Katakana, Hiragana letters
206 static void TestKatakanaHiragana(void)
209 UErrorCode status
= U_ZERO_ERROR
;
210 myCollation
= ucol_open("ja_JP", &status
);
211 if (U_FAILURE(status
))
213 log_err("ERROR: in creation of rule based collator: %s\n",
214 myErrorName(status
));
218 log_verbose("Testing Japanese Katakana, Hiragana Characters Collation\n");
219 ucol_setStrength(myCollation
, UCOL_QUATERNARY
);
220 ucol_setAttribute(myCollation
, UCOL_CASE_LEVEL
, UCOL_ON
, &status
);
221 for (i
= 0; i
< 3 ; i
++) {
222 doTest(myCollation
, testKatakanaHiraganaCases
[i
],
223 testKatakanaHiraganaCases
[i
+ 1], UCOL_LESS
);
226 ucol_close(myCollation
);
232 static void TestChooonKigoo(void)
235 UErrorCode status
= U_ZERO_ERROR
;
236 myCollation
= ucol_open("ja_JP", &status
);
237 if (U_FAILURE(status
))
239 log_err("ERROR: in creation of rule based collator: %s\n",
240 myErrorName(status
));
244 log_verbose("Testing Japanese Choo-on Kigoo Characters Collation\n");
245 ucol_setAttribute(myCollation
, UCOL_STRENGTH
, UCOL_QUATERNARY
, &status
);
246 ucol_setAttribute(myCollation
, UCOL_CASE_LEVEL
, UCOL_ON
, &status
);
247 for (i
= 0; i
< 7 ; i
++) {
248 doTest(myCollation
, testChooonKigooCases
[i
], testChooonKigooCases
[i
+ 1],
252 ucol_close(myCollation
);
255 #endif /* #if !UCONFIG_NO_COLLATION */