]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/testi18n.c
2 * "$Id: testi18n.c 6649 2007-07-11 21:46:42Z mike $"
4 * Internationalization test for Common UNIX Printing System (CUPS).
6 * Copyright 2007 by Apple Inc.
7 * Copyright 1997-2006 by Easy Software Products.
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/".
15 * This file is subject to the Apple OS-Developed Software exception.
19 * main() - Main entry for internationalization test module.
20 * print_utf8() - Print UTF-8 string with (optional) message.
24 * Include necessary headers...
41 static void print_utf8(const char *msg
, const cups_utf8_t
*src
);
45 * 'main()' - Main entry for internationalization test module.
48 int /* O - Exit code */
49 main(int argc
, /* I - Argument Count */
50 char *argv
[]) /* I - Arguments */
52 FILE *fp
; /* File pointer */
53 int count
; /* File line counter */
54 int status
, /* Status of current test */
55 errors
; /* Error count */
56 char line
[1024]; /* File line source string */
57 int len
; /* Length (count) of string */
58 char legsrc
[1024], /* Legacy source string */
59 legdest
[1024], /* Legacy destination string */
60 *legptr
; /* Pointer into legacy string */
61 cups_utf8_t utf8latin
[] = /* UTF-8 Latin-1 source */
62 { 0x41, 0x20, 0x21, 0x3D, 0x20, 0xC3, 0x84, 0x2E, 0x00 };
63 /* "A != <A WITH DIAERESIS>." - use ISO 8859-1 */
64 cups_utf8_t utf8repla
[] = /* UTF-8 Latin-1 replacement */
65 { 0x41, 0x20, 0xE2, 0x89, 0xA2, 0x20, 0xC3, 0x84, 0x2E, 0x00 };
66 /* "A <NOT IDENTICAL TO> <A WITH DIAERESIS>." */
67 cups_utf8_t utf8greek
[] = /* UTF-8 Greek source string */
68 { 0x41, 0x20, 0x21, 0x3D, 0x20, 0xCE, 0x91, 0x2E, 0x00 };
69 /* "A != <ALPHA>." - use ISO 8859-7 */
70 cups_utf8_t utf8japan
[] = /* UTF-8 Japanese source */
71 { 0x41, 0x20, 0x21, 0x3D, 0x20, 0xEE, 0x9C, 0x80, 0x2E, 0x00 };
72 /* "A != <PRIVATE U+E700>." - use Windows 932 or EUC-JP */
73 cups_utf8_t utf8taiwan
[] = /* UTF-8 Chinese source */
74 { 0x41, 0x20, 0x21, 0x3D, 0x20, 0xE4, 0xB9, 0x82, 0x2E, 0x00 };
75 /* "A != <CJK U+4E42>." - use Windows 950 (Big5) or EUC-TW */
76 cups_utf8_t utf8dest
[1024]; /* UTF-8 destination string */
77 cups_utf32_t utf32dest
[1024]; /* UTF-32 destination string */
81 * Make sure we have a symbolic link from the data directory to a
82 * "charmaps" directory, and then point the library at it...
85 if (access("charmaps", 0))
86 symlink("../data", "charmaps");
88 putenv("CUPS_DATADIR=.");
91 * Start with some conversion tests from a UTF-8 test file.
96 if ((fp
= fopen("utf8demo.txt", "r")) == NULL
)
98 perror("utf8demo.txt");
106 fputs("cupsUTF8ToUTF32 of utfdemo.txt: ", stdout
);
108 for (count
= 0, status
= 0; fgets(line
, sizeof(line
), fp
);)
112 if (cupsUTF8ToUTF32(utf32dest
, (cups_utf8_t
*)line
, 1024) < 0)
114 printf("FAIL (UTF-8 to UTF-32 on line %d)\n", count
);
125 * cupsUTF8ToCharset(CUPS_EUC_JP)
128 fputs("cupsUTF8ToCharset(CUPS_EUC_JP) of utfdemo.txt: ", stdout
);
132 for (count
= 0, status
= 0; fgets(line
, sizeof(line
), fp
);)
136 len
= cupsUTF8ToCharset(legdest
, (cups_utf8_t
*)line
, 1024, CUPS_EUC_JP
);
139 printf("FAIL (UTF-8 to EUC-JP on line %d)\n", count
);
152 * Test charmap load for ISO-8859-1...
155 fputs("_cupsCharmapGet(CUPS_ISO8859_1): ", stdout
);
157 if (!_cupsCharmapGet(CUPS_ISO8859_1
))
166 * Test charmap load for Windows-932 (Shift-JIS)...
169 fputs("_cupsCharmapGet(CUPS_WINDOWS_932): ", stdout
);
171 if (!_cupsCharmapGet(CUPS_WINDOWS_932
))
180 * Test VBCS charmap load for EUC-JP...
183 fputs("_cupsCharmapGet(CUPS_EUC_JP): ", stdout
);
185 if (!_cupsCharmapGet(CUPS_EUC_JP
))
194 * Test VBCS charmap load for EUC-TW...
197 fputs("_cupsCharmapGet(CUPS_EUC_TW): ", stdout
);
199 if (!_cupsCharmapGet(CUPS_EUC_TW
))
208 * Test UTF-8 to legacy charset (ISO 8859-1)...
211 fputs("cupsUTF8ToCharset(CUPS_ISO8859_1): ", stdout
);
215 len
= cupsUTF8ToCharset(legdest
, utf8latin
, 1024, CUPS_ISO8859_1
);
218 printf("FAIL (len=%d)\n", len
);
228 fputs("cupsCharsetToUTF8(CUPS_ISO8859_1): ", stdout
);
230 strcpy(legsrc
, legdest
);
232 len
= cupsCharsetToUTF8(utf8dest
, legsrc
, 1024, CUPS_ISO8859_1
);
233 if (len
!= strlen((char *)utf8latin
))
235 printf("FAIL (len=%d, expected %d)\n", len
, (int)strlen((char *)utf8latin
));
236 print_utf8(" utf8latin", utf8latin
);
237 print_utf8(" utf8dest", utf8dest
);
240 else if (memcmp(utf8latin
, utf8dest
, len
))
242 puts("FAIL (results do not match)");
243 print_utf8(" utf8latin", utf8latin
);
244 print_utf8(" utf8dest", utf8dest
);
247 else if (cupsUTF8ToCharset(legdest
, utf8repla
, 1024, CUPS_ISO8859_1
) < 0)
249 puts("FAIL (replacement characters do not work!)");
256 * Test UTF-8 to/from legacy charset (ISO 8859-7)...
259 fputs("cupsUTF8ToCharset(CUPS_ISO8859_7): ", stdout
);
261 if (cupsUTF8ToCharset(legdest
, utf8greek
, 1024, CUPS_ISO8859_7
) < 0)
268 for (legptr
= legdest
; *legptr
&& *legptr
!= '?'; legptr
++);
272 puts("FAIL (unknown character)");
279 fputs("cupsCharsetToUTF8(CUPS_ISO8859_7): ", stdout
);
281 strcpy(legsrc
, legdest
);
283 len
= cupsCharsetToUTF8(utf8dest
, legsrc
, 1024, CUPS_ISO8859_7
);
284 if (len
!= strlen((char *)utf8greek
))
286 printf("FAIL (len=%d, expected %d)\n", len
, (int)strlen((char *)utf8greek
));
287 print_utf8(" utf8greek", utf8greek
);
288 print_utf8(" utf8dest", utf8dest
);
291 else if (memcmp(utf8greek
, utf8dest
, len
))
293 puts("FAIL (results do not match)");
294 print_utf8(" utf8greek", utf8greek
);
295 print_utf8(" utf8dest", utf8dest
);
302 * Test UTF-8 to/from legacy charset (Windows 932)...
305 fputs("cupsUTF8ToCharset(CUPS_WINDOWS_932): ", stdout
);
307 if (cupsUTF8ToCharset(legdest
, utf8japan
, 1024, CUPS_WINDOWS_932
) < 0)
314 for (legptr
= legdest
; *legptr
&& *legptr
!= '?'; legptr
++);
318 puts("FAIL (unknown character)");
325 fputs("cupsCharsetToUTF8(CUPS_WINDOWS_932): ", stdout
);
327 strcpy(legsrc
, legdest
);
329 len
= cupsCharsetToUTF8(utf8dest
, legsrc
, 1024, CUPS_WINDOWS_932
);
330 if (len
!= strlen((char *)utf8japan
))
332 printf("FAIL (len=%d, expected %d)\n", len
, (int)strlen((char *)utf8japan
));
333 print_utf8(" utf8japan", utf8japan
);
334 print_utf8(" utf8dest", utf8dest
);
337 else if (memcmp(utf8japan
, utf8dest
, len
))
339 puts("FAIL (results do not match)");
340 print_utf8(" utf8japan", utf8japan
);
341 print_utf8(" utf8dest", utf8dest
);
348 * Test UTF-8 to/from legacy charset (EUC-JP)...
351 fputs("cupsUTF8ToCharset(CUPS_EUC_JP): ", stdout
);
353 if (cupsUTF8ToCharset(legdest
, utf8japan
, 1024, CUPS_EUC_JP
) < 0)
360 for (legptr
= legdest
; *legptr
&& *legptr
!= '?'; legptr
++);
364 puts("FAIL (unknown character)");
371 fputs("cupsCharsetToUTF8(CUPS_EUC_JP): ", stdout
);
373 strcpy(legsrc
, legdest
);
375 len
= cupsCharsetToUTF8(utf8dest
, legsrc
, 1024, CUPS_EUC_JP
);
376 if (len
!= strlen((char *)utf8japan
))
378 printf("FAIL (len=%d, expected %d)\n", len
, (int)strlen((char *)utf8japan
));
379 print_utf8(" utf8japan", utf8japan
);
380 print_utf8(" utf8dest", utf8dest
);
383 else if (memcmp(utf8japan
, utf8dest
, len
))
385 puts("FAIL (results do not match)");
386 print_utf8(" utf8japan", utf8japan
);
387 print_utf8(" utf8dest", utf8dest
);
394 * Test UTF-8 to/from legacy charset (Windows 950)...
397 fputs("cupsUTF8ToCharset(CUPS_WINDOWS_950): ", stdout
);
399 if (cupsUTF8ToCharset(legdest
, utf8taiwan
, 1024, CUPS_WINDOWS_950
) < 0)
406 for (legptr
= legdest
; *legptr
&& *legptr
!= '?'; legptr
++);
410 puts("FAIL (unknown character)");
417 fputs("cupsCharsetToUTF8(CUPS_WINDOWS_950): ", stdout
);
419 strcpy(legsrc
, legdest
);
421 len
= cupsCharsetToUTF8(utf8dest
, legsrc
, 1024, CUPS_WINDOWS_950
);
422 if (len
!= strlen((char *)utf8taiwan
))
424 printf("FAIL (len=%d, expected %d)\n", len
, (int)strlen((char *)utf8taiwan
));
425 print_utf8(" utf8taiwan", utf8taiwan
);
426 print_utf8(" utf8dest", utf8dest
);
429 else if (memcmp(utf8taiwan
, utf8dest
, len
))
431 puts("FAIL (results do not match)");
432 print_utf8(" utf8taiwan", utf8taiwan
);
433 print_utf8(" utf8dest", utf8dest
);
440 * Test UTF-8 to/from legacy charset (EUC-TW)...
443 fputs("cupsUTF8ToCharset(CUPS_EUC_TW): ", stdout
);
445 if (cupsUTF8ToCharset(legdest
, utf8taiwan
, 1024, CUPS_EUC_TW
) < 0)
452 for (legptr
= legdest
; *legptr
&& *legptr
!= '?'; legptr
++);
456 puts("FAIL (unknown character)");
463 fputs("cupsCharsetToUTF8(CUPS_EUC_TW): ", stdout
);
465 strcpy(legsrc
, legdest
);
467 len
= cupsCharsetToUTF8(utf8dest
, legsrc
, 1024, CUPS_EUC_TW
);
468 if (len
!= strlen((char *)utf8taiwan
))
470 printf("FAIL (len=%d, expected %d)\n", len
, (int)strlen((char *)utf8taiwan
));
471 print_utf8(" utf8taiwan", utf8taiwan
);
472 print_utf8(" utf8dest", utf8dest
);
475 else if (memcmp(utf8taiwan
, utf8dest
, len
))
477 puts("FAIL (results do not match)");
478 print_utf8(" utf8taiwan", utf8taiwan
);
479 print_utf8(" utf8dest", utf8dest
);
487 * Test UTF-8 (16-bit) to UTF-32 (w/ BOM)...
490 printf("\ntesti18n: Testing UTF-8 to UTF-32 (w/ BOM)...\n");
491 len
= cupsUTF8ToUTF32(utf32dest
, utf8good
, 1024);
496 print_utf8(" utf8good ", utf8good
);
497 print_utf32(" utf32dest", utf32dest
);
499 memcpy (utf32src
, utf32dest
, (len
+ 1) * sizeof(cups_utf32_t
));
500 len
= cupsUTF32ToUTF8(utf8dest
, utf32src
, 1024);
503 if (len
!= strlen ((char *) utf8good
))
505 if (memcmp(utf8good
, utf8dest
, len
) != 0)
509 * Test invalid UTF-8 (16-bit) to UTF-32 (w/ BOM)...
512 printf("\ntesti18n: Testing UTF-8 bad 16-bit source string...\n");
513 len
= cupsUTF8ToUTF32(utf32dest
, utf8bad
, 1024);
517 print_utf8(" utf8bad ", utf8bad
);
520 * Test _cupsCharmapFlush()...
523 printf("\ntesti18n: Testing _cupsCharmapFlush()...\n");
533 * 'print_utf8()' - Print UTF-8 string with (optional) message.
537 print_utf8(const char *msg
, /* I - Message String */
538 const cups_utf8_t
*src
) /* I - UTF-8 Source String */
544 printf(" %02x", *src
);
551 * End of "$Id: testi18n.c 6649 2007-07-11 21:46:42Z mike $"