]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/testi18n.c
3a01eb15eb4e7849a0f561db2f84b58fd4becad0
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.
31 * Include necessary headers...
48 static void print_utf8(const char *msg
, const cups_utf8_t
*src
);
52 * 'main()' - Main entry for internationalization test module.
55 int /* O - Exit code */
56 main(int argc
, /* I - Argument Count */
57 char *argv
[]) /* I - Arguments */
59 FILE *fp
; /* File pointer */
60 int count
; /* File line counter */
61 int status
, /* Status of current test */
62 errors
; /* Error count */
63 char line
[1024]; /* File line source string */
64 int len
; /* Length (count) of string */
65 char legsrc
[1024], /* Legacy source string */
66 legdest
[1024], /* Legacy destination string */
67 *legptr
; /* Pointer into legacy string */
68 cups_utf8_t utf8latin
[] = /* UTF-8 Latin-1 source */
69 { 0x41, 0x20, 0x21, 0x3D, 0x20, 0xC3, 0x84, 0x2E, 0x00 };
70 /* "A != <A WITH DIAERESIS>." - use ISO 8859-1 */
71 cups_utf8_t utf8repla
[] = /* UTF-8 Latin-1 replacement */
72 { 0x41, 0x20, 0xE2, 0x89, 0xA2, 0x20, 0xC3, 0x84, 0x2E, 0x00 };
73 /* "A <NOT IDENTICAL TO> <A WITH DIAERESIS>." */
74 cups_utf8_t utf8greek
[] = /* UTF-8 Greek source string */
75 { 0x41, 0x20, 0x21, 0x3D, 0x20, 0xCE, 0x91, 0x2E, 0x00 };
76 /* "A != <ALPHA>." - use ISO 8859-7 */
77 cups_utf8_t utf8japan
[] = /* UTF-8 Japanese source */
78 { 0x41, 0x20, 0x21, 0x3D, 0x20, 0xEE, 0x9C, 0x80, 0x2E, 0x00 };
79 /* "A != <PRIVATE U+E700>." - use Windows 932 or EUC-JP */
80 cups_utf8_t utf8taiwan
[] = /* UTF-8 Chinese source */
81 { 0x41, 0x20, 0x21, 0x3D, 0x20, 0xE4, 0xB9, 0x82, 0x2E, 0x00 };
82 /* "A != <CJK U+4E42>." - use Windows 950 (Big5) or EUC-TW */
83 cups_utf8_t utf8dest
[1024]; /* UTF-8 destination string */
84 cups_utf32_t utf32dest
[1024]; /* UTF-32 destination string */
85 _cups_vmap_t
*vmap
; /* VBCS charmap pointer */
89 * Make sure we have a symbolic link from the data directory to a
90 * "charmaps" directory, and then point the library at it...
93 if (access("charmaps", 0))
94 symlink("../data", "charmaps");
96 putenv("CUPS_DATADIR=.");
99 * Start with some conversion tests from a UTF-8 test file.
104 if ((fp
= fopen("utf8demo.txt", "r")) == NULL
)
106 perror("utf8demo.txt");
114 fputs("cupsUTF8ToUTF32 of utfdemo.txt: ", stdout
);
116 for (count
= 0, status
= 0; fgets(line
, sizeof(line
), fp
);)
120 if (cupsUTF8ToUTF32(utf32dest
, (cups_utf8_t
*)line
, 1024) < 0)
122 printf("FAIL (UTF-8 to UTF-32 on line %d)\n", count
);
133 * cupsUTF8ToCharset(CUPS_EUC_JP)
136 fputs("cupsUTF8ToCharset(CUPS_EUC_JP) of utfdemo.txt: ", stdout
);
140 for (count
= 0, status
= 0; fgets(line
, sizeof(line
), fp
);)
144 len
= cupsUTF8ToCharset(legdest
, (cups_utf8_t
*)line
, 1024, CUPS_EUC_JP
);
147 printf("FAIL (UTF-8 to EUC-JP on line %d)\n", count
);
160 * Test charmap load for ISO-8859-1...
163 fputs("_cupsCharmapGet(CUPS_ISO8859_1): ", stdout
);
165 if (!_cupsCharmapGet(CUPS_ISO8859_1
))
174 * Test charmap load for Windows-932 (Shift-JIS)...
177 fputs("_cupsCharmapGet(CUPS_WINDOWS_932): ", stdout
);
179 if (!_cupsCharmapGet(CUPS_WINDOWS_932
))
188 * Test VBCS charmap load for EUC-JP...
191 fputs("_cupsCharmapGet(CUPS_EUC_JP): ", stdout
);
193 if ((vmap
= (_cups_vmap_t
*)_cupsCharmapGet(CUPS_EUC_JP
)) == NULL
)
202 * Test VBCS charmap load for EUC-TW...
205 fputs("_cupsCharmapGet(CUPS_EUC_TW): ", stdout
);
207 if ((vmap
= (_cups_vmap_t
*)_cupsCharmapGet(CUPS_EUC_TW
)) == NULL
)
216 * Test UTF-8 to legacy charset (ISO 8859-1)...
219 fputs("cupsUTF8ToCharset(CUPS_ISO8859_1): ", stdout
);
223 len
= cupsUTF8ToCharset(legdest
, utf8latin
, 1024, CUPS_ISO8859_1
);
226 printf("FAIL (len=%d)\n", len
);
236 fputs("cupsCharsetToUTF8(CUPS_ISO8859_1): ", stdout
);
238 strcpy(legsrc
, legdest
);
240 len
= cupsCharsetToUTF8(utf8dest
, legsrc
, 1024, CUPS_ISO8859_1
);
241 if (len
!= strlen((char *)utf8latin
))
243 printf("FAIL (len=%d, expected %d)\n", len
, (int)strlen((char *)utf8latin
));
244 print_utf8(" utf8latin", utf8latin
);
245 print_utf8(" utf8dest", utf8dest
);
248 else if (memcmp(utf8latin
, utf8dest
, len
))
250 puts("FAIL (results do not match)");
251 print_utf8(" utf8latin", utf8latin
);
252 print_utf8(" utf8dest", utf8dest
);
255 else if (cupsUTF8ToCharset(legdest
, utf8repla
, 1024, CUPS_ISO8859_1
) < 0)
257 puts("FAIL (replacement characters do not work!)");
264 * Test UTF-8 to/from legacy charset (ISO 8859-7)...
267 fputs("cupsUTF8ToCharset(CUPS_ISO8859_7): ", stdout
);
269 if (cupsUTF8ToCharset(legdest
, utf8greek
, 1024, CUPS_ISO8859_7
) < 0)
276 for (legptr
= legdest
; *legptr
&& *legptr
!= '?'; legptr
++);
280 puts("FAIL (unknown character)");
287 fputs("cupsCharsetToUTF8(CUPS_ISO8859_7): ", stdout
);
289 strcpy(legsrc
, legdest
);
291 len
= cupsCharsetToUTF8(utf8dest
, legsrc
, 1024, CUPS_ISO8859_7
);
292 if (len
!= strlen((char *)utf8greek
))
294 printf("FAIL (len=%d, expected %d)\n", len
, (int)strlen((char *)utf8greek
));
295 print_utf8(" utf8greek", utf8greek
);
296 print_utf8(" utf8dest", utf8dest
);
299 else if (memcmp(utf8greek
, utf8dest
, len
))
301 puts("FAIL (results do not match)");
302 print_utf8(" utf8greek", utf8greek
);
303 print_utf8(" utf8dest", utf8dest
);
310 * Test UTF-8 to/from legacy charset (Windows 932)...
313 fputs("cupsUTF8ToCharset(CUPS_WINDOWS_932): ", stdout
);
315 if (cupsUTF8ToCharset(legdest
, utf8japan
, 1024, CUPS_WINDOWS_932
) < 0)
322 for (legptr
= legdest
; *legptr
&& *legptr
!= '?'; legptr
++);
326 puts("FAIL (unknown character)");
333 fputs("cupsCharsetToUTF8(CUPS_WINDOWS_932): ", stdout
);
335 strcpy(legsrc
, legdest
);
337 len
= cupsCharsetToUTF8(utf8dest
, legsrc
, 1024, CUPS_WINDOWS_932
);
338 if (len
!= strlen((char *)utf8japan
))
340 printf("FAIL (len=%d, expected %d)\n", len
, (int)strlen((char *)utf8japan
));
341 print_utf8(" utf8japan", utf8japan
);
342 print_utf8(" utf8dest", utf8dest
);
345 else if (memcmp(utf8japan
, utf8dest
, len
))
347 puts("FAIL (results do not match)");
348 print_utf8(" utf8japan", utf8japan
);
349 print_utf8(" utf8dest", utf8dest
);
356 * Test UTF-8 to/from legacy charset (EUC-JP)...
359 fputs("cupsUTF8ToCharset(CUPS_EUC_JP): ", stdout
);
361 if (cupsUTF8ToCharset(legdest
, utf8japan
, 1024, CUPS_EUC_JP
) < 0)
368 for (legptr
= legdest
; *legptr
&& *legptr
!= '?'; legptr
++);
372 puts("FAIL (unknown character)");
379 fputs("cupsCharsetToUTF8(CUPS_EUC_JP): ", stdout
);
381 strcpy(legsrc
, legdest
);
383 len
= cupsCharsetToUTF8(utf8dest
, legsrc
, 1024, CUPS_EUC_JP
);
384 if (len
!= strlen((char *)utf8japan
))
386 printf("FAIL (len=%d, expected %d)\n", len
, (int)strlen((char *)utf8japan
));
387 print_utf8(" utf8japan", utf8japan
);
388 print_utf8(" utf8dest", utf8dest
);
391 else if (memcmp(utf8japan
, utf8dest
, len
))
393 puts("FAIL (results do not match)");
394 print_utf8(" utf8japan", utf8japan
);
395 print_utf8(" utf8dest", utf8dest
);
402 * Test UTF-8 to/from legacy charset (Windows 950)...
405 fputs("cupsUTF8ToCharset(CUPS_WINDOWS_950): ", stdout
);
407 if (cupsUTF8ToCharset(legdest
, utf8taiwan
, 1024, CUPS_WINDOWS_950
) < 0)
414 for (legptr
= legdest
; *legptr
&& *legptr
!= '?'; legptr
++);
418 puts("FAIL (unknown character)");
425 fputs("cupsCharsetToUTF8(CUPS_WINDOWS_950): ", stdout
);
427 strcpy(legsrc
, legdest
);
429 len
= cupsCharsetToUTF8(utf8dest
, legsrc
, 1024, CUPS_WINDOWS_950
);
430 if (len
!= strlen((char *)utf8taiwan
))
432 printf("FAIL (len=%d, expected %d)\n", len
, (int)strlen((char *)utf8taiwan
));
433 print_utf8(" utf8taiwan", utf8taiwan
);
434 print_utf8(" utf8dest", utf8dest
);
437 else if (memcmp(utf8taiwan
, utf8dest
, len
))
439 puts("FAIL (results do not match)");
440 print_utf8(" utf8taiwan", utf8taiwan
);
441 print_utf8(" utf8dest", utf8dest
);
448 * Test UTF-8 to/from legacy charset (EUC-TW)...
451 fputs("cupsUTF8ToCharset(CUPS_EUC_TW): ", stdout
);
453 if (cupsUTF8ToCharset(legdest
, utf8taiwan
, 1024, CUPS_EUC_TW
) < 0)
460 for (legptr
= legdest
; *legptr
&& *legptr
!= '?'; legptr
++);
464 puts("FAIL (unknown character)");
471 fputs("cupsCharsetToUTF8(CUPS_EUC_TW): ", stdout
);
473 strcpy(legsrc
, legdest
);
475 len
= cupsCharsetToUTF8(utf8dest
, legsrc
, 1024, CUPS_EUC_TW
);
476 if (len
!= strlen((char *)utf8taiwan
))
478 printf("FAIL (len=%d, expected %d)\n", len
, (int)strlen((char *)utf8taiwan
));
479 print_utf8(" utf8taiwan", utf8taiwan
);
480 print_utf8(" utf8dest", utf8dest
);
483 else if (memcmp(utf8taiwan
, utf8dest
, len
))
485 puts("FAIL (results do not match)");
486 print_utf8(" utf8taiwan", utf8taiwan
);
487 print_utf8(" utf8dest", utf8dest
);
495 * Test UTF-8 (16-bit) to UTF-32 (w/ BOM)...
498 printf("\ntesti18n: Testing UTF-8 to UTF-32 (w/ BOM)...\n");
499 len
= cupsUTF8ToUTF32(utf32dest
, utf8good
, 1024);
504 print_utf8(" utf8good ", utf8good
);
505 print_utf32(" utf32dest", utf32dest
);
507 memcpy (utf32src
, utf32dest
, (len
+ 1) * sizeof(cups_utf32_t
));
508 len
= cupsUTF32ToUTF8(utf8dest
, utf32src
, 1024);
511 if (len
!= strlen ((char *) utf8good
))
513 if (memcmp(utf8good
, utf8dest
, len
) != 0)
517 * Test invalid UTF-8 (16-bit) to UTF-32 (w/ BOM)...
520 printf("\ntesti18n: Testing UTF-8 bad 16-bit source string...\n");
521 len
= cupsUTF8ToUTF32(utf32dest
, utf8bad
, 1024);
525 print_utf8(" utf8bad ", utf8bad
);
528 * Test _cupsCharmapFlush()...
531 printf("\ntesti18n: Testing _cupsCharmapFlush()...\n");
541 * 'print_utf8()' - Print UTF-8 string with (optional) message.
545 print_utf8(const char *msg
, /* I - Message String */
546 const cups_utf8_t
*src
) /* I - UTF-8 Source String */
552 printf(" %02x", *src
);