]>
Commit | Line | Data |
---|---|---|
ef416fc2 | 1 | /* |
75bd9771 | 2 | * "$Id: testi18n.c 7560 2008-05-13 06:34:04Z mike $" |
ef416fc2 | 3 | * |
4 | * Internationalization test for Common UNIX Printing System (CUPS). | |
5 | * | |
bf3816c7 | 6 | * Copyright 2007-2009 by Apple Inc. |
e1d6a774 | 7 | * Copyright 1997-2006 by Easy Software Products. |
ef416fc2 | 8 | * |
bc44d920 | 9 | * These coded instructions, statements, and computer programs are the |
10 | * property of Apple Inc. and are protected by Federal copyright | |
11 | * law. Distribution and use rights are outlined in the file "LICENSE.txt" | |
12 | * which should have been included with this file. If this file is | |
13 | * file is missing or damaged, see the license at "http://www.cups.org/". | |
ef416fc2 | 14 | * |
bc44d920 | 15 | * This file is subject to the Apple OS-Developed Software exception. |
ef416fc2 | 16 | * |
17 | * Contents: | |
18 | * | |
89d46774 | 19 | * main() - Main entry for internationalization test module. |
20 | * print_utf8() - Print UTF-8 string with (optional) message. | |
ef416fc2 | 21 | */ |
22 | ||
23 | /* | |
24 | * Include necessary headers... | |
25 | */ | |
26 | ||
27 | #include <stdio.h> | |
28 | #include <stdlib.h> | |
29 | #include <errno.h> | |
30 | #include <time.h> | |
89d46774 | 31 | #include <unistd.h> |
ef416fc2 | 32 | |
e1d6a774 | 33 | #include "i18n.h" |
ef416fc2 | 34 | #include "string.h" |
ef416fc2 | 35 | |
36 | ||
bf3816c7 MS |
37 | /* |
38 | * Local globals... | |
39 | */ | |
40 | ||
41 | static const char * const lang_encodings[] = | |
42 | { /* Encoding strings */ | |
43 | "us-ascii", "iso-8859-1", | |
44 | "iso-8859-2", "iso-8859-3", | |
45 | "iso-8859-4", "iso-8859-5", | |
46 | "iso-8859-6", "iso-8859-7", | |
47 | "iso-8859-8", "iso-8859-9", | |
48 | "iso-8859-10", "utf-8", | |
49 | "iso-8859-13", "iso-8859-14", | |
50 | "iso-8859-15", "windows-874", | |
51 | "windows-1250", "windows-1251", | |
52 | "windows-1252", "windows-1253", | |
53 | "windows-1254", "windows-1255", | |
54 | "windows-1256", "windows-1257", | |
55 | "windows-1258", "koi8-r", | |
56 | "koi8-u", "iso-8859-11", | |
57 | "iso-8859-16", "mac-roman", | |
58 | "unknown", "unknown", | |
59 | "unknown", "unknown", | |
60 | "unknown", "unknown", | |
61 | "unknown", "unknown", | |
62 | "unknown", "unknown", | |
63 | "unknown", "unknown", | |
64 | "unknown", "unknown", | |
65 | "unknown", "unknown", | |
66 | "unknown", "unknown", | |
67 | "unknown", "unknown", | |
68 | "unknown", "unknown", | |
69 | "unknown", "unknown", | |
70 | "unknown", "unknown", | |
71 | "unknown", "unknown", | |
72 | "unknown", "unknown", | |
73 | "unknown", "unknown", | |
74 | "unknown", "unknown", | |
75 | "windows-932", "windows-936", | |
76 | "windows-949", "windows-950", | |
77 | "windows-1361", "unknown", | |
78 | "unknown", "unknown", | |
79 | "unknown", "unknown", | |
80 | "unknown", "unknown", | |
81 | "unknown", "unknown", | |
82 | "unknown", "unknown", | |
83 | "unknown", "unknown", | |
84 | "unknown", "unknown", | |
85 | "unknown", "unknown", | |
86 | "unknown", "unknown", | |
87 | "unknown", "unknown", | |
88 | "unknown", "unknown", | |
89 | "unknown", "unknown", | |
90 | "unknown", "unknown", | |
91 | "unknown", "unknown", | |
92 | "unknown", "unknown", | |
93 | "unknown", "unknown", | |
94 | "unknown", "unknown", | |
95 | "unknown", "unknown", | |
96 | "unknown", "unknown", | |
97 | "unknown", "unknown", | |
98 | "unknown", "unknown", | |
99 | "unknown", "unknown", | |
100 | "unknown", "unknown", | |
101 | "unknown", "unknown", | |
102 | "unknown", "unknown", | |
103 | "unknown", "unknown", | |
104 | "unknown", "unknown", | |
105 | "unknown", "unknown", | |
106 | "unknown", "unknown", | |
107 | "euc-cn", "euc-jp", | |
108 | "euc-kr", "euc-tw", | |
109 | "jis-x0213" | |
110 | }; | |
111 | ||
112 | ||
ef416fc2 | 113 | /* |
114 | * Local functions... | |
115 | */ | |
116 | ||
ef416fc2 | 117 | static void print_utf8(const char *msg, const cups_utf8_t *src); |
ef416fc2 | 118 | |
119 | ||
120 | /* | |
121 | * 'main()' - Main entry for internationalization test module. | |
122 | */ | |
123 | ||
124 | int /* O - Exit code */ | |
125 | main(int argc, /* I - Argument Count */ | |
126 | char *argv[]) /* I - Arguments */ | |
ef416fc2 | 127 | { |
128 | FILE *fp; /* File pointer */ | |
129 | int count; /* File line counter */ | |
e1d6a774 | 130 | int status, /* Status of current test */ |
131 | errors; /* Error count */ | |
ef416fc2 | 132 | char line[1024]; /* File line source string */ |
133 | int len; /* Length (count) of string */ | |
e1d6a774 | 134 | char legsrc[1024], /* Legacy source string */ |
135 | legdest[1024], /* Legacy destination string */ | |
136 | *legptr; /* Pointer into legacy string */ | |
ef416fc2 | 137 | cups_utf8_t utf8latin[] = /* UTF-8 Latin-1 source */ |
138 | { 0x41, 0x20, 0x21, 0x3D, 0x20, 0xC3, 0x84, 0x2E, 0x00 }; | |
139 | /* "A != <A WITH DIAERESIS>." - use ISO 8859-1 */ | |
140 | cups_utf8_t utf8repla[] = /* UTF-8 Latin-1 replacement */ | |
141 | { 0x41, 0x20, 0xE2, 0x89, 0xA2, 0x20, 0xC3, 0x84, 0x2E, 0x00 }; | |
142 | /* "A <NOT IDENTICAL TO> <A WITH DIAERESIS>." */ | |
143 | cups_utf8_t utf8greek[] = /* UTF-8 Greek source string */ | |
144 | { 0x41, 0x20, 0x21, 0x3D, 0x20, 0xCE, 0x91, 0x2E, 0x00 }; | |
e1d6a774 | 145 | /* "A != <ALPHA>." - use ISO 8859-7 */ |
ef416fc2 | 146 | cups_utf8_t utf8japan[] = /* UTF-8 Japanese source */ |
147 | { 0x41, 0x20, 0x21, 0x3D, 0x20, 0xEE, 0x9C, 0x80, 0x2E, 0x00 }; | |
148 | /* "A != <PRIVATE U+E700>." - use Windows 932 or EUC-JP */ | |
149 | cups_utf8_t utf8taiwan[] = /* UTF-8 Chinese source */ | |
150 | { 0x41, 0x20, 0x21, 0x3D, 0x20, 0xE4, 0xB9, 0x82, 0x2E, 0x00 }; | |
151 | /* "A != <CJK U+4E42>." - use Windows 950 (Big5) or EUC-TW */ | |
ef416fc2 | 152 | cups_utf8_t utf8dest[1024]; /* UTF-8 destination string */ |
ef416fc2 | 153 | cups_utf32_t utf32dest[1024]; /* UTF-32 destination string */ |
ef416fc2 | 154 | |
155 | ||
bf3816c7 MS |
156 | if (argc > 1) |
157 | { | |
158 | int i; /* Looping var */ | |
159 | cups_encoding_t encoding; /* Source encoding */ | |
160 | ||
161 | ||
162 | if (argc != 3) | |
163 | { | |
164 | puts("Usage: ./testi18n [filename charset]"); | |
165 | return (1); | |
166 | } | |
167 | ||
168 | if ((fp = fopen(argv[1], "rb")) == NULL) | |
169 | { | |
170 | perror(argv[1]); | |
171 | return (1); | |
172 | } | |
173 | ||
174 | for (i = 0, encoding = CUPS_AUTO_ENCODING; | |
175 | i < (int)(sizeof(lang_encodings) / sizeof(lang_encodings[0])); | |
176 | i ++) | |
177 | if (!strcasecmp(lang_encodings[i], argv[2])) | |
178 | { | |
179 | encoding = (cups_encoding_t)i; | |
180 | break; | |
181 | } | |
182 | ||
183 | if (encoding == CUPS_AUTO_ENCODING) | |
184 | { | |
185 | fprintf(stderr, "%s: Unknown character set!\n", argv[2]); | |
186 | return (1); | |
187 | } | |
188 | ||
189 | while (fgets(line, sizeof(line), fp)) | |
190 | { | |
191 | if (cupsCharsetToUTF8(utf8dest, line, sizeof(utf8dest), encoding) < 0) | |
192 | { | |
193 | fprintf(stderr, "%s: Unable to convert line: %s", argv[1], line); | |
194 | return (1); | |
195 | } | |
196 | ||
197 | fputs((char *)utf8dest, stdout); | |
198 | } | |
199 | ||
200 | fclose(fp); | |
201 | return (0); | |
202 | } | |
203 | ||
89d46774 | 204 | /* |
205 | * Make sure we have a symbolic link from the data directory to a | |
206 | * "charmaps" directory, and then point the library at it... | |
207 | */ | |
208 | ||
209 | if (access("charmaps", 0)) | |
210 | symlink("../data", "charmaps"); | |
211 | ||
212 | putenv("CUPS_DATADIR=."); | |
213 | ||
ef416fc2 | 214 | /* |
e1d6a774 | 215 | * Start with some conversion tests from a UTF-8 test file. |
ef416fc2 | 216 | */ |
217 | ||
e1d6a774 | 218 | errors = 0; |
219 | ||
bf3816c7 | 220 | if ((fp = fopen("utf8demo.txt", "rb")) == NULL) |
ef416fc2 | 221 | { |
e1d6a774 | 222 | perror("utf8demo.txt"); |
223 | return (1); | |
ef416fc2 | 224 | } |
225 | ||
226 | /* | |
e1d6a774 | 227 | * cupsUTF8ToUTF32 |
ef416fc2 | 228 | */ |
229 | ||
e1d6a774 | 230 | fputs("cupsUTF8ToUTF32 of utfdemo.txt: ", stdout); |
231 | ||
232 | for (count = 0, status = 0; fgets(line, sizeof(line), fp);) | |
ef416fc2 | 233 | { |
e1d6a774 | 234 | count ++; |
235 | ||
236 | if (cupsUTF8ToUTF32(utf32dest, (cups_utf8_t *)line, 1024) < 0) | |
237 | { | |
238 | printf("FAIL (UTF-8 to UTF-32 on line %d)\n", count); | |
239 | errors ++; | |
240 | status = 1; | |
241 | break; | |
242 | } | |
ef416fc2 | 243 | } |
244 | ||
e1d6a774 | 245 | if (!status) |
246 | puts("PASS"); | |
ef416fc2 | 247 | |
e1d6a774 | 248 | /* |
249 | * cupsUTF8ToCharset(CUPS_EUC_JP) | |
250 | */ | |
ef416fc2 | 251 | |
e1d6a774 | 252 | fputs("cupsUTF8ToCharset(CUPS_EUC_JP) of utfdemo.txt: ", stdout); |
ef416fc2 | 253 | |
e1d6a774 | 254 | rewind(fp); |
255 | ||
256 | for (count = 0, status = 0; fgets(line, sizeof(line), fp);) | |
257 | { | |
258 | count ++; | |
ef416fc2 | 259 | |
260 | len = cupsUTF8ToCharset(legdest, (cups_utf8_t *)line, 1024, CUPS_EUC_JP); | |
261 | if (len < 0) | |
e1d6a774 | 262 | { |
263 | printf("FAIL (UTF-8 to EUC-JP on line %d)\n", count); | |
264 | errors ++; | |
265 | status = 1; | |
266 | break; | |
267 | } | |
ef416fc2 | 268 | } |
269 | ||
e1d6a774 | 270 | if (!status) |
271 | puts("PASS"); | |
272 | ||
ef416fc2 | 273 | fclose(fp); |
274 | ||
e1d6a774 | 275 | /* |
276 | * Test charmap load for ISO-8859-1... | |
277 | */ | |
278 | ||
279 | fputs("_cupsCharmapGet(CUPS_ISO8859_1): ", stdout); | |
280 | ||
281 | if (!_cupsCharmapGet(CUPS_ISO8859_1)) | |
282 | { | |
283 | errors ++; | |
284 | puts("FAIL"); | |
285 | } | |
286 | else | |
287 | puts("PASS"); | |
ef416fc2 | 288 | |
289 | /* | |
e1d6a774 | 290 | * Test charmap load for Windows-932 (Shift-JIS)... |
ef416fc2 | 291 | */ |
292 | ||
e1d6a774 | 293 | fputs("_cupsCharmapGet(CUPS_WINDOWS_932): ", stdout); |
ef416fc2 | 294 | |
e1d6a774 | 295 | if (!_cupsCharmapGet(CUPS_WINDOWS_932)) |
296 | { | |
297 | errors ++; | |
298 | puts("FAIL"); | |
299 | } | |
300 | else | |
301 | puts("PASS"); | |
ef416fc2 | 302 | |
e1d6a774 | 303 | /* |
304 | * Test VBCS charmap load for EUC-JP... | |
305 | */ | |
306 | ||
307 | fputs("_cupsCharmapGet(CUPS_EUC_JP): ", stdout); | |
308 | ||
d09495fa | 309 | if (!_cupsCharmapGet(CUPS_EUC_JP)) |
ef416fc2 | 310 | { |
e1d6a774 | 311 | errors ++; |
312 | puts("FAIL"); | |
ef416fc2 | 313 | } |
e1d6a774 | 314 | else |
315 | puts("PASS"); | |
ef416fc2 | 316 | |
317 | /* | |
318 | * Test VBCS charmap load for EUC-TW... | |
319 | */ | |
320 | ||
e1d6a774 | 321 | fputs("_cupsCharmapGet(CUPS_EUC_TW): ", stdout); |
ef416fc2 | 322 | |
d09495fa | 323 | if (!_cupsCharmapGet(CUPS_EUC_TW)) |
ef416fc2 | 324 | { |
e1d6a774 | 325 | errors ++; |
326 | puts("FAIL"); | |
ef416fc2 | 327 | } |
e1d6a774 | 328 | else |
329 | puts("PASS"); | |
ef416fc2 | 330 | |
331 | /* | |
332 | * Test UTF-8 to legacy charset (ISO 8859-1)... | |
333 | */ | |
334 | ||
e1d6a774 | 335 | fputs("cupsUTF8ToCharset(CUPS_ISO8859_1): ", stdout); |
ef416fc2 | 336 | |
337 | legdest[0] = 0; | |
338 | ||
339 | len = cupsUTF8ToCharset(legdest, utf8latin, 1024, CUPS_ISO8859_1); | |
340 | if (len < 0) | |
ef416fc2 | 341 | { |
e1d6a774 | 342 | printf("FAIL (len=%d)\n", len); |
343 | errors ++; | |
ef416fc2 | 344 | } |
e1d6a774 | 345 | else |
346 | puts("PASS"); | |
ef416fc2 | 347 | |
e1d6a774 | 348 | /* |
349 | * cupsCharsetToUTF8 | |
350 | */ | |
ef416fc2 | 351 | |
e1d6a774 | 352 | fputs("cupsCharsetToUTF8(CUPS_ISO8859_1): ", stdout); |
ef416fc2 | 353 | |
e1d6a774 | 354 | strcpy(legsrc, legdest); |
ef416fc2 | 355 | |
e1d6a774 | 356 | len = cupsCharsetToUTF8(utf8dest, legsrc, 1024, CUPS_ISO8859_1); |
357 | if (len != strlen((char *)utf8latin)) | |
358 | { | |
89d46774 | 359 | printf("FAIL (len=%d, expected %d)\n", len, (int)strlen((char *)utf8latin)); |
e1d6a774 | 360 | print_utf8(" utf8latin", utf8latin); |
361 | print_utf8(" utf8dest", utf8dest); | |
362 | errors ++; | |
363 | } | |
364 | else if (memcmp(utf8latin, utf8dest, len)) | |
ef416fc2 | 365 | { |
e1d6a774 | 366 | puts("FAIL (results do not match)"); |
367 | print_utf8(" utf8latin", utf8latin); | |
368 | print_utf8(" utf8dest", utf8dest); | |
369 | errors ++; | |
ef416fc2 | 370 | } |
e1d6a774 | 371 | else if (cupsUTF8ToCharset(legdest, utf8repla, 1024, CUPS_ISO8859_1) < 0) |
372 | { | |
373 | puts("FAIL (replacement characters do not work!)"); | |
374 | errors ++; | |
375 | } | |
376 | else | |
377 | puts("PASS"); | |
ef416fc2 | 378 | |
379 | /* | |
e1d6a774 | 380 | * Test UTF-8 to/from legacy charset (ISO 8859-7)... |
ef416fc2 | 381 | */ |
e1d6a774 | 382 | |
383 | fputs("cupsUTF8ToCharset(CUPS_ISO8859_7): ", stdout); | |
384 | ||
385 | if (cupsUTF8ToCharset(legdest, utf8greek, 1024, CUPS_ISO8859_7) < 0) | |
ef416fc2 | 386 | { |
e1d6a774 | 387 | puts("FAIL"); |
388 | errors ++; | |
ef416fc2 | 389 | } |
e1d6a774 | 390 | else |
391 | { | |
392 | for (legptr = legdest; *legptr && *legptr != '?'; legptr ++); | |
393 | ||
394 | if (*legptr) | |
395 | { | |
396 | puts("FAIL (unknown character)"); | |
397 | errors ++; | |
398 | } | |
399 | else | |
400 | puts("PASS"); | |
401 | } | |
402 | ||
403 | fputs("cupsCharsetToUTF8(CUPS_ISO8859_7): ", stdout); | |
404 | ||
ef416fc2 | 405 | strcpy(legsrc, legdest); |
e1d6a774 | 406 | |
ef416fc2 | 407 | len = cupsCharsetToUTF8(utf8dest, legsrc, 1024, CUPS_ISO8859_7); |
e1d6a774 | 408 | if (len != strlen((char *)utf8greek)) |
409 | { | |
89d46774 | 410 | printf("FAIL (len=%d, expected %d)\n", len, (int)strlen((char *)utf8greek)); |
e1d6a774 | 411 | print_utf8(" utf8greek", utf8greek); |
412 | print_utf8(" utf8dest", utf8dest); | |
413 | errors ++; | |
414 | } | |
415 | else if (memcmp(utf8greek, utf8dest, len)) | |
416 | { | |
417 | puts("FAIL (results do not match)"); | |
418 | print_utf8(" utf8greek", utf8greek); | |
419 | print_utf8(" utf8dest", utf8dest); | |
420 | errors ++; | |
421 | } | |
422 | else | |
423 | puts("PASS"); | |
ef416fc2 | 424 | |
425 | /* | |
e1d6a774 | 426 | * Test UTF-8 to/from legacy charset (Windows 932)... |
ef416fc2 | 427 | */ |
e1d6a774 | 428 | |
429 | fputs("cupsUTF8ToCharset(CUPS_WINDOWS_932): ", stdout); | |
430 | ||
431 | if (cupsUTF8ToCharset(legdest, utf8japan, 1024, CUPS_WINDOWS_932) < 0) | |
ef416fc2 | 432 | { |
e1d6a774 | 433 | puts("FAIL"); |
434 | errors ++; | |
ef416fc2 | 435 | } |
e1d6a774 | 436 | else |
437 | { | |
438 | for (legptr = legdest; *legptr && *legptr != '?'; legptr ++); | |
439 | ||
440 | if (*legptr) | |
441 | { | |
442 | puts("FAIL (unknown character)"); | |
443 | errors ++; | |
444 | } | |
445 | else | |
446 | puts("PASS"); | |
447 | } | |
448 | ||
449 | fputs("cupsCharsetToUTF8(CUPS_WINDOWS_932): ", stdout); | |
450 | ||
ef416fc2 | 451 | strcpy(legsrc, legdest); |
e1d6a774 | 452 | |
ef416fc2 | 453 | len = cupsCharsetToUTF8(utf8dest, legsrc, 1024, CUPS_WINDOWS_932); |
e1d6a774 | 454 | if (len != strlen((char *)utf8japan)) |
455 | { | |
89d46774 | 456 | printf("FAIL (len=%d, expected %d)\n", len, (int)strlen((char *)utf8japan)); |
e1d6a774 | 457 | print_utf8(" utf8japan", utf8japan); |
458 | print_utf8(" utf8dest", utf8dest); | |
459 | errors ++; | |
460 | } | |
461 | else if (memcmp(utf8japan, utf8dest, len)) | |
462 | { | |
463 | puts("FAIL (results do not match)"); | |
464 | print_utf8(" utf8japan", utf8japan); | |
465 | print_utf8(" utf8dest", utf8dest); | |
466 | errors ++; | |
467 | } | |
468 | else | |
469 | puts("PASS"); | |
ef416fc2 | 470 | |
471 | /* | |
e1d6a774 | 472 | * Test UTF-8 to/from legacy charset (EUC-JP)... |
ef416fc2 | 473 | */ |
e1d6a774 | 474 | |
475 | fputs("cupsUTF8ToCharset(CUPS_EUC_JP): ", stdout); | |
476 | ||
477 | if (cupsUTF8ToCharset(legdest, utf8japan, 1024, CUPS_EUC_JP) < 0) | |
ef416fc2 | 478 | { |
e1d6a774 | 479 | puts("FAIL"); |
480 | errors ++; | |
ef416fc2 | 481 | } |
e1d6a774 | 482 | else |
483 | { | |
484 | for (legptr = legdest; *legptr && *legptr != '?'; legptr ++); | |
485 | ||
486 | if (*legptr) | |
487 | { | |
488 | puts("FAIL (unknown character)"); | |
489 | errors ++; | |
490 | } | |
491 | else | |
492 | puts("PASS"); | |
493 | } | |
494 | ||
495 | fputs("cupsCharsetToUTF8(CUPS_EUC_JP): ", stdout); | |
496 | ||
ef416fc2 | 497 | strcpy(legsrc, legdest); |
e1d6a774 | 498 | |
ef416fc2 | 499 | len = cupsCharsetToUTF8(utf8dest, legsrc, 1024, CUPS_EUC_JP); |
e1d6a774 | 500 | if (len != strlen((char *)utf8japan)) |
501 | { | |
89d46774 | 502 | printf("FAIL (len=%d, expected %d)\n", len, (int)strlen((char *)utf8japan)); |
e1d6a774 | 503 | print_utf8(" utf8japan", utf8japan); |
504 | print_utf8(" utf8dest", utf8dest); | |
505 | errors ++; | |
506 | } | |
507 | else if (memcmp(utf8japan, utf8dest, len)) | |
508 | { | |
509 | puts("FAIL (results do not match)"); | |
510 | print_utf8(" utf8japan", utf8japan); | |
511 | print_utf8(" utf8dest", utf8dest); | |
512 | errors ++; | |
513 | } | |
514 | else | |
515 | puts("PASS"); | |
ef416fc2 | 516 | |
517 | /* | |
e1d6a774 | 518 | * Test UTF-8 to/from legacy charset (Windows 950)... |
ef416fc2 | 519 | */ |
e1d6a774 | 520 | |
521 | fputs("cupsUTF8ToCharset(CUPS_WINDOWS_950): ", stdout); | |
522 | ||
523 | if (cupsUTF8ToCharset(legdest, utf8taiwan, 1024, CUPS_WINDOWS_950) < 0) | |
524 | { | |
525 | puts("FAIL"); | |
526 | errors ++; | |
527 | } | |
528 | else | |
ef416fc2 | 529 | { |
e1d6a774 | 530 | for (legptr = legdest; *legptr && *legptr != '?'; legptr ++); |
531 | ||
532 | if (*legptr) | |
533 | { | |
534 | puts("FAIL (unknown character)"); | |
535 | errors ++; | |
536 | } | |
537 | else | |
538 | puts("PASS"); | |
ef416fc2 | 539 | } |
e1d6a774 | 540 | |
541 | fputs("cupsCharsetToUTF8(CUPS_WINDOWS_950): ", stdout); | |
542 | ||
ef416fc2 | 543 | strcpy(legsrc, legdest); |
e1d6a774 | 544 | |
ef416fc2 | 545 | len = cupsCharsetToUTF8(utf8dest, legsrc, 1024, CUPS_WINDOWS_950); |
e1d6a774 | 546 | if (len != strlen((char *)utf8taiwan)) |
547 | { | |
89d46774 | 548 | printf("FAIL (len=%d, expected %d)\n", len, (int)strlen((char *)utf8taiwan)); |
e1d6a774 | 549 | print_utf8(" utf8taiwan", utf8taiwan); |
550 | print_utf8(" utf8dest", utf8dest); | |
551 | errors ++; | |
552 | } | |
553 | else if (memcmp(utf8taiwan, utf8dest, len)) | |
554 | { | |
555 | puts("FAIL (results do not match)"); | |
556 | print_utf8(" utf8taiwan", utf8taiwan); | |
557 | print_utf8(" utf8dest", utf8dest); | |
558 | errors ++; | |
559 | } | |
560 | else | |
561 | puts("PASS"); | |
ef416fc2 | 562 | |
563 | /* | |
e1d6a774 | 564 | * Test UTF-8 to/from legacy charset (EUC-TW)... |
ef416fc2 | 565 | */ |
e1d6a774 | 566 | |
567 | fputs("cupsUTF8ToCharset(CUPS_EUC_TW): ", stdout); | |
568 | ||
569 | if (cupsUTF8ToCharset(legdest, utf8taiwan, 1024, CUPS_EUC_TW) < 0) | |
570 | { | |
571 | puts("FAIL"); | |
572 | errors ++; | |
573 | } | |
574 | else | |
ef416fc2 | 575 | { |
e1d6a774 | 576 | for (legptr = legdest; *legptr && *legptr != '?'; legptr ++); |
577 | ||
578 | if (*legptr) | |
579 | { | |
580 | puts("FAIL (unknown character)"); | |
581 | errors ++; | |
582 | } | |
583 | else | |
584 | puts("PASS"); | |
ef416fc2 | 585 | } |
e1d6a774 | 586 | |
587 | fputs("cupsCharsetToUTF8(CUPS_EUC_TW): ", stdout); | |
588 | ||
ef416fc2 | 589 | strcpy(legsrc, legdest); |
e1d6a774 | 590 | |
ef416fc2 | 591 | len = cupsCharsetToUTF8(utf8dest, legsrc, 1024, CUPS_EUC_TW); |
e1d6a774 | 592 | if (len != strlen((char *)utf8taiwan)) |
593 | { | |
89d46774 | 594 | printf("FAIL (len=%d, expected %d)\n", len, (int)strlen((char *)utf8taiwan)); |
e1d6a774 | 595 | print_utf8(" utf8taiwan", utf8taiwan); |
596 | print_utf8(" utf8dest", utf8dest); | |
597 | errors ++; | |
598 | } | |
599 | else if (memcmp(utf8taiwan, utf8dest, len)) | |
600 | { | |
601 | puts("FAIL (results do not match)"); | |
602 | print_utf8(" utf8taiwan", utf8taiwan); | |
603 | print_utf8(" utf8dest", utf8dest); | |
604 | errors ++; | |
605 | } | |
606 | else | |
607 | puts("PASS"); | |
ef416fc2 | 608 | |
e1d6a774 | 609 | #if 0 |
ef416fc2 | 610 | /* |
611 | * Test UTF-8 (16-bit) to UTF-32 (w/ BOM)... | |
612 | */ | |
613 | if (verbose) | |
614 | printf("\ntesti18n: Testing UTF-8 to UTF-32 (w/ BOM)...\n"); | |
615 | len = cupsUTF8ToUTF32(utf32dest, utf8good, 1024); | |
616 | if (len < 0) | |
617 | return (1); | |
618 | if (verbose) | |
619 | { | |
620 | print_utf8(" utf8good ", utf8good); | |
621 | print_utf32(" utf32dest", utf32dest); | |
622 | } | |
623 | memcpy (utf32src, utf32dest, (len + 1) * sizeof(cups_utf32_t)); | |
624 | len = cupsUTF32ToUTF8(utf8dest, utf32src, 1024); | |
625 | if (len < 0) | |
626 | return (1); | |
627 | if (len != strlen ((char *) utf8good)) | |
628 | return (1); | |
629 | if (memcmp(utf8good, utf8dest, len) != 0) | |
630 | return (1); | |
631 | ||
632 | /* | |
633 | * Test invalid UTF-8 (16-bit) to UTF-32 (w/ BOM)... | |
634 | */ | |
635 | if (verbose) | |
636 | printf("\ntesti18n: Testing UTF-8 bad 16-bit source string...\n"); | |
637 | len = cupsUTF8ToUTF32(utf32dest, utf8bad, 1024); | |
638 | if (len >= 0) | |
639 | return (1); | |
640 | if (verbose) | |
641 | print_utf8(" utf8bad ", utf8bad); | |
642 | ||
643 | /* | |
e1d6a774 | 644 | * Test _cupsCharmapFlush()... |
ef416fc2 | 645 | */ |
646 | if (verbose) | |
e1d6a774 | 647 | printf("\ntesti18n: Testing _cupsCharmapFlush()...\n"); |
648 | _cupsCharmapFlush(); | |
ef416fc2 | 649 | return (0); |
e1d6a774 | 650 | #endif /* 0 */ |
651 | ||
652 | return (errors > 0); | |
ef416fc2 | 653 | } |
654 | ||
655 | ||
656 | /* | |
e1d6a774 | 657 | * 'print_utf8()' - Print UTF-8 string with (optional) message. |
ef416fc2 | 658 | */ |
659 | ||
e1d6a774 | 660 | static void |
661 | print_utf8(const char *msg, /* I - Message String */ | |
662 | const cups_utf8_t *src) /* I - UTF-8 Source String */ | |
ef416fc2 | 663 | { |
58dc1933 MS |
664 | const char *prefix; /* Prefix string */ |
665 | ||
666 | ||
e1d6a774 | 667 | if (msg) |
668 | printf("%s:", msg); | |
ef416fc2 | 669 | |
58dc1933 MS |
670 | for (prefix = " "; *src; src ++) |
671 | { | |
672 | printf("%s%02x", prefix, *src); | |
673 | ||
674 | if ((src[0] & 0x80) && (src[1] & 0x80)) | |
675 | prefix = ""; | |
676 | else | |
677 | prefix = " "; | |
678 | } | |
ef416fc2 | 679 | |
e1d6a774 | 680 | putchar('\n'); |
681 | } | |
ef416fc2 | 682 | |
ef416fc2 | 683 | |
e1d6a774 | 684 | /* |
75bd9771 | 685 | * End of "$Id: testi18n.c 7560 2008-05-13 06:34:04Z mike $" |
ef416fc2 | 686 | */ |