]>
Commit | Line | Data |
---|---|---|
b75a7d8f A |
1 | /******************************************************************** |
2 | * COPYRIGHT: | |
3 | * Copyright (c) 1997-2003, International Business Machines Corporation and | |
4 | * others. All Rights Reserved. | |
5 | ******************************************************************** | |
6 | ************************************************************************ | |
7 | * Date Name Description | |
8 | * 02/28/2001 aliu Creation | |
9 | * 03/01/2001 George port to HP/UX | |
10 | ************************************************************************/ | |
11 | ||
12 | #include "unicode/utypes.h" | |
13 | ||
14 | #if !UCONFIG_NO_TRANSLITERATION | |
15 | ||
16 | #include "jamotest.h" | |
17 | #include "unicode/utypes.h" | |
18 | #include "unicode/translit.h" | |
19 | #include "rbt.h" | |
20 | #include "cpdtrans.h" | |
21 | ||
22 | // SEP is the disambiguation separator used by Latin-Jamo and Jamo-Latin | |
23 | #define SEP "'" | |
24 | ||
25 | JamoTest::JamoTest() | |
26 | { | |
27 | UErrorCode status = U_ZERO_ERROR; | |
28 | NAME_JAMO = new RuleBasedTransliterator("Name-Jamo", | |
29 | JAMO_NAMES_RULES, | |
30 | UTRANS_FORWARD, status); | |
31 | ||
32 | if (U_FAILURE(status)) { | |
33 | delete NAME_JAMO; | |
34 | NAME_JAMO = NULL; | |
35 | } | |
36 | status = U_ZERO_ERROR; | |
37 | JAMO_NAME = new RuleBasedTransliterator("Jamo-Name", | |
38 | JAMO_NAMES_RULES, | |
39 | UTRANS_REVERSE, status); | |
40 | if (U_FAILURE(status)) { | |
41 | delete JAMO_NAME; | |
42 | JAMO_NAME = NULL; | |
43 | } | |
44 | } | |
45 | ||
46 | JamoTest::~JamoTest() | |
47 | { | |
48 | delete NAME_JAMO; | |
49 | delete JAMO_NAME; | |
50 | } | |
51 | ||
52 | void | |
53 | JamoTest::runIndexedTest(int32_t index, UBool exec, | |
54 | const char* &name, char* /*par*/) { | |
55 | switch (index) { | |
56 | TESTCASE(0,TestJamo); | |
57 | TESTCASE(1,TestRealText); | |
58 | TESTCASE(2,TestPiecemeal); | |
59 | default: name = ""; break; | |
60 | } | |
61 | } | |
62 | ||
63 | void | |
64 | JamoTest::TestJamo() { | |
65 | UParseError parseError; | |
66 | UErrorCode status = U_ZERO_ERROR; | |
67 | Transliterator* latinJamo = Transliterator::createInstance("Latin-Jamo", UTRANS_FORWARD, parseError, status); | |
68 | ||
69 | if (latinJamo == 0 || U_FAILURE(status)) { | |
70 | errln("FAIL: createInstance() returned 0"); | |
71 | return; | |
72 | } | |
73 | ||
74 | Transliterator* jamoLatin = latinJamo->createInverse(status); | |
75 | ||
76 | if (jamoLatin == 0) { | |
77 | delete latinJamo; | |
78 | errln("FAIL: createInverse() returned 0"); | |
79 | return; | |
80 | } | |
81 | ||
82 | static const char* CASE[] = { | |
83 | // Column 1 is the latin text L1 to be fed to Latin-Jamo | |
84 | // to yield output J. | |
85 | ||
86 | // Column 2 is expected value of J. J is fed to | |
87 | // Jamo-Latin to yield output L2. | |
88 | ||
89 | // Column 3 is expected value of L2. If the expected | |
90 | // value of L2 is L1, then L2 is NULL. | |
91 | "bab", "(Bi)(A)(Bf)", NULL, | |
92 | "babb", "(Bi)(A)(Bf)(Bi)(EU)", "bab" SEP "beu", | |
93 | "babbba", "(Bi)(A)(Bf)(BB)(A)", NULL, | |
94 | "bagg", "(Bi)(A)(GGf)", NULL, | |
95 | "baggga", "(Bi)(A)(GGf)(Gi)(A)", NULL, | |
96 | "bag" SEP "gga", "(Bi)(A)(Gf)(GGi)(A)", NULL, | |
97 | "kabsa", "(Ki)(A)(Bf)(Si)(A)", NULL, | |
98 | "kabska", "(Ki)(A)(BS)(Ki)(A)", NULL, | |
99 | "gabsbka", "(Gi)(A)(BS)(Bi)(EU)(Ki)(A)", "gabsbeuka", // not (Kf) | |
100 | "gga", "(GGi)(A)", NULL, | |
101 | "bsa", "(Bi)(EU)(Si)(A)", "beusa", | |
102 | "agg", "(IEUNG)(A)(GGf)", NULL, | |
103 | "agga", "(IEUNG)(A)(GGi)(A)", NULL, | |
104 | "la", "(R)(A)", "ra", | |
105 | "bs", "(Bi)(EU)(Sf)", "beus", | |
106 | "kalgga", "(Ki)(A)(L)(GGi)(A)", NULL, | |
107 | ||
108 | // 'r' in a final position is treated like 'l' | |
109 | "karka", "(Ki)(A)(L)(Ki)(A)", "kalka", | |
110 | }; | |
111 | ||
112 | enum { CASE_length = sizeof(CASE) / sizeof(CASE[0]) }; | |
113 | ||
114 | int32_t i; | |
115 | for (i=0; i<CASE_length; i+=3) { | |
116 | UnicodeString jamo = nameToJamo(CASE[i+1]); | |
117 | if (CASE[i+2] == NULL) { | |
118 | expect(*latinJamo, CASE[i], jamo, *jamoLatin); | |
119 | } else { | |
120 | // Handle case where round-trip is expected to fail | |
121 | expect(*latinJamo, CASE[i], jamo); | |
122 | expect(*jamoLatin, jamo, CASE[i+2]); | |
123 | } | |
124 | } | |
125 | ||
126 | delete latinJamo; | |
127 | delete jamoLatin; | |
128 | } | |
129 | ||
130 | /** | |
131 | * Test various step-at-a-time transformation of hangul to jamo to | |
132 | * latin and back. | |
133 | */ | |
134 | void JamoTest::TestPiecemeal(void) { | |
135 | UnicodeString hangul; hangul.append((UChar)0xBC0F); | |
136 | UnicodeString jamo = nameToJamo("(Mi)(I)(Cf)"); | |
137 | UnicodeString latin("mic"); | |
138 | ||
139 | Transliterator *t = NULL; | |
140 | UErrorCode status = U_ZERO_ERROR; | |
141 | ||
142 | t = Transliterator::createInstance("NFD", UTRANS_FORWARD, status); // was Hangul-Jamo | |
143 | if (U_FAILURE(status) || t == 0) { | |
144 | errln("FAIL: createInstance failed"); | |
145 | return; | |
146 | } | |
147 | expect(*t, hangul, jamo); | |
148 | delete t; | |
149 | ||
150 | t = Transliterator::createInstance("NFC", UTRANS_FORWARD, status); // was Jamo-Hangul | |
151 | if (U_FAILURE(status) || t == 0) { | |
152 | errln("FAIL: createInstance failed"); | |
153 | return; | |
154 | } | |
155 | expect(*t, jamo, hangul); | |
156 | delete t; | |
157 | ||
158 | t = Transliterator::createInstance("Latin-Jamo", UTRANS_FORWARD, status); | |
159 | if (U_FAILURE(status) || t == 0) { | |
160 | errln("FAIL: createInstance failed"); | |
161 | return; | |
162 | } | |
163 | expect(*t, latin, jamo); | |
164 | delete t; | |
165 | ||
166 | t = Transliterator::createInstance("Jamo-Latin", UTRANS_FORWARD, status); | |
167 | if (U_FAILURE(status) || t == 0) { | |
168 | errln("FAIL: createInstance failed"); | |
169 | return; | |
170 | } | |
171 | expect(*t, jamo, latin); | |
172 | delete t; | |
173 | ||
174 | t = Transliterator::createInstance("Hangul-Latin", UTRANS_FORWARD, status); | |
175 | if (U_FAILURE(status) || t == 0) { | |
176 | errln("FAIL: createInstance failed"); | |
177 | return; | |
178 | } | |
179 | expect(*t, hangul, latin); | |
180 | delete t; | |
181 | ||
182 | t = Transliterator::createInstance("Latin-Hangul", UTRANS_FORWARD, status); | |
183 | if (U_FAILURE(status) || t == 0) { | |
184 | errln("FAIL: createInstance failed"); | |
185 | return; | |
186 | } | |
187 | expect(*t, latin, hangul); | |
188 | delete t; | |
189 | ||
190 | t = Transliterator::createInstance("Hangul-Latin; Latin-Jamo", UTRANS_FORWARD, status); | |
191 | if (U_FAILURE(status) || t == 0) { | |
192 | errln("FAIL: createInstance failed"); | |
193 | return; | |
194 | } | |
195 | expect(*t, hangul, jamo); | |
196 | delete t; | |
197 | ||
198 | t = Transliterator::createInstance("Jamo-Latin; Latin-Hangul", UTRANS_FORWARD, status); | |
199 | if (U_FAILURE(status) || t == 0) { | |
200 | errln("FAIL: createInstance failed"); | |
201 | return; | |
202 | } | |
203 | expect(*t, jamo, hangul); | |
204 | delete t; | |
205 | ||
206 | t = Transliterator::createInstance("Hangul-Latin; Latin-Hangul", UTRANS_FORWARD, status); | |
207 | if (U_FAILURE(status) || t == 0) { | |
208 | errln("FAIL: createInstance failed"); | |
209 | return; | |
210 | } | |
211 | expect(*t, hangul, hangul); | |
212 | delete t; | |
213 | } | |
214 | ||
215 | void | |
216 | JamoTest::TestRealText() { | |
217 | // Test text taken from the Unicode web site | |
218 | static const char* WHAT_IS_UNICODE[] = { | |
219 | "\\uc720\\ub2c8\\ucf54\\ub4dc\\uc5d0", "\\ub300\\ud574", "?", | |
220 | ||
221 | "\\uc5b4\\ub5a4", "\\ud50c\\ub7ab\\ud3fc,", "\\uc5b4\\ub5a4", | |
222 | "\\ud504\\ub85c\\uadf8\\ub7a8,", "\\uc5b4\\ub5a4", "\\uc5b8\\uc5b4\\uc5d0\\ub3c4", | |
223 | "\\uc0c1\\uad00\\uc5c6\\uc774", "\\uc720\\ub2c8\\ucf54\\ub4dc\\ub294", "\\ubaa8\\ub4e0", | |
224 | "\\ubb38\\uc790\\uc5d0", "\\ub300\\ud574", "\\uace0\\uc720", "\\ubc88\\ud638\\ub97c", | |
225 | "\\uc81c\\uacf5\\ud569\\ub2c8\\ub2e4.", | |
226 | ||
227 | "\\uae30\\ubcf8\\uc801\\uc73c\\ub85c", "\\ucef4\\ud4e8\\ud130\\ub294", | |
228 | "\\uc22b\\uc790\\ub9cc", "\\ucc98\\ub9ac\\ud569\\ub2c8\\ub2e4.", "\\uae00\\uc790\\ub098", | |
229 | "\\ub2e4\\ub978", "\\ubb38\\uc790\\uc5d0\\ub3c4", "\\uc22b\\uc790\\ub97c", | |
230 | "\\uc9c0\\uc815\\ud558\\uc5ec", | |
231 | "\\uc800\\uc7a5\\ud569\\ub2c8\\ub2e4.", "\\uc720\\ub2c8\\ucf54\\ub4dc\\uac00", | |
232 | "\\uac1c\\ubc1c\\ub418\\uae30", "\\uc804\\uc5d0\\ub294", "\\uc774\\ub7ec\\ud55c", | |
233 | "\\uc22b\\uc790\\ub97c", "\\uc9c0\\uc815\\ud558\\uae30", "\\uc704\\ud574", "\\uc218\\ubc31", | |
234 | "\\uac00\\uc9c0\\uc758", "\\ub2e4\\ub978", "\\uae30\\ud638\\ud654", | |
235 | "\\uc2dc\\uc2a4\\ud15c\\uc744", | |
236 | "\\uc0ac\\uc6a9\\ud588\\uc2b5\\ub2c8\\ub2e4.", "\\ub2e8\\uc77c", "\\uae30\\ud638\\ud654", | |
237 | "\\ubc29\\ubc95\\uc73c\\ub85c\\ub294", "\\ubaa8\\ub4e0", "\\ubb38\\uc790\\ub97c", | |
238 | "\\ud3ec\\ud568\\ud560", "\\uc218", "\\uc5c6\\uc5c8\\uc2b5\\ub2c8\\ub2e4.", "\\uc608\\ub97c", | |
239 | "\\ub4e4\\uc5b4", "\\uc720\\ub7fd", "\\uc5f0\\ud569\\uc5d0\\uc11c\\ub9cc", | |
240 | "\\ubcf4\\ub354\\ub77c\\ub3c4", "\\ubaa8\\ub4e0", "\\uac01", "\\ub098\\ub77c\\ubcc4", | |
241 | "\\uc5b8\\uc5b4\\ub97c", "\\ucc98\\ub9ac\\ud558\\ub824\\uba74", "\\uc5ec\\ub7ec", | |
242 | "\\uac1c\\uc758", "\\ub2e4\\ub978", "\\uae30\\ud638\\ud654", "\\ubc29\\ubc95\\uc774", | |
243 | "\\ud544\\uc694\\ud569\\ub2c8\\ub2e4.", "\\uc601\\uc5b4\\uc640", "\\uac19\\uc740", | |
244 | "\\ub2e8\\uc77c", "\\uc5b8\\uc5b4\\uc758", "\\uacbd\\uc6b0\\ub3c4", | |
245 | "\\uacf5\\ud1b5\\uc801\\uc73c\\ub85c", "\\uc0ac\\uc6a9\\ub418\\ub294", "\\ubaa8\\ub4e0", | |
246 | "\\uae00\\uc790,", "\\ubb38\\uc7a5", "\\ubd80\\ud638", "\\ubc0f", | |
247 | "\\ud14c\\ud06c\\ub2c8\\uceec", "\\uae30\\ud638\\uc5d0", "\\ub9de\\ub294", "\\ub2e8\\uc77c", | |
248 | "\\uae30\\ud638\\ud654", "\\ubc29\\ubc95\\uc744", "\\uac16\\uace0", "\\uc788\\uc9c0", | |
249 | "\\ubabb\\ud558\\uc600\\uc2b5\\ub2c8\\ub2e4.", | |
250 | ||
251 | "\\uc774\\ub7ec\\ud55c", "\\uae30\\ud638\\ud654", "\\uc2dc\\uc2a4\\ud15c\\uc740", | |
252 | "\\ub610\\ud55c", "\\ub2e4\\ub978", "\\uae30\\ud638\\ud654", "\\uc2dc\\uc2a4\\ud15c\\uacfc", | |
253 | "\\ucda9\\ub3cc\\ud569\\ub2c8\\ub2e4.", "\\uc989", "\\ub450", "\\uac00\\uc9c0", | |
254 | "\\uae30\\ud638\\ud654", "\\ubc29\\ubc95\\uc774", "\\ub450", "\\uac1c\\uc758", "\\ub2e4\\ub978", | |
255 | "\\ubb38\\uc790\\uc5d0", "\\ub300\\ud574", "\\uac19\\uc740", "\\ubc88\\ud638\\ub97c", | |
256 | "\\uc0ac\\uc6a9\\ud558\\uac70\\ub098", "\\uac19\\uc740", "\\ubb38\\uc790\\uc5d0", | |
257 | "\\ub300\\ud574", "\\ub2e4\\ub978", "\\ubc88\\ud638\\ub97c", "\\uc0ac\\uc6a9\\ud560", "\\uc218", | |
258 | "\\uc788\\uc2b5\\ub2c8\\ub2e4.", "\\uc8fc\\uc5b4\\uc9c4", "\\ubaa8\\ub4e0", | |
259 | "\\ucef4\\ud4e8\\ud130(\\ud2b9\\ud788", "\\uc11c\\ubc84)\\ub294", "\\uc11c\\ub85c", | |
260 | "\\ub2e4\\ub978", "\\uc5ec\\ub7ec", "\\uac00\\uc9c0", "\\uae30\\ud638\\ud654", | |
261 | "\\ubc29\\ubc95\\uc744", "\\uc9c0\\uc6d0\\ud574\\uc57c", | |
262 | "\\ud569\\ub2c8\\ub2e4.", "\\uadf8\\ub7ec\\ub098,", "\\ub370\\uc774\\ud130\\ub97c", | |
263 | "\\uc11c\\ub85c", "\\ub2e4\\ub978", "\\uae30\\ud638\\ud654", "\\ubc29\\ubc95\\uc774\\ub098", | |
264 | "\\ud50c\\ub7ab\\ud3fc", "\\uac04\\uc5d0", "\\uc804\\ub2ec\\ud560", "\\ub54c\\ub9c8\\ub2e4", | |
265 | "\\uadf8", "\\ub370\\uc774\\ud130\\ub294", "\\ud56d\\uc0c1", "\\uc190\\uc0c1\\uc758", | |
266 | "\\uc704\\ud5d8\\uc744", "\\uacaa\\uac8c", "\\ub429\\ub2c8\\ub2e4.", | |
267 | ||
268 | "\\uc720\\ub2c8\\ucf54\\ub4dc\\ub85c", "\\ubaa8\\ub4e0", "\\uac83\\uc744", | |
269 | "\\ud574\\uacb0\\ud560", "\\uc218", "\\uc788\\uc2b5\\ub2c8\\ub2e4!", | |
270 | "\\uc720\\ub2c8\\ucf54\\ub4dc\\ub294", "\\uc0ac\\uc6a9", "\\uc911\\uc778", | |
271 | "\\ud50c\\ub7ab\\ud3fc,", "\\ud504\\ub85c\\uadf8\\ub7a8,", "\\uc5b8\\uc5b4\\uc5d0", | |
272 | "\\uad00\\uacc4\\uc5c6\\uc774", "\\ubb38\\uc790\\ub9c8\\ub2e4", "\\uace0\\uc720\\ud55c", | |
273 | "\\uc22b\\uc790\\ub97c", | |
274 | "\\uc81c\\uacf5\\ud569\\ub2c8\\ub2e4.", "\\uc720\\ub2c8\\ucf54\\ub4dc", | |
275 | "\\ud45c\\uc900\\uc740", // "Apple, HP, IBM, JustSystem, Microsoft, Oracle, SAP, " | |
276 | // "Sun, Sybase, Unisys " | |
277 | "\\ubc0f", "\\uae30\\ud0c0", "\\uc5ec\\ub7ec", | |
278 | "\\ud68c\\uc0ac\\uc640", "\\uac19\\uc740", "\\uc5c5\\uacc4", | |
279 | "\\uc120\\ub450\\uc8fc\\uc790\\uc5d0", "\\uc758\\ud574", | |
280 | "\\ucc44\\ud0dd\\ub418\\uc5c8\\uc2b5\\ub2c8\\ub2e4.", "\\uc720\\ub2c8\\ucf54\\ub4dc\\ub294", | |
281 | // "XML, Java, ECMAScript(JavaScript), LDAP, CORBA 3.0, WML " | |
282 | "\\ub4f1\\uacfc", | |
283 | "\\uac19\\uc774", "\\ud604\\uc7ac", "\\ub110\\ub9ac", "\\uc0ac\\uc6a9\\ub418\\ub294", | |
284 | "\\ud45c\\uc900\\uc5d0\\uc11c", "\\ud544\\uc694\\ud558\\uba70", "\\uc774\\ub294", // "ISO/IEC", | |
285 | "10646\\uc744", "\\uad6c\\ud604\\ud558\\ub294", "\\uacf5\\uc2dd\\uc801\\uc778", | |
286 | "\\ubc29\\ubc95\\uc785\\ub2c8\\ub2e4.", "\\uc774\\ub294", "\\ub9ce\\uc740", "\\uc6b4\\uc601", | |
287 | "\\uccb4\\uc81c,", "\\uc694\\uc998", "\\uc0ac\\uc6a9\\ub418\\ub294", "\\ubaa8\\ub4e0", | |
288 | "\\ube0c\\ub77c\\uc6b0\\uc800", "\\ubc0f", "\\uae30\\ud0c0", "\\ub9ce\\uc740", | |
289 | "\\uc81c\\ud488\\uc5d0\\uc11c", | |
290 | "\\uc9c0\\uc6d0\\ub429\\ub2c8\\ub2e4.", "\\uc720\\ub2c8\\ucf54\\ub4dc", | |
291 | "\\ud45c\\uc900\\uc758", "\\ubd80\\uc0c1\\uacfc", "\\uc774\\ub97c", | |
292 | "\\uc9c0\\uc6d0\\ud558\\ub294", "\\ub3c4\\uad6c\\uc758", "\\uac00\\uc6a9\\uc131\\uc740", | |
293 | "\\ucd5c\\uadfc", "\\uc804", "\\uc138\\uacc4\\uc5d0", "\\ubd88\\uace0", "\\uc788\\ub294", | |
294 | "\\uae30\\uc220", "\\uacbd\\ud5a5\\uc5d0\\uc11c", "\\uac00\\uc7a5", "\\uc911\\uc694\\ud55c", | |
295 | "\\ubd80\\ubd84\\uc744", "\\ucc28\\uc9c0\\ud558\\uace0", "\\uc788\\uc2b5\\ub2c8\\ub2e4.", | |
296 | ||
297 | "\\uc720\\ub2c8\\ucf54\\ub4dc\\ub97c", | |
298 | "\\ud074\\ub77c\\uc774\\uc5b8\\ud2b8-\\uc11c\\ubc84", "\\ub610\\ub294", | |
299 | "\\ub2e4\\uc911-\\uc5f0\\uacb0", "\\uc751\\uc6a9", "\\ud504\\ub85c\\uadf8\\ub7a8\\uacfc", | |
300 | "\\uc6f9", "\\uc0ac\\uc774\\ud2b8\\uc5d0", "\\ud1b5\\ud569\\ud558\\uba74", | |
301 | "\\ub808\\uac70\\uc2dc", "\\ubb38\\uc790", "\\uc138\\ud2b8", "\\uc0ac\\uc6a9\\uc5d0", | |
302 | "\\uc788\\uc5b4\\uc11c", "\\uc0c1\\ub2f9\\ud55c", "\\ube44\\uc6a9", "\\uc808\\uac10", | |
303 | "\\ud6a8\\uacfc\\uac00", | |
304 | "\\ub098\\ud0c0\\ub0a9\\ub2c8\\ub2e4.", "\\uc720\\ub2c8\\ucf54\\ub4dc\\ub97c", | |
305 | "\\ud1b5\\ud574", "\\ub9ac\\uc5d4\\uc9c0\\ub2c8\\uc5b4\\ub9c1", "\\uc5c6\\uc774", | |
306 | "\\ub2e4\\uc911", "\\ud50c\\ub7ab\\ud3fc,", "\\uc5b8\\uc5b4", "\\ubc0f", "\\uad6d\\uac00", | |
307 | "\\uac04\\uc5d0", "\\ub2e8\\uc77c", "\\uc18c\\ud504\\ud2b8\\uc6e8\\uc5b4", | |
308 | "\\ud50c\\ub7ab\\ud3fc", "\\ub610\\ub294", "\\ub2e8\\uc77c", "\\uc6f9", | |
309 | "\\uc0ac\\uc774\\ud2b8\\ub97c", "\\ubaa9\\ud45c\\ub85c", "\\uc0bc\\uc744", "\\uc218", | |
310 | "\\uc788\\uc2b5\\ub2c8\\ub2e4.", "\\uc774\\ub97c", "\\uc0ac\\uc6a9\\ud558\\uba74", | |
311 | "\\ub370\\uc774\\ud130\\ub97c", "\\uc190\\uc0c1", "\\uc5c6\\uc774", "\\uc5ec\\ub7ec", | |
312 | "\\uc2dc\\uc2a4\\ud15c\\uc744", "\\ud1b5\\ud574", "\\uc804\\uc1a1\\ud560", "\\uc218", | |
313 | "\\uc788\\uc2b5\\ub2c8\\ub2e4.", | |
314 | ||
315 | "\\uc720\\ub2c8\\ucf54\\ub4dc", "\\ucf58\\uc18c\\uc2dc\\uc5c4\\uc5d0", "\\ub300\\ud574", | |
316 | "\\uc720\\ub2c8\\ucf54\\ub4dc", "\\ucf58\\uc18c\\uc2dc\\uc5c4\\uc740", | |
317 | "\\ube44\\uc601\\ub9ac", "\\uc870\\uc9c1\\uc73c\\ub85c\\uc11c", "\\ud604\\ub300", | |
318 | "\\uc18c\\ud504\\ud2b8\\uc6e8\\uc5b4", "\\uc81c\\ud488\\uacfc", | |
319 | "\\ud45c\\uc900\\uc5d0\\uc11c", "\\ud14d\\uc2a4\\ud2b8\\uc758", "\\ud45c\\ud604\\uc744", | |
320 | "\\uc9c0\\uc815\\ud558\\ub294", "\\uc720\\ub2c8\\ucf54\\ub4dc", "\\ud45c\\uc900\\uc758", | |
321 | "\\uc0ac\\uc6a9\\uc744", "\\uac1c\\ubc1c\\ud558\\uace0", "\\ud655\\uc7a5\\ud558\\uba70", | |
322 | "\\uc7a5\\ub824\\ud558\\uae30", "\\uc704\\ud574", | |
323 | "\\uc138\\uc6cc\\uc84c\\uc2b5\\ub2c8\\ub2e4.", "\\ucf58\\uc18c\\uc2dc\\uc5c4", | |
324 | "\\uba64\\ubc84\\uc27d\\uc740", "\\ucef4\\ud4e8\\ud130\\uc640", "\\uc815\\ubcf4", | |
325 | "\\ucc98\\ub9ac", "\\uc0b0\\uc5c5\\uc5d0", "\\uc885\\uc0ac\\ud558\\uace0", "\\uc788\\ub294", | |
326 | "\\uad11\\ubc94\\uc704\\ud55c", "\\ud68c\\uc0ac", "\\ubc0f", "\\uc870\\uc9c1\\uc758", | |
327 | "\\ubc94\\uc704\\ub97c", | |
328 | "\\ub098\\ud0c0\\ub0c5\\ub2c8\\ub2e4.", "\\ucf58\\uc18c\\uc2dc\\uc5c4\\uc758", | |
329 | "\\uc7ac\\uc815\\uc740", "\\uc804\\uc801\\uc73c\\ub85c", "\\ud68c\\ube44\\uc5d0", | |
330 | "\\uc758\\ud574", "\\ucda9\\ub2f9\\ub429\\ub2c8\\ub2e4.", "\\uc720\\ub2c8\\ucf54\\ub4dc", | |
331 | "\\ucee8\\uc18c\\uc2dc\\uc5c4\\uc5d0\\uc11c\\uc758", "\\uba64\\ubc84\\uc27d\\uc740", | |
332 | "\\uc804", "\\uc138\\uacc4", "\\uc5b4\\ub290", "\\uacf3\\uc5d0\\uc11c\\ub098", | |
333 | "\\uc720\\ub2c8\\ucf54\\ub4dc", "\\ud45c\\uc900\\uc744", "\\uc9c0\\uc6d0\\ud558\\uace0", | |
334 | "\\uadf8", "\\ud655\\uc7a5\\uacfc", "\\uad6c\\ud604\\uc744", | |
335 | "\\uc9c0\\uc6d0\\ud558\\uace0\\uc790\\ud558\\ub294", "\\uc870\\uc9c1\\uacfc", | |
336 | "\\uac1c\\uc778\\uc5d0\\uac8c", "\\uac1c\\ubc29\\ub418\\uc5b4", | |
337 | "\\uc788\\uc2b5\\ub2c8\\ub2e4.", | |
338 | ||
339 | "\\ub354", "\\uc790\\uc138\\ud55c", "\\ub0b4\\uc6a9\\uc740", "\\uc6a9\\uc5b4\\uc9d1,", | |
340 | "\\uc608\\uc81c", "\\uc720\\ub2c8\\ucf54\\ub4dc", "\\uc0ac\\uc6a9", "\\uac00\\ub2a5", | |
341 | "\\uc81c\\ud488,", "\\uae30\\uc220", "\\uc815\\ubcf4", "\\ubc0f", "\\uae30\\ud0c0", | |
342 | "\\uc720\\uc6a9\\ud55c", "\\uc815\\ubcf4\\ub97c", | |
343 | "\\ucc38\\uc870\\ud558\\uc2ed\\uc2dc\\uc624." | |
344 | }; | |
345 | ||
346 | enum { WHAT_IS_UNICODE_length = sizeof(WHAT_IS_UNICODE) / sizeof(WHAT_IS_UNICODE[0]) }; | |
347 | ||
348 | UParseError parseError; | |
349 | UErrorCode status = U_ZERO_ERROR; | |
350 | Transliterator* latinJamo = Transliterator::createInstance("Latin-Jamo", UTRANS_FORWARD, parseError, status); | |
351 | Transliterator* jamoHangul = Transliterator::createInstance("NFC(NFD)", UTRANS_FORWARD, parseError, status); | |
352 | if (latinJamo == 0 || jamoHangul == 0 || U_FAILURE(status)) { | |
353 | delete latinJamo; | |
354 | delete jamoHangul; | |
355 | errln("FAIL: createInstance returned NULL"); | |
356 | return; | |
357 | } | |
358 | Transliterator* jamoLatin = latinJamo->createInverse(status); | |
359 | Transliterator* hangulJamo = jamoHangul->createInverse(status); | |
360 | if (jamoLatin == 0 || hangulJamo == 0) { | |
361 | errln("FAIL: createInverse returned NULL"); | |
362 | delete latinJamo; | |
363 | delete jamoLatin; | |
364 | delete jamoHangul; | |
365 | delete hangulJamo; | |
366 | return; | |
367 | } | |
368 | ||
369 | Transliterator* tarray[4] = | |
370 | { hangulJamo, jamoLatin, latinJamo, jamoHangul }; | |
371 | CompoundTransliterator rt(tarray, 4); | |
372 | ||
373 | UnicodeString buf; | |
374 | int32_t total = 0; | |
375 | int32_t errors = 0; | |
376 | int32_t i; | |
377 | for (i=0; i < WHAT_IS_UNICODE_length; ++i) { | |
378 | ++total; | |
379 | UnicodeString hangul = WHAT_IS_UNICODE[i]; | |
380 | hangul = hangul.unescape(); // Parse backslash-u escapes | |
381 | UnicodeString hangulX = hangul; | |
382 | rt.transliterate(hangulX); | |
383 | if (hangul != hangulX) { | |
384 | ++errors; | |
385 | UnicodeString jamo = hangul; hangulJamo->transliterate(jamo); | |
386 | UnicodeString latin = jamo; jamoLatin->transliterate(latin); | |
387 | UnicodeString jamo2 = latin; latinJamo->transliterate(jamo2); | |
388 | UnicodeString hangul2 = jamo2; jamoHangul->transliterate(hangul2); | |
389 | ||
390 | buf.remove(0); | |
391 | buf.append("FAIL: "); | |
392 | if (hangul2 != hangulX) { | |
393 | buf.append((UnicodeString)"(Weird: " + hangulX + " != " + hangul2 + ")"); | |
394 | } | |
395 | // The Hangul-Jamo conversion is not usually the | |
396 | // bug here, so we hide it from display. | |
397 | // Uncomment lines to see the Hangul. | |
398 | buf.append(//hangul + " => " + | |
399 | jamoToName(jamo) + " => " + | |
400 | latin + " => " + jamoToName(jamo2) | |
401 | //+ " => " + hangul2 | |
402 | ); | |
403 | errln(prettify(buf)); | |
404 | } | |
405 | } | |
406 | if (errors != 0) { | |
407 | errln((UnicodeString)"Test word failures: " + errors + " out of " + total); | |
408 | } else { | |
409 | logln((UnicodeString)"All " + total + " test words passed"); | |
410 | } | |
411 | ||
412 | delete latinJamo; | |
413 | delete jamoLatin; | |
414 | delete jamoHangul; | |
415 | delete hangulJamo; | |
416 | } | |
417 | ||
418 | // Override TransliteratorTest | |
419 | void | |
420 | JamoTest::expectAux(const UnicodeString& tag, | |
421 | const UnicodeString& summary, UBool pass, | |
422 | const UnicodeString& expectedResult) { | |
423 | UnicodeString jsum = jamoToName(summary); | |
424 | UnicodeString jexp = jamoToName(expectedResult); | |
425 | TransliteratorTest::expectAux(tag, jsum, pass, jexp); | |
426 | } | |
427 | ||
428 | const char* JamoTest::JAMO_NAMES_RULES = | |
429 | "'(Gi)' <> \\u1100;" | |
430 | "'(GGi)' <> \\u1101;" | |
431 | "'(Ni)' <> \\u1102;" | |
432 | "'(Di)' <> \\u1103;" | |
433 | "'(DD)' <> \\u1104;" | |
434 | "'(R)' <> \\u1105;" | |
435 | "'(Mi)' <> \\u1106;" | |
436 | "'(Bi)' <> \\u1107;" | |
437 | "'(BB)' <> \\u1108;" | |
438 | "'(Si)' <> \\u1109;" | |
439 | "'(SSi)' <> \\u110A;" | |
440 | "'(IEUNG)' <> \\u110B;" | |
441 | "'(Ji)' <> \\u110C;" | |
442 | "'(JJ)' <> \\u110D;" | |
443 | "'(Ci)' <> \\u110E;" | |
444 | "'(Ki)' <> \\u110F;" | |
445 | "'(Ti)' <> \\u1110;" | |
446 | "'(Pi)' <> \\u1111;" | |
447 | "'(Hi)' <> \\u1112;" | |
448 | ||
449 | "'(A)' <> \\u1161;" | |
450 | "'(AE)' <> \\u1162;" | |
451 | "'(YA)' <> \\u1163;" | |
452 | "'(YAE)' <> \\u1164;" | |
453 | "'(EO)' <> \\u1165;" | |
454 | "'(E)' <> \\u1166;" | |
455 | "'(YEO)' <> \\u1167;" | |
456 | "'(YE)' <> \\u1168;" | |
457 | "'(O)' <> \\u1169;" | |
458 | "'(WA)' <> \\u116A;" | |
459 | "'(WAE)' <> \\u116B;" | |
460 | "'(OE)' <> \\u116C;" | |
461 | "'(YO)' <> \\u116D;" | |
462 | "'(U)' <> \\u116E;" | |
463 | "'(WEO)' <> \\u116F;" | |
464 | "'(WE)' <> \\u1170;" | |
465 | "'(WI)' <> \\u1171;" | |
466 | "'(YU)' <> \\u1172;" | |
467 | "'(EU)' <> \\u1173;" | |
468 | "'(YI)' <> \\u1174;" | |
469 | "'(I)' <> \\u1175;" | |
470 | ||
471 | "'(Gf)' <> \\u11A8;" | |
472 | "'(GGf)' <> \\u11A9;" | |
473 | "'(GS)' <> \\u11AA;" | |
474 | "'(Nf)' <> \\u11AB;" | |
475 | "'(NJ)' <> \\u11AC;" | |
476 | "'(NH)' <> \\u11AD;" | |
477 | "'(Df)' <> \\u11AE;" | |
478 | "'(L)' <> \\u11AF;" | |
479 | "'(LG)' <> \\u11B0;" | |
480 | "'(LM)' <> \\u11B1;" | |
481 | "'(LB)' <> \\u11B2;" | |
482 | "'(LS)' <> \\u11B3;" | |
483 | "'(LT)' <> \\u11B4;" | |
484 | "'(LP)' <> \\u11B5;" | |
485 | "'(LH)' <> \\u11B6;" | |
486 | "'(Mf)' <> \\u11B7;" | |
487 | "'(Bf)' <> \\u11B8;" | |
488 | "'(BS)' <> \\u11B9;" | |
489 | "'(Sf)' <> \\u11BA;" | |
490 | "'(SSf)' <> \\u11BB;" | |
491 | "'(NG)' <> \\u11BC;" | |
492 | "'(Jf)' <> \\u11BD;" | |
493 | "'(Cf)' <> \\u11BE;" | |
494 | "'(Kf)' <> \\u11BF;" | |
495 | "'(Tf)' <> \\u11C0;" | |
496 | "'(Pf)' <> \\u11C1;" | |
497 | "'(Hf)' <> \\u11C2;"; | |
498 | ||
499 | /** | |
500 | * Convert short names to actual jamo. E.g., "x(LG)y" returns | |
501 | * "x\u11B0y". See JAMO_NAMES for table of names. | |
502 | */ | |
503 | UnicodeString | |
504 | JamoTest::nameToJamo(const UnicodeString& input) { | |
505 | if (NAME_JAMO == 0) { | |
506 | errln("Failed to create NAME_JAMO"); | |
507 | return input; /* failure! */ | |
508 | } | |
509 | UnicodeString result(input); | |
510 | NAME_JAMO->transliterate(result); | |
511 | return result; | |
512 | } | |
513 | ||
514 | /** | |
515 | * Convert jamo to short names. E.g., "x\u11B0y" returns | |
516 | * "x(LG)y". See JAMO_NAMES for table of names. | |
517 | */ | |
518 | UnicodeString | |
519 | JamoTest::jamoToName(const UnicodeString& input) { | |
520 | if (NAME_JAMO == 0) { | |
521 | errln("Failed to create NAME_JAMO"); | |
522 | return input; /* failure! */ | |
523 | } | |
524 | UnicodeString result(input); | |
525 | JAMO_NAME->transliterate(result); | |
526 | return result; | |
527 | } | |
528 | ||
529 | #endif /* #if !UCONFIG_NO_TRANSLITERATION */ |