]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/testi18n.c
2 * "$Id: testi18n.c 5294 2006-03-15 21:09:32Z mike $"
4 * Internationalization test for Common UNIX Printing System (CUPS).
6 * Copyright 1997-2006 by Easy Software Products.
8 * These coded instructions, statements, and computer programs are
9 * the property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights are outlined in the
11 * file "LICENSE.txt" which should have been included with this file.
12 * If this file is missing or damaged please contact Easy Software
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
26 * main() - Main entry for internationalization test module.
27 * print_utf8() - Print UTF-8 string with (optional) message.
28 * print_utf32() - Print UTF-32 string with (optional) message.
32 * Include necessary headers...
48 static void print_utf8(const char *msg
, const cups_utf8_t
*src
);
49 static void print_utf32(const char *msg
, const cups_utf32_t
*src
);
53 * 'main()' - Main entry for internationalization test module.
56 int /* O - Exit code */
57 main(int argc
, /* I - Argument Count */
58 char *argv
[]) /* I - Arguments */
60 FILE *fp
; /* File pointer */
61 int count
; /* File line counter */
62 int status
, /* Status of current test */
63 errors
; /* Error count */
64 char line
[1024]; /* File line source string */
65 int len
; /* Length (count) of string */
66 char legsrc
[1024], /* Legacy source string */
67 legdest
[1024], /* Legacy destination string */
68 *legptr
; /* Pointer into legacy string */
69 cups_utf8_t utf8latin
[] = /* UTF-8 Latin-1 source */
70 { 0x41, 0x20, 0x21, 0x3D, 0x20, 0xC3, 0x84, 0x2E, 0x00 };
71 /* "A != <A WITH DIAERESIS>." - use ISO 8859-1 */
72 cups_utf8_t utf8repla
[] = /* UTF-8 Latin-1 replacement */
73 { 0x41, 0x20, 0xE2, 0x89, 0xA2, 0x20, 0xC3, 0x84, 0x2E, 0x00 };
74 /* "A <NOT IDENTICAL TO> <A WITH DIAERESIS>." */
75 cups_utf8_t utf8greek
[] = /* UTF-8 Greek source string */
76 { 0x41, 0x20, 0x21, 0x3D, 0x20, 0xCE, 0x91, 0x2E, 0x00 };
77 /* "A != <ALPHA>." - use ISO 8859-7 */
78 cups_utf8_t utf8japan
[] = /* UTF-8 Japanese source */
79 { 0x41, 0x20, 0x21, 0x3D, 0x20, 0xEE, 0x9C, 0x80, 0x2E, 0x00 };
80 /* "A != <PRIVATE U+E700>." - use Windows 932 or EUC-JP */
81 cups_utf8_t utf8taiwan
[] = /* UTF-8 Chinese source */
82 { 0x41, 0x20, 0x21, 0x3D, 0x20, 0xE4, 0xB9, 0x82, 0x2E, 0x00 };
83 /* "A != <CJK U+4E42>." - use Windows 950 (Big5) or EUC-TW */
84 cups_utf8_t utf8good
[] = /* UTF-8 good 16-bit source */
85 { 0x41, 0x20, 0xE2, 0x89, 0xA2, 0x20, 0xC3, 0x84, 0x2E, 0x00 };
86 /* "A <NOT IDENTICAL TO> <A WITH DIAERESIS>." */
87 cups_utf8_t utf8bad
[] = /* UTF-8 bad 16-bit source */
88 { 0x41, 0x20, 0xE2, 0x89, 0xA2, 0x20, 0xF8, 0x84, 0x2E, 0x00 };
89 /* "A <NOT IDENTICAL TO> <...bad stuff...>." */
90 cups_utf8_t utf8dest
[1024]; /* UTF-8 destination string */
91 cups_utf32_t utf32src
[1024]; /* UTF-32 source string */
92 cups_utf32_t utf32dest
[1024]; /* UTF-32 destination string */
93 _cups_vmap_t
*vmap
; /* VBCS charmap pointer */
97 * Start with some conversion tests from a UTF-8 test file.
102 if ((fp
= fopen("utf8demo.txt", "r")) == NULL
)
104 perror("utf8demo.txt");
112 fputs("cupsUTF8ToUTF32 of utfdemo.txt: ", stdout
);
114 for (count
= 0, status
= 0; fgets(line
, sizeof(line
), fp
);)
118 if (cupsUTF8ToUTF32(utf32dest
, (cups_utf8_t
*)line
, 1024) < 0)
120 printf("FAIL (UTF-8 to UTF-32 on line %d)\n", count
);
131 * cupsUTF8ToCharset(CUPS_EUC_JP)
134 fputs("cupsUTF8ToCharset(CUPS_EUC_JP) of utfdemo.txt: ", stdout
);
138 for (count
= 0, status
= 0; fgets(line
, sizeof(line
), fp
);)
142 len
= cupsUTF8ToCharset(legdest
, (cups_utf8_t
*)line
, 1024, CUPS_EUC_JP
);
145 printf("FAIL (UTF-8 to EUC-JP on line %d)\n", count
);
158 * Test charmap load for ISO-8859-1...
161 fputs("_cupsCharmapGet(CUPS_ISO8859_1): ", stdout
);
163 if (!_cupsCharmapGet(CUPS_ISO8859_1
))
172 * Test charmap load for Windows-932 (Shift-JIS)...
175 fputs("_cupsCharmapGet(CUPS_WINDOWS_932): ", stdout
);
177 if (!_cupsCharmapGet(CUPS_WINDOWS_932
))
186 * Test VBCS charmap load for EUC-JP...
189 fputs("_cupsCharmapGet(CUPS_EUC_JP): ", stdout
);
191 if ((vmap
= (_cups_vmap_t
*)_cupsCharmapGet(CUPS_EUC_JP
)) == NULL
)
200 * Test VBCS charmap load for EUC-TW...
203 fputs("_cupsCharmapGet(CUPS_EUC_TW): ", stdout
);
205 if ((vmap
= (_cups_vmap_t
*)_cupsCharmapGet(CUPS_EUC_TW
)) == NULL
)
214 * Test UTF-8 to legacy charset (ISO 8859-1)...
217 fputs("cupsUTF8ToCharset(CUPS_ISO8859_1): ", stdout
);
221 len
= cupsUTF8ToCharset(legdest
, utf8latin
, 1024, CUPS_ISO8859_1
);
224 printf("FAIL (len=%d)\n", len
);
234 fputs("cupsCharsetToUTF8(CUPS_ISO8859_1): ", stdout
);
236 strcpy(legsrc
, legdest
);
238 len
= cupsCharsetToUTF8(utf8dest
, legsrc
, 1024, CUPS_ISO8859_1
);
239 if (len
!= strlen((char *)utf8latin
))
241 printf("FAIL (len=%d, expected %d)\n", len
, strlen((char *)utf8latin
));
242 print_utf8(" utf8latin", utf8latin
);
243 print_utf8(" utf8dest", utf8dest
);
246 else if (memcmp(utf8latin
, utf8dest
, len
))
248 puts("FAIL (results do not match)");
249 print_utf8(" utf8latin", utf8latin
);
250 print_utf8(" utf8dest", utf8dest
);
253 else if (cupsUTF8ToCharset(legdest
, utf8repla
, 1024, CUPS_ISO8859_1
) < 0)
255 puts("FAIL (replacement characters do not work!)");
262 * Test UTF-8 to/from legacy charset (ISO 8859-7)...
265 fputs("cupsUTF8ToCharset(CUPS_ISO8859_7): ", stdout
);
267 if (cupsUTF8ToCharset(legdest
, utf8greek
, 1024, CUPS_ISO8859_7
) < 0)
274 for (legptr
= legdest
; *legptr
&& *legptr
!= '?'; legptr
++);
278 puts("FAIL (unknown character)");
285 fputs("cupsCharsetToUTF8(CUPS_ISO8859_7): ", stdout
);
287 strcpy(legsrc
, legdest
);
289 len
= cupsCharsetToUTF8(utf8dest
, legsrc
, 1024, CUPS_ISO8859_7
);
290 if (len
!= strlen((char *)utf8greek
))
292 printf("FAIL (len=%d, expected %d)\n", len
, strlen((char *)utf8greek
));
293 print_utf8(" utf8greek", utf8greek
);
294 print_utf8(" utf8dest", utf8dest
);
297 else if (memcmp(utf8greek
, utf8dest
, len
))
299 puts("FAIL (results do not match)");
300 print_utf8(" utf8greek", utf8greek
);
301 print_utf8(" utf8dest", utf8dest
);
308 * Test UTF-8 to/from legacy charset (Windows 932)...
311 fputs("cupsUTF8ToCharset(CUPS_WINDOWS_932): ", stdout
);
313 if (cupsUTF8ToCharset(legdest
, utf8japan
, 1024, CUPS_WINDOWS_932
) < 0)
320 for (legptr
= legdest
; *legptr
&& *legptr
!= '?'; legptr
++);
324 puts("FAIL (unknown character)");
331 fputs("cupsCharsetToUTF8(CUPS_WINDOWS_932): ", stdout
);
333 strcpy(legsrc
, legdest
);
335 len
= cupsCharsetToUTF8(utf8dest
, legsrc
, 1024, CUPS_WINDOWS_932
);
336 if (len
!= strlen((char *)utf8japan
))
338 printf("FAIL (len=%d, expected %d)\n", len
, strlen((char *)utf8japan
));
339 print_utf8(" utf8japan", utf8japan
);
340 print_utf8(" utf8dest", utf8dest
);
343 else if (memcmp(utf8japan
, utf8dest
, len
))
345 puts("FAIL (results do not match)");
346 print_utf8(" utf8japan", utf8japan
);
347 print_utf8(" utf8dest", utf8dest
);
354 * Test UTF-8 to/from legacy charset (EUC-JP)...
357 fputs("cupsUTF8ToCharset(CUPS_EUC_JP): ", stdout
);
359 if (cupsUTF8ToCharset(legdest
, utf8japan
, 1024, CUPS_EUC_JP
) < 0)
366 for (legptr
= legdest
; *legptr
&& *legptr
!= '?'; legptr
++);
370 puts("FAIL (unknown character)");
377 fputs("cupsCharsetToUTF8(CUPS_EUC_JP): ", stdout
);
379 strcpy(legsrc
, legdest
);
381 len
= cupsCharsetToUTF8(utf8dest
, legsrc
, 1024, CUPS_EUC_JP
);
382 if (len
!= strlen((char *)utf8japan
))
384 printf("FAIL (len=%d, expected %d)\n", len
, strlen((char *)utf8japan
));
385 print_utf8(" utf8japan", utf8japan
);
386 print_utf8(" utf8dest", utf8dest
);
389 else if (memcmp(utf8japan
, utf8dest
, len
))
391 puts("FAIL (results do not match)");
392 print_utf8(" utf8japan", utf8japan
);
393 print_utf8(" utf8dest", utf8dest
);
400 * Test UTF-8 to/from legacy charset (Windows 950)...
403 fputs("cupsUTF8ToCharset(CUPS_WINDOWS_950): ", stdout
);
405 if (cupsUTF8ToCharset(legdest
, utf8taiwan
, 1024, CUPS_WINDOWS_950
) < 0)
412 for (legptr
= legdest
; *legptr
&& *legptr
!= '?'; legptr
++);
416 puts("FAIL (unknown character)");
423 fputs("cupsCharsetToUTF8(CUPS_WINDOWS_950): ", stdout
);
425 strcpy(legsrc
, legdest
);
427 len
= cupsCharsetToUTF8(utf8dest
, legsrc
, 1024, CUPS_WINDOWS_950
);
428 if (len
!= strlen((char *)utf8taiwan
))
430 printf("FAIL (len=%d, expected %d)\n", len
, strlen((char *)utf8taiwan
));
431 print_utf8(" utf8taiwan", utf8taiwan
);
432 print_utf8(" utf8dest", utf8dest
);
435 else if (memcmp(utf8taiwan
, utf8dest
, len
))
437 puts("FAIL (results do not match)");
438 print_utf8(" utf8taiwan", utf8taiwan
);
439 print_utf8(" utf8dest", utf8dest
);
446 * Test UTF-8 to/from legacy charset (EUC-TW)...
449 fputs("cupsUTF8ToCharset(CUPS_EUC_TW): ", stdout
);
451 if (cupsUTF8ToCharset(legdest
, utf8taiwan
, 1024, CUPS_EUC_TW
) < 0)
458 for (legptr
= legdest
; *legptr
&& *legptr
!= '?'; legptr
++);
462 puts("FAIL (unknown character)");
469 fputs("cupsCharsetToUTF8(CUPS_EUC_TW): ", stdout
);
471 strcpy(legsrc
, legdest
);
473 len
= cupsCharsetToUTF8(utf8dest
, legsrc
, 1024, CUPS_EUC_TW
);
474 if (len
!= strlen((char *)utf8taiwan
))
476 printf("FAIL (len=%d, expected %d)\n", len
, strlen((char *)utf8taiwan
));
477 print_utf8(" utf8taiwan", utf8taiwan
);
478 print_utf8(" utf8dest", utf8dest
);
481 else if (memcmp(utf8taiwan
, utf8dest
, len
))
483 puts("FAIL (results do not match)");
484 print_utf8(" utf8taiwan", utf8taiwan
);
485 print_utf8(" utf8dest", utf8dest
);
493 * Test UTF-8 (16-bit) to UTF-32 (w/ BOM)...
496 printf("\ntesti18n: Testing UTF-8 to UTF-32 (w/ BOM)...\n");
497 len
= cupsUTF8ToUTF32(utf32dest
, utf8good
, 1024);
502 print_utf8(" utf8good ", utf8good
);
503 print_utf32(" utf32dest", utf32dest
);
505 memcpy (utf32src
, utf32dest
, (len
+ 1) * sizeof(cups_utf32_t
));
506 len
= cupsUTF32ToUTF8(utf8dest
, utf32src
, 1024);
509 if (len
!= strlen ((char *) utf8good
))
511 if (memcmp(utf8good
, utf8dest
, len
) != 0)
515 * Test invalid UTF-8 (16-bit) to UTF-32 (w/ BOM)...
518 printf("\ntesti18n: Testing UTF-8 bad 16-bit source string...\n");
519 len
= cupsUTF8ToUTF32(utf32dest
, utf8bad
, 1024);
523 print_utf8(" utf8bad ", utf8bad
);
526 * Test _cupsCharmapFlush()...
529 printf("\ntesti18n: Testing _cupsCharmapFlush()...\n");
539 * 'print_utf8()' - Print UTF-8 string with (optional) message.
543 print_utf8(const char *msg
, /* I - Message String */
544 const cups_utf8_t
*src
) /* I - UTF-8 Source String */
550 printf(" %02x", *src
);
557 * 'print_utf32()' - Print UTF-32 string with (optional) message.
561 print_utf32(const char *msg
, /* I - Message String */
562 const cups_utf32_t
*src
) /* I - UTF-32 Source String */
568 printf(" %04x", (int) *src
);
575 * End of "$Id: testi18n.c 5294 2006-03-15 21:09:32Z mike $"