]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/testi18n.c
2 * "$Id: testi18n.c 5837 2006-08-17 14:37:40Z 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.
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 */
88 * Make sure we have a symbolic link from the data directory to a
89 * "charmaps" directory, and then point the library at it...
92 if (access("charmaps", 0))
93 symlink("../data", "charmaps");
95 putenv("CUPS_DATADIR=.");
98 * Start with some conversion tests from a UTF-8 test file.
103 if ((fp
= fopen("utf8demo.txt", "r")) == NULL
)
105 perror("utf8demo.txt");
113 fputs("cupsUTF8ToUTF32 of utfdemo.txt: ", stdout
);
115 for (count
= 0, status
= 0; fgets(line
, sizeof(line
), fp
);)
119 if (cupsUTF8ToUTF32(utf32dest
, (cups_utf8_t
*)line
, 1024) < 0)
121 printf("FAIL (UTF-8 to UTF-32 on line %d)\n", count
);
132 * cupsUTF8ToCharset(CUPS_EUC_JP)
135 fputs("cupsUTF8ToCharset(CUPS_EUC_JP) of utfdemo.txt: ", stdout
);
139 for (count
= 0, status
= 0; fgets(line
, sizeof(line
), fp
);)
143 len
= cupsUTF8ToCharset(legdest
, (cups_utf8_t
*)line
, 1024, CUPS_EUC_JP
);
146 printf("FAIL (UTF-8 to EUC-JP on line %d)\n", count
);
159 * Test charmap load for ISO-8859-1...
162 fputs("_cupsCharmapGet(CUPS_ISO8859_1): ", stdout
);
164 if (!_cupsCharmapGet(CUPS_ISO8859_1
))
173 * Test charmap load for Windows-932 (Shift-JIS)...
176 fputs("_cupsCharmapGet(CUPS_WINDOWS_932): ", stdout
);
178 if (!_cupsCharmapGet(CUPS_WINDOWS_932
))
187 * Test VBCS charmap load for EUC-JP...
190 fputs("_cupsCharmapGet(CUPS_EUC_JP): ", stdout
);
192 if (!_cupsCharmapGet(CUPS_EUC_JP
))
201 * Test VBCS charmap load for EUC-TW...
204 fputs("_cupsCharmapGet(CUPS_EUC_TW): ", stdout
);
206 if (!_cupsCharmapGet(CUPS_EUC_TW
))
215 * Test UTF-8 to legacy charset (ISO 8859-1)...
218 fputs("cupsUTF8ToCharset(CUPS_ISO8859_1): ", stdout
);
222 len
= cupsUTF8ToCharset(legdest
, utf8latin
, 1024, CUPS_ISO8859_1
);
225 printf("FAIL (len=%d)\n", len
);
235 fputs("cupsCharsetToUTF8(CUPS_ISO8859_1): ", stdout
);
237 strcpy(legsrc
, legdest
);
239 len
= cupsCharsetToUTF8(utf8dest
, legsrc
, 1024, CUPS_ISO8859_1
);
240 if (len
!= strlen((char *)utf8latin
))
242 printf("FAIL (len=%d, expected %d)\n", len
, (int)strlen((char *)utf8latin
));
243 print_utf8(" utf8latin", utf8latin
);
244 print_utf8(" utf8dest", utf8dest
);
247 else if (memcmp(utf8latin
, utf8dest
, len
))
249 puts("FAIL (results do not match)");
250 print_utf8(" utf8latin", utf8latin
);
251 print_utf8(" utf8dest", utf8dest
);
254 else if (cupsUTF8ToCharset(legdest
, utf8repla
, 1024, CUPS_ISO8859_1
) < 0)
256 puts("FAIL (replacement characters do not work!)");
263 * Test UTF-8 to/from legacy charset (ISO 8859-7)...
266 fputs("cupsUTF8ToCharset(CUPS_ISO8859_7): ", stdout
);
268 if (cupsUTF8ToCharset(legdest
, utf8greek
, 1024, CUPS_ISO8859_7
) < 0)
275 for (legptr
= legdest
; *legptr
&& *legptr
!= '?'; legptr
++);
279 puts("FAIL (unknown character)");
286 fputs("cupsCharsetToUTF8(CUPS_ISO8859_7): ", stdout
);
288 strcpy(legsrc
, legdest
);
290 len
= cupsCharsetToUTF8(utf8dest
, legsrc
, 1024, CUPS_ISO8859_7
);
291 if (len
!= strlen((char *)utf8greek
))
293 printf("FAIL (len=%d, expected %d)\n", len
, (int)strlen((char *)utf8greek
));
294 print_utf8(" utf8greek", utf8greek
);
295 print_utf8(" utf8dest", utf8dest
);
298 else if (memcmp(utf8greek
, utf8dest
, len
))
300 puts("FAIL (results do not match)");
301 print_utf8(" utf8greek", utf8greek
);
302 print_utf8(" utf8dest", utf8dest
);
309 * Test UTF-8 to/from legacy charset (Windows 932)...
312 fputs("cupsUTF8ToCharset(CUPS_WINDOWS_932): ", stdout
);
314 if (cupsUTF8ToCharset(legdest
, utf8japan
, 1024, CUPS_WINDOWS_932
) < 0)
321 for (legptr
= legdest
; *legptr
&& *legptr
!= '?'; legptr
++);
325 puts("FAIL (unknown character)");
332 fputs("cupsCharsetToUTF8(CUPS_WINDOWS_932): ", stdout
);
334 strcpy(legsrc
, legdest
);
336 len
= cupsCharsetToUTF8(utf8dest
, legsrc
, 1024, CUPS_WINDOWS_932
);
337 if (len
!= strlen((char *)utf8japan
))
339 printf("FAIL (len=%d, expected %d)\n", len
, (int)strlen((char *)utf8japan
));
340 print_utf8(" utf8japan", utf8japan
);
341 print_utf8(" utf8dest", utf8dest
);
344 else if (memcmp(utf8japan
, utf8dest
, len
))
346 puts("FAIL (results do not match)");
347 print_utf8(" utf8japan", utf8japan
);
348 print_utf8(" utf8dest", utf8dest
);
355 * Test UTF-8 to/from legacy charset (EUC-JP)...
358 fputs("cupsUTF8ToCharset(CUPS_EUC_JP): ", stdout
);
360 if (cupsUTF8ToCharset(legdest
, utf8japan
, 1024, CUPS_EUC_JP
) < 0)
367 for (legptr
= legdest
; *legptr
&& *legptr
!= '?'; legptr
++);
371 puts("FAIL (unknown character)");
378 fputs("cupsCharsetToUTF8(CUPS_EUC_JP): ", stdout
);
380 strcpy(legsrc
, legdest
);
382 len
= cupsCharsetToUTF8(utf8dest
, legsrc
, 1024, CUPS_EUC_JP
);
383 if (len
!= strlen((char *)utf8japan
))
385 printf("FAIL (len=%d, expected %d)\n", len
, (int)strlen((char *)utf8japan
));
386 print_utf8(" utf8japan", utf8japan
);
387 print_utf8(" utf8dest", utf8dest
);
390 else if (memcmp(utf8japan
, utf8dest
, len
))
392 puts("FAIL (results do not match)");
393 print_utf8(" utf8japan", utf8japan
);
394 print_utf8(" utf8dest", utf8dest
);
401 * Test UTF-8 to/from legacy charset (Windows 950)...
404 fputs("cupsUTF8ToCharset(CUPS_WINDOWS_950): ", stdout
);
406 if (cupsUTF8ToCharset(legdest
, utf8taiwan
, 1024, CUPS_WINDOWS_950
) < 0)
413 for (legptr
= legdest
; *legptr
&& *legptr
!= '?'; legptr
++);
417 puts("FAIL (unknown character)");
424 fputs("cupsCharsetToUTF8(CUPS_WINDOWS_950): ", stdout
);
426 strcpy(legsrc
, legdest
);
428 len
= cupsCharsetToUTF8(utf8dest
, legsrc
, 1024, CUPS_WINDOWS_950
);
429 if (len
!= strlen((char *)utf8taiwan
))
431 printf("FAIL (len=%d, expected %d)\n", len
, (int)strlen((char *)utf8taiwan
));
432 print_utf8(" utf8taiwan", utf8taiwan
);
433 print_utf8(" utf8dest", utf8dest
);
436 else if (memcmp(utf8taiwan
, utf8dest
, len
))
438 puts("FAIL (results do not match)");
439 print_utf8(" utf8taiwan", utf8taiwan
);
440 print_utf8(" utf8dest", utf8dest
);
447 * Test UTF-8 to/from legacy charset (EUC-TW)...
450 fputs("cupsUTF8ToCharset(CUPS_EUC_TW): ", stdout
);
452 if (cupsUTF8ToCharset(legdest
, utf8taiwan
, 1024, CUPS_EUC_TW
) < 0)
459 for (legptr
= legdest
; *legptr
&& *legptr
!= '?'; legptr
++);
463 puts("FAIL (unknown character)");
470 fputs("cupsCharsetToUTF8(CUPS_EUC_TW): ", stdout
);
472 strcpy(legsrc
, legdest
);
474 len
= cupsCharsetToUTF8(utf8dest
, legsrc
, 1024, CUPS_EUC_TW
);
475 if (len
!= strlen((char *)utf8taiwan
))
477 printf("FAIL (len=%d, expected %d)\n", len
, (int)strlen((char *)utf8taiwan
));
478 print_utf8(" utf8taiwan", utf8taiwan
);
479 print_utf8(" utf8dest", utf8dest
);
482 else if (memcmp(utf8taiwan
, utf8dest
, len
))
484 puts("FAIL (results do not match)");
485 print_utf8(" utf8taiwan", utf8taiwan
);
486 print_utf8(" utf8dest", utf8dest
);
494 * Test UTF-8 (16-bit) to UTF-32 (w/ BOM)...
497 printf("\ntesti18n: Testing UTF-8 to UTF-32 (w/ BOM)...\n");
498 len
= cupsUTF8ToUTF32(utf32dest
, utf8good
, 1024);
503 print_utf8(" utf8good ", utf8good
);
504 print_utf32(" utf32dest", utf32dest
);
506 memcpy (utf32src
, utf32dest
, (len
+ 1) * sizeof(cups_utf32_t
));
507 len
= cupsUTF32ToUTF8(utf8dest
, utf32src
, 1024);
510 if (len
!= strlen ((char *) utf8good
))
512 if (memcmp(utf8good
, utf8dest
, len
) != 0)
516 * Test invalid UTF-8 (16-bit) to UTF-32 (w/ BOM)...
519 printf("\ntesti18n: Testing UTF-8 bad 16-bit source string...\n");
520 len
= cupsUTF8ToUTF32(utf32dest
, utf8bad
, 1024);
524 print_utf8(" utf8bad ", utf8bad
);
527 * Test _cupsCharmapFlush()...
530 printf("\ntesti18n: Testing _cupsCharmapFlush()...\n");
540 * 'print_utf8()' - Print UTF-8 string with (optional) message.
544 print_utf8(const char *msg
, /* I - Message String */
545 const cups_utf8_t
*src
) /* I - UTF-8 Source String */
551 printf(" %02x", *src
);
558 * End of "$Id: testi18n.c 5837 2006-08-17 14:37:40Z mike $"