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