]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/testi18n.c
Load cups into easysw/current.
[thirdparty/cups.git] / cups / testi18n.c
index 8b0fbad2f6c5dd6470601f2579066cca01ed97e5..8392a65fe3a01a0c9f8f972f0aabd70cb30be847 100644 (file)
@@ -1,9 +1,9 @@
 /*
- * "$Id: testi18n.c 5195 2006-02-27 21:05:46Z mike $"
+ * "$Id: testi18n.c 5294 2006-03-15 21:09:32Z mike $"
  *
  *   Internationalization test for Common UNIX Printing System (CUPS).
  *
- *   Copyright 1997-2005 by Easy Software Products.
+ *   Copyright 1997-2006 by Easy Software Products.
  *
  *   These coded instructions, statements, and computer programs are
  *   the property of Easy Software Products and are protected by Federal
  *
  * Contents:
  *
- *   main()           - Main entry for internationalization test module.
- *   print_synopsis() - Print program synopsis (help).
- *   print_utf8()     - Print UTF-8 string with (optional) message.
- *   print_utf16()    - Print UTF-16 string with (optional) message.
- *   print_utf32()    - Print UTF-32 string with (optional) message.
- *   test_transcode() - Test 'transcode.c' module.
- *   test_normalize() - Test 'normalize.c' module.
+ *   main()        - Main entry for internationalization test module.
+ *   print_utf8()  - Print UTF-8 string with (optional) message.
+ *   print_utf32() - Print UTF-32 string with (optional) message.
  */
 
 /*
 #include <errno.h>
 #include <time.h>
 
-#include "language.h"
+#include "i18n.h"
 #include "string.h"
-#include "transcode.h"
-#include "normalize.h"
-
-
-/*
- * Local Globals...
- */
-
-static const char *program_synopsis[] = /* Program help */
-{
-  "testi18n [-vh]",
-  "         -v  verbose (print each called function and result)",
-  "         -h  help (print this synopsis)",
-  "",
-  "'testi18n' is a utility to test CUPS internationalization",
-  "Copyright 1997-2005 by Easy Software Products.",
-  NULL
-};
-static int     error_count = 0;        /* Total error count */
 
 
 /*
  * Local functions...
  */
 
-static void    print_synopsis(void);
 static void    print_utf8(const char *msg, const cups_utf8_t *src);
-static void    print_utf16(const char *msg, const cups_utf16_t *src);
 static void    print_utf32(const char *msg, const cups_utf32_t *src);
-static int     test_transcode(const int verbose);
-static int     test_normalize(const int verbose);
 
 
 /*
@@ -83,140 +56,16 @@ static int test_normalize(const int verbose);
 int                                    /* O - Exit code */
 main(int  argc,                                /* I - Argument Count */
      char *argv[])                     /* I - Arguments */
-{
-  int          ai;                     /* Argument index */
-  char         *ap;                    /* Argument pointer */
-  int          verbose;                /* Verbose flag */
-  int          errors;                 /* Error count */
-
-
- /*
-  * Check for switches...
-  */
-
-  verbose = 0;
-
-  for (ai = 1; ai < argc; ai ++)
-  {
-    ap = argv[ai];
-    if (*ap != '-')
-      break;
-
-    for (ap ++; *ap != '\0'; ap ++)
-    {
-      switch (*ap)
-      {
-       case 'v':                       /* verbose */
-         verbose = 1;
-         break;
-
-       case 'h':                       /* help */
-         print_synopsis();
-         return (0);
-
-       default:
-         print_synopsis();
-         return (1);
-      }
-    }
-  }
-
- /*
-  * Test all internationalization modules and functions...
-  */
-
-  errors = test_transcode(verbose);
-  error_count += errors;
-  printf("\ntesti18n: %d errors found in 'transcode.c'\n", errors);
-
-  errors = test_normalize(verbose);
-  error_count += errors;
-  printf("\ntesti18n: %d errors found in 'normalize.c'\n", errors);
-
-  return (error_count > 0);
-}
-
-
-/*
- * 'print_synopsis()' - Print program synopsis (help).
- */
-
-static void
-print_synopsis(void)
-{
-  int  i;                              /* Looping variable */
-
-
-  for (i = 0; program_synopsis[i]; i ++)
-    puts(program_synopsis[i]);
-}
-
-
-/*
- * 'print_utf8()' - Print UTF-8 string with (optional) message.
- */
-
-static void
-print_utf8(const char       *msg,      /* I - Message String */
-          const cups_utf8_t *src)      /* I - UTF-8 Source String */
-{
-  if (msg != NULL)
-    printf("%s:", msg);
-
-  for (; *src; src ++)
-    printf(" %02x", *src);
-  printf("\n");
-  return;
-}
-
-
-/*
- * 'print_utf16()' - Print UTF-16 string with (optional) message.
- */
-
-static void
-print_utf16(const char        *msg,    /* I - Message String */
-           const cups_utf16_t *src)    /* I - UTF-16 Source String */
-{
-  if (msg != NULL)
-    printf("%s:", msg);
-  for (; *src; src ++)
-    printf(" %04x", (int) *src);
-  printf("\n");
-  return;
-}
-
-
-/*
- * 'print_utf32()' - Print UTF-32 string with (optional) message.
- */
-
-static void
-print_utf32(const char        *msg,    /* I - Message String */
-           const cups_utf32_t *src)    /* I - UTF-32 Source String */
-{
-  if (msg != NULL)
-    printf("%s:", msg);
-  for (; *src; src ++)
-    printf(" %04x", (int) *src);
-  printf("\n");
-  return;
-}
-
-
-/*
- * 'test_transcode()' - Test 'transcode.c' module.
- */
-
-static int                             /* O - Zero or error count */
-test_transcode(const int verbose)      /* I - Verbose flag */
 {
   FILE         *fp;                    /* File pointer */
   int          count;                  /* File line counter */
+  int          status,                 /* Status of current test */
+               errors;                 /* Error count */
   char         line[1024];             /* File line source string */
   int          len;                    /* Length (count) of string */
-  char         legsrc[1024];           /* Legacy source string */
-  char         legdest[1024];          /* Legacy destination string */
+  char         legsrc[1024],           /* Legacy source string */
+               legdest[1024],          /* Legacy destination string */
+               *legptr;                /* Pointer into legacy string */
   cups_utf8_t  utf8latin[] =           /* UTF-8 Latin-1 source */
     { 0x41, 0x20, 0x21, 0x3D, 0x20, 0xC3, 0x84, 0x2E, 0x00 };
     /* "A != <A WITH DIAERESIS>." - use ISO 8859-1 */
@@ -225,7 +74,7 @@ test_transcode(const int verbose)    /* I - Verbose flag */
     /* "A <NOT IDENTICAL TO> <A WITH DIAERESIS>." */
   cups_utf8_t  utf8greek[] =           /* UTF-8 Greek source string */
     { 0x41, 0x20, 0x21, 0x3D, 0x20, 0xCE, 0x91, 0x2E, 0x00 };
-    /* "A != <ALHPA>." - use ISO 8859-7 */
+    /* "A != <ALPHA>." - use ISO 8859-7 */
   cups_utf8_t  utf8japan[] =           /* UTF-8 Japanese source */
     { 0x41, 0x20, 0x21, 0x3D, 0x20, 0xEE, 0x9C, 0x80, 0x2E, 0x00 };
     /* "A != <PRIVATE U+E700>." - use Windows 932 or EUC-JP */
@@ -239,256 +88,407 @@ test_transcode(const int verbose)        /* I - Verbose flag */
     { 0x41, 0x20, 0xE2, 0x89, 0xA2, 0x20, 0xF8, 0x84, 0x2E, 0x00 };
     /* "A <NOT IDENTICAL TO> <...bad stuff...>." */
   cups_utf8_t  utf8dest[1024];         /* UTF-8 destination string */
-  cups_utf16_t utf16sur[] =            /* UTF-16 with surrogates */
-    { 0xD800, 0xDC00, 0x20, 0x21, 0x3D, 0x20, 0xC4, 0x2E, 0x00 };
-    /* "<Surrogate pair> != <A WITH DIAERESIS>." */
-  cups_utf16_t utf16src[1024];         /* UTF-16 source string */
-  cups_utf16_t utf16dest[1024];        /* UTF-16 destination string */
   cups_utf32_t utf32src[1024];         /* UTF-32 source string */
   cups_utf32_t utf32dest[1024];        /* UTF-32 destination string */
-  _cups_vmap_t  *vmap;                  /* VBCS charmap pointer */
+  _cups_vmap_t  *vmap;                 /* VBCS charmap pointer */
 
 
  /*
-  * Test with (inserted) and (deleted) leading BOM...
+  * Start with some conversion tests from a UTF-8 test file.
   */
 
-  if (verbose)
+  errors = 0;
+
+  if ((fp = fopen("utf8demo.txt", "r")) == NULL)
   {
-    printf("\ntesti18n: Testing 'transcode.c'...\n");
-    printf(" testing with insert/delete leading BOM...\n");
+    perror("utf8demo.txt");
+    return (1);
   }
 
  /*
-  * Test UTF-8 to UTF-32/EUC-JP on demo file...
+  * cupsUTF8ToUTF32
   */
 
-  if (verbose)
+  fputs("cupsUTF8ToUTF32 of utfdemo.txt: ", stdout);
+
+  for (count = 0, status = 0; fgets(line, sizeof(line), fp);)
   {
-    printf("\ntesti18n: Testing UTF-8 source 'utf8demo.txt'...\n");
-    printf(" testing UTF-8 to UTF-32...\n");
-    printf(" testing UTF-8 to EUC-JP...\n");
+    count ++;
+
+    if (cupsUTF8ToUTF32(utf32dest, (cups_utf8_t *)line, 1024) < 0)
+    {
+      printf("FAIL (UTF-8 to UTF-32 on line %d)\n", count);
+      errors ++;
+      status = 1;
+      break;
+    }
   }
 
-  if ((fp = fopen("utf8demo.txt", "r")) == NULL)
-    return (1);
+  if (!status)
+    puts("PASS");
 
-  for (count = 0;;)
-  {
-    if (fgets(line, 1024, fp) == NULL)
-      break;
+ /*
+  * cupsUTF8ToCharset(CUPS_EUC_JP)
+  */
 
-    count ++;
+  fputs("cupsUTF8ToCharset(CUPS_EUC_JP) of utfdemo.txt: ", stdout);
 
-    len = cupsUTF8ToUTF32(utf32dest, (cups_utf8_t *)line, 1024);
-    if (len < 0)
-      printf(" error line: %d (UTF-8 to UTF-32)\n", count);
+  rewind(fp);
+
+  for (count = 0, status = 0; fgets(line, sizeof(line), fp);)
+  {
+    count ++;
 
     len = cupsUTF8ToCharset(legdest, (cups_utf8_t *)line, 1024, CUPS_EUC_JP);
     if (len < 0)
-      printf(" error line: %d (UTF-8 to EUC-JP)\n", count);
+    {
+      printf("FAIL (UTF-8 to EUC-JP on line %d)\n", count);
+      errors ++;
+      status = 1;
+      break;
+    }
   }
 
+  if (!status)
+    puts("PASS");
+
   fclose(fp);
 
-  if (verbose)
-    printf(" total lines: %d\n", count);
+ /*
+  * Test charmap load for ISO-8859-1...
+  */
+
+  fputs("_cupsCharmapGet(CUPS_ISO8859_1): ", stdout);
+
+  if (!_cupsCharmapGet(CUPS_ISO8859_1))
+  {
+    errors ++;
+    puts("FAIL");
+  }
+  else
+    puts("PASS");
 
  /*
-  * Test VBCS charmap load for EUC-JP...
+  * Test charmap load for Windows-932 (Shift-JIS)...
   */
 
-  if (verbose)
-    printf("\ntesti18n: Loading VBCS charmap EUC-JP (Japanese)...\n");
+  fputs("_cupsCharmapGet(CUPS_WINDOWS_932): ", stdout);
 
-  vmap = (_cups_vmap_t *) cupsCharmapGet(CUPS_EUC_JP);
-  if (vmap == NULL)
-    return (1);
+  if (!_cupsCharmapGet(CUPS_WINDOWS_932))
+  {
+    errors ++;
+    puts("FAIL");
+  }
+  else
+    puts("PASS");
 
-  if (verbose)
+ /*
+  * Test VBCS charmap load for EUC-JP...
+  */
+
+  fputs("_cupsCharmapGet(CUPS_EUC_JP): ", stdout);
+
+  if ((vmap = (_cups_vmap_t *)_cupsCharmapGet(CUPS_EUC_JP)) == NULL)
   {
-    printf(" charcount: %d\n", vmap->charcount);
-    printf(" widecount: %d\n", vmap->widecount);
+    errors ++;
+    puts("FAIL");
   }
+  else
+    puts("PASS");
 
  /*
   * Test VBCS charmap load for EUC-TW...
   */
 
-  if (verbose)
-    printf("\ntesti18n: Loading VBCS charmap EUC-TW (Taiwan)...\n");
-
-  vmap = (_cups_vmap_t *) cupsCharmapGet(CUPS_EUC_TW);
-  if (vmap == NULL)
-    return (1);
+  fputs("_cupsCharmapGet(CUPS_EUC_TW): ", stdout);
 
-  if (verbose)
+  if ((vmap = (_cups_vmap_t *)_cupsCharmapGet(CUPS_EUC_TW)) == NULL)
   {
-    printf(" charcount: %d\n", vmap->charcount);
-    printf(" widecount: %d\n", vmap->widecount);
+    errors ++;
+    puts("FAIL");
   }
+  else
+    puts("PASS");
 
  /*
   * Test UTF-8 to legacy charset (ISO 8859-1)...
   */
 
-  if (verbose)
-    printf("\ntesti18n: Testing UTF-8 to ISO 8859-1 (Latin1)...\n");
+  fputs("cupsUTF8ToCharset(CUPS_ISO8859_1): ", stdout);
 
   legdest[0] = 0;
 
   len = cupsUTF8ToCharset(legdest, utf8latin, 1024, CUPS_ISO8859_1);
   if (len < 0)
-    return (1);
-
-  if (verbose)
   {
-    print_utf8(" utf8latin", utf8latin);
-    print_utf8(" legdest  ", (cups_utf8_t *) legdest);
+    printf("FAIL (len=%d)\n", len);
+    errors ++;
   }
+  else
+    puts("PASS");
 
-  strcpy(legsrc, legdest);
-
-  len = cupsCharsetToUTF8(utf8dest, legsrc, 1024, CUPS_ISO8859_1);
-
-  if (len < 0)
-    return (1);
+ /*
+  * cupsCharsetToUTF8
+  */
 
-  if (len != strlen ((char *) utf8latin))
-    return (1);
+  fputs("cupsCharsetToUTF8(CUPS_ISO8859_1): ", stdout);
 
-  if (memcmp(utf8latin, utf8dest, len) != 0)
-    return (1);
+  strcpy(legsrc, legdest);
 
- /*
-  * Test UTF-8 to Latin-1 (ISO 8859-1) with replacement...
-  */
-  if (verbose)
-    printf("\ntesti18n: Testing UTF-8 to ISO 8859-1 w/ replace...\n");
-  len = cupsUTF8ToCharset(legdest, utf8repla, 1024, CUPS_ISO8859_1);
-  if (len < 0)
-    return (1);
-  if (verbose)
+  len = cupsCharsetToUTF8(utf8dest, legsrc, 1024, CUPS_ISO8859_1);
+  if (len != strlen((char *)utf8latin))
+  {
+    printf("FAIL (len=%d, expected %d)\n", len, strlen((char *)utf8latin));
+    print_utf8("    utf8latin", utf8latin);
+    print_utf8("    utf8dest", utf8dest);
+    errors ++;
+  }
+  else if (memcmp(utf8latin, utf8dest, len))
   {
-    print_utf8(" utf8repla", utf8repla);
-    print_utf8(" legdest  ", (cups_utf8_t *) legdest);
+    puts("FAIL (results do not match)");
+    print_utf8("    utf8latin", utf8latin);
+    print_utf8("    utf8dest", utf8dest);
+    errors ++;
   }
+  else if (cupsUTF8ToCharset(legdest, utf8repla, 1024, CUPS_ISO8859_1) < 0)
+  {
+    puts("FAIL (replacement characters do not work!)");
+    errors ++;
+  }
+  else
+    puts("PASS");
 
  /*
-  * Test UTF-8 to legacy charset (ISO 8859-7)...
+  * Test UTF-8 to/from legacy charset (ISO 8859-7)...
   */
-  if (verbose)
-    printf("\ntesti18n: Testing UTF-8 to ISO 8859-7 (Greek)...\n");
-  legdest[0] = 0;
-  len = cupsUTF8ToCharset(legdest, utf8greek, 1024, CUPS_ISO8859_7);
-  if (len < 0)
-    return (1);
-  if (verbose)
+
+  fputs("cupsUTF8ToCharset(CUPS_ISO8859_7): ", stdout);
+
+  if (cupsUTF8ToCharset(legdest, utf8greek, 1024, CUPS_ISO8859_7) < 0)
   {
-    print_utf8(" utf8greek", utf8greek);
-    print_utf8(" legdest  ", (cups_utf8_t *) legdest);
+    puts("FAIL");
+    errors ++;
   }
+  else
+  {
+    for (legptr = legdest; *legptr && *legptr != '?'; legptr ++);
+
+    if (*legptr)
+    {
+      puts("FAIL (unknown character)");
+      errors ++;
+    }
+    else
+      puts("PASS");
+  }
+
+  fputs("cupsCharsetToUTF8(CUPS_ISO8859_7): ", stdout);
+
   strcpy(legsrc, legdest);
+
   len = cupsCharsetToUTF8(utf8dest, legsrc, 1024, CUPS_ISO8859_7);
-  if (len < 0)
-    return (1);
-  if (len != strlen ((char *) utf8greek))
-    return (1);
-  if (memcmp(utf8greek, utf8dest, len) != 0)
-    return (1);
+  if (len != strlen((char *)utf8greek))
+  {
+    printf("FAIL (len=%d, expected %d)\n", len, strlen((char *)utf8greek));
+    print_utf8("    utf8greek", utf8greek);
+    print_utf8("    utf8dest", utf8dest);
+    errors ++;
+  }
+  else if (memcmp(utf8greek, utf8dest, len))
+  {
+    puts("FAIL (results do not match)");
+    print_utf8("    utf8greek", utf8greek);
+    print_utf8("    utf8dest", utf8dest);
+    errors ++;
+  }
+  else
+    puts("PASS");
 
  /*
-  * Test UTF-8 to legacy charset (Windows 932)...
+  * Test UTF-8 to/from legacy charset (Windows 932)...
   */
-  if (verbose)
-    printf("\ntesti18n: Testing UTF-8 to Windows 932 (Japanese)...\n");
-  legdest[0] = 0;
-  len = cupsUTF8ToCharset(legdest, utf8japan, 1024, CUPS_WINDOWS_932);
-  if (len < 0)
-    return (1);
-  if (verbose)
+
+  fputs("cupsUTF8ToCharset(CUPS_WINDOWS_932): ", stdout);
+
+  if (cupsUTF8ToCharset(legdest, utf8japan, 1024, CUPS_WINDOWS_932) < 0)
   {
-    print_utf8(" utf8japan", utf8japan);
-    print_utf8(" legdest  ", (cups_utf8_t *) legdest);
+    puts("FAIL");
+    errors ++;
   }
+  else
+  {
+    for (legptr = legdest; *legptr && *legptr != '?'; legptr ++);
+
+    if (*legptr)
+    {
+      puts("FAIL (unknown character)");
+      errors ++;
+    }
+    else
+      puts("PASS");
+  }
+
+  fputs("cupsCharsetToUTF8(CUPS_WINDOWS_932): ", stdout);
+
   strcpy(legsrc, legdest);
+
   len = cupsCharsetToUTF8(utf8dest, legsrc, 1024, CUPS_WINDOWS_932);
-  if (len < 0)
-    return (1);
-  if (len != strlen ((char *) utf8japan))
-    return (1);
-  if (memcmp(utf8japan, utf8dest, len) != 0)
-    return (1);
+  if (len != strlen((char *)utf8japan))
+  {
+    printf("FAIL (len=%d, expected %d)\n", len, strlen((char *)utf8japan));
+    print_utf8("    utf8japan", utf8japan);
+    print_utf8("    utf8dest", utf8dest);
+    errors ++;
+  }
+  else if (memcmp(utf8japan, utf8dest, len))
+  {
+    puts("FAIL (results do not match)");
+    print_utf8("    utf8japan", utf8japan);
+    print_utf8("    utf8dest", utf8dest);
+    errors ++;
+  }
+  else
+    puts("PASS");
 
  /*
-  * Test UTF-8 to legacy charset (EUC-JP)...
+  * Test UTF-8 to/from legacy charset (EUC-JP)...
   */
-  if (verbose)
-    printf("\ntesti18n: Testing UTF-8 to EUC-JP (Japanese)...\n");
-  legdest[0] = 0;
-  len = cupsUTF8ToCharset(legdest, utf8japan, 1024, CUPS_EUC_JP);
-  if (len < 0)
-    return (1);
-  if (verbose)
+
+  fputs("cupsUTF8ToCharset(CUPS_EUC_JP): ", stdout);
+
+  if (cupsUTF8ToCharset(legdest, utf8japan, 1024, CUPS_EUC_JP) < 0)
   {
-    print_utf8(" utf8japan", utf8japan);
-    print_utf8(" legdest  ", (cups_utf8_t *) legdest);
+    puts("FAIL");
+    errors ++;
   }
+  else
+  {
+    for (legptr = legdest; *legptr && *legptr != '?'; legptr ++);
+
+    if (*legptr)
+    {
+      puts("FAIL (unknown character)");
+      errors ++;
+    }
+    else
+      puts("PASS");
+  }
+
+  fputs("cupsCharsetToUTF8(CUPS_EUC_JP): ", stdout);
+
   strcpy(legsrc, legdest);
+
   len = cupsCharsetToUTF8(utf8dest, legsrc, 1024, CUPS_EUC_JP);
-  if (len < 0)
-    return (1);
-  if (len != strlen ((char *) utf8japan))
-    return (1);
-  if (memcmp(utf8japan, utf8dest, len) != 0)
-    return (1);
+  if (len != strlen((char *)utf8japan))
+  {
+    printf("FAIL (len=%d, expected %d)\n", len, strlen((char *)utf8japan));
+    print_utf8("    utf8japan", utf8japan);
+    print_utf8("    utf8dest", utf8dest);
+    errors ++;
+  }
+  else if (memcmp(utf8japan, utf8dest, len))
+  {
+    puts("FAIL (results do not match)");
+    print_utf8("    utf8japan", utf8japan);
+    print_utf8("    utf8dest", utf8dest);
+    errors ++;
+  }
+  else
+    puts("PASS");
 
  /*
-  * Test UTF-8 to legacy charset (Windows 950)...
+  * Test UTF-8 to/from legacy charset (Windows 950)...
   */
-  if (verbose)
-    printf("\ntesti18n: Testing UTF-8 to Windows 950 (Chinese)...\n");
-  legdest[0] = 0;
-  len = cupsUTF8ToCharset(legdest, utf8taiwan, 1024, CUPS_WINDOWS_950);
-  if (len < 0)
-    return (1);
-  if (verbose)
+
+  fputs("cupsUTF8ToCharset(CUPS_WINDOWS_950): ", stdout);
+
+  if (cupsUTF8ToCharset(legdest, utf8taiwan, 1024, CUPS_WINDOWS_950) < 0)
+  {
+    puts("FAIL");
+    errors ++;
+  }
+  else
   {
-    print_utf8(" utf8taiwan", utf8taiwan);
-    print_utf8(" legdest   ", (cups_utf8_t *) legdest);
+    for (legptr = legdest; *legptr && *legptr != '?'; legptr ++);
+
+    if (*legptr)
+    {
+      puts("FAIL (unknown character)");
+      errors ++;
+    }
+    else
+      puts("PASS");
   }
+
+  fputs("cupsCharsetToUTF8(CUPS_WINDOWS_950): ", stdout);
+
   strcpy(legsrc, legdest);
+
   len = cupsCharsetToUTF8(utf8dest, legsrc, 1024, CUPS_WINDOWS_950);
-  if (len < 0)
-    return (1);
-  if (len != strlen ((char *) utf8taiwan))
-    return (1);
-  if (memcmp(utf8taiwan, utf8dest, len) != 0)
-    return (1);
+  if (len != strlen((char *)utf8taiwan))
+  {
+    printf("FAIL (len=%d, expected %d)\n", len, strlen((char *)utf8taiwan));
+    print_utf8("    utf8taiwan", utf8taiwan);
+    print_utf8("    utf8dest", utf8dest);
+    errors ++;
+  }
+  else if (memcmp(utf8taiwan, utf8dest, len))
+  {
+    puts("FAIL (results do not match)");
+    print_utf8("    utf8taiwan", utf8taiwan);
+    print_utf8("    utf8dest", utf8dest);
+    errors ++;
+  }
+  else
+    puts("PASS");
 
  /*
-  * Test UTF-8 to legacy charset (EUC-TW)...
+  * Test UTF-8 to/from legacy charset (EUC-TW)...
   */
-  if (verbose)
-    printf("\ntesti18n: Testing UTF-8 to EUC-TW (Chinese)...\n");
-  legdest[0] = 0;
-  len = cupsUTF8ToCharset(legdest, utf8taiwan, 1024, CUPS_EUC_TW);
-  if (len < 0)
-    return (1);
-  if (verbose)
+
+  fputs("cupsUTF8ToCharset(CUPS_EUC_TW): ", stdout);
+
+  if (cupsUTF8ToCharset(legdest, utf8taiwan, 1024, CUPS_EUC_TW) < 0)
+  {
+    puts("FAIL");
+    errors ++;
+  }
+  else
   {
-    print_utf8(" utf8taiwan", utf8taiwan);
-    print_utf8(" legdest   ", (cups_utf8_t *) legdest);
+    for (legptr = legdest; *legptr && *legptr != '?'; legptr ++);
+
+    if (*legptr)
+    {
+      puts("FAIL (unknown character)");
+      errors ++;
+    }
+    else
+      puts("PASS");
   }
+
+  fputs("cupsCharsetToUTF8(CUPS_EUC_TW): ", stdout);
+
   strcpy(legsrc, legdest);
+
   len = cupsCharsetToUTF8(utf8dest, legsrc, 1024, CUPS_EUC_TW);
-  if (len < 0)
-    return (1);
-  if (len != strlen ((char *) utf8taiwan))
-    return (1);
-  if (memcmp(utf8taiwan, utf8dest, len) != 0)
-    return (1);
+  if (len != strlen((char *)utf8taiwan))
+  {
+    printf("FAIL (len=%d, expected %d)\n", len, strlen((char *)utf8taiwan));
+    print_utf8("    utf8taiwan", utf8taiwan);
+    print_utf8("    utf8dest", utf8dest);
+    errors ++;
+  }
+  else if (memcmp(utf8taiwan, utf8dest, len))
+  {
+    puts("FAIL (results do not match)");
+    print_utf8("    utf8taiwan", utf8taiwan);
+    print_utf8("    utf8dest", utf8dest);
+    errors ++;
+  }
+  else
+    puts("PASS");
 
+#if 0
  /*
   * Test UTF-8 (16-bit) to UTF-32 (w/ BOM)...
   */
@@ -523,269 +523,54 @@ test_transcode(const int verbose)        /* I - Verbose flag */
     print_utf8(" utf8bad  ", utf8bad);
 
  /*
-  * Test UTF-8 (16-bit) to UTF-16 (w/ BOM)...
-  */
-  if (verbose)
-    printf("\ntesti18n: Testing UTF-8 to UTF-16 (w/ BOM)...\n");
-  len = cupsUTF8ToUTF16(utf16dest, utf8good, 1024);
-  if (len < 0)
-    return (1);
-  if (verbose)
-  {
-    print_utf8(" utf8good ", utf8good);
-    print_utf16(" utf16dest", utf16dest);
-  }
-  memcpy (utf16src, utf16dest, (len + 1) * sizeof(cups_utf16_t));
-  len = cupsUTF16ToUTF8(utf8dest, utf16src, 1024);
-  if (len < 0)
-    return (1);
-  if (len != strlen ((char *) utf8good))
-    return (1);
-  if (memcmp(utf8good, utf8dest, len) != 0)
-    return (1);
-
- /*
-  * Test UTF-16 to UTF-32 with surrogates...
+  * Test _cupsCharmapFlush()...
   */
   if (verbose)
-    printf("\ntesti18n: Testing UTF-16 to UTF-32 w/ surrogates...\n");
-  len = cupsUTF16ToUTF32(utf32dest, utf16sur, 1024);
-  if (len < 0)
-    return (1);
-  if (verbose)
-  {
-    print_utf16(" utf16sur ", utf16sur);
-    print_utf32(" utf32dest", utf32dest);
-  }
-
- /*
-  * Test cupsCharmapFlush()...
-  */
-  if (verbose)
-    printf("\ntesti18n: Testing cupsCharmapFlush()...\n");
-  cupsCharmapFlush();
+    printf("\ntesti18n: Testing _cupsCharmapFlush()...\n");
+  _cupsCharmapFlush();
   return (0);
+#endif /* 0 */
+
+  return (errors > 0);
 }
 
 
 /*
- * 'test_normalize()' - Test 'normalize.c' module.
+ * 'print_utf8()' - Print UTF-8 string with (optional) message.
  */
 
-static int                             /* O - Zero or error count */
-test_normalize(const int verbose)      /* I - Verbose flag */
+static void
+print_utf8(const char       *msg,      /* I - Message String */
+          const cups_utf8_t *src)      /* I - UTF-8 Source String */
 {
-  FILE         *fp;                    /* File pointer */
-  int          count;                  /* File line counter */
-  char         line[1024];             /* File line source string */
-  int          len;                    /* Length (count) of string */
-  int          diff;                   /* Difference of two strings */
-  int          prop;                   /* Property of a character */
-  int          i;                      /* Looping variable */
-  cups_utf32_t utf32char;              /* UTF-32 character */
-  cups_utf8_t  utf8src[1024];          /* UTF-8 source string */
-  cups_utf8_t  utf8dest[1024];         /* UTF-8 destination string */
-  cups_utf16_t utf16src[] =            /* UTF-16 non-normal source */
-    { 0x0149, 0x20, 0x21, 0x3D, 0x20, 0xC4, 0x2E, 0x00 };
-    /* "<SMALL N PRECEDED BY APOSTROPHE> != <A WITH DIAERESIS>." */
-  cups_utf16_t utf16dest[1024];        /* UTF-16 destination string */
-  cups_utf32_t utf32dest[1024];        /* UTF-32 destination string */
-
-  if (verbose)
-    printf("\ntesti18n: Testing 'normalize.c'...\n");
-
- /*
-  * Test UTF-8 to NFKD/NFC/Properties on demo file...
-  */
-  if (verbose)
-  {
-    printf("\ntesti18n: Testing UTF-8 source 'utf8demo.txt'...\n");
-    printf(" testing UTF-8 to NFKD...\n");
-    printf(" testing UTF-8 to NFC...\n");
-    printf(" testing UTF-8 to Character Properties...\n");
-  }
-  if ((fp = fopen("utf8demo.txt", "r")) == NULL)
-    return (1);
-  for (count = 0;;)
-  {
-    if (fgets(line, 1024, fp) == NULL)
-      break;
-    count ++;
-    len = cupsUTF8Normalize(utf8dest, (cups_utf8_t *)line, 1024, CUPS_NORM_NFKD);
-    if (len < 0)
-      printf(" error line: %d (UTF-8 to NFKD)\n", count);
-    len = cupsUTF8Normalize(utf8dest, (cups_utf8_t *)line, 1024, CUPS_NORM_NFC);
-    if (len < 0)
-      printf(" error line: %d (UTF-8 to NFC)\n", count);
-    len = cupsUTF8ToUTF32(utf32dest, (cups_utf8_t *)line, 1024);
-    if (len < 0)
-    {
-      printf(" error line: %d (UTF-8 to UTF-32)\n", count);
-      continue;
-    }
-    for (i = 0; i < len; i ++)
-    {
-      prop = cupsUTF32CharacterProperty(utf32dest[i],
-                                       CUPS_PROP_GENERAL_CATEGORY);
-      if (prop < 0)
-       printf(" error line: %d (Prop - General Category)\n", count);
-      prop = cupsUTF32CharacterProperty(utf32dest[i],
-                                       CUPS_PROP_BIDI_CATEGORY);
-      if (prop < 0)
-       printf(" error line: %d (Prop - Bidi Category)\n", count);
-      prop = cupsUTF32CharacterProperty(utf32dest[i],
-                                       CUPS_PROP_COMBINING_CLASS);
-      if (prop < 0)
-       printf(" error line: %d (Prop - Combining Class)\n", count);
-      prop = cupsUTF32CharacterProperty(utf32dest[i],
-                                       CUPS_PROP_BREAK_CLASS);
-      if (prop < 0)
-       printf(" error line: %d (Prop - Break Class)\n", count);
-    }
-  }
-  fclose(fp);
-  if (verbose)
-    printf(" total lines: %d\n", count);
-
- /*
-  * Test UTF-8 normalization NFKD...
-  */
-  if (verbose)
-    printf("\ntesti18n: Testing UTF-8 normalization NFKD...\n");
-  len = cupsUTF16ToUTF8(utf8dest, utf16src, 1024);
-  if (len < 0)
-    return (1);
-  strcpy((char *) utf8src, (char *) utf8dest);
-  len = cupsUTF8Normalize(utf8dest, utf8src, 1024, CUPS_NORM_NFKD);
-  if (len < 0)
-    return (1);
-  len = cupsUTF8ToUTF16(utf16dest, utf8dest, 1024);
-  if (len < 0)
-    return (1);
-  if (verbose)
-  {
-    print_utf16(" utf16src ", utf16src);
-    print_utf16(" utf16dest", utf16dest);
-  }
+  if (msg)
+    printf("%s:", msg);
 
- /*
-  * Test UTF-8 normalization NFD...
-  */
-  if (verbose)
-    printf("\ntesti18n: Testing UTF-8 normalization NFD...\n");
-  len = cupsUTF8Normalize(utf8dest, utf8src, 1024, CUPS_NORM_NFD);
-  if (len < 0)
-    return (1);
-  len = cupsUTF8ToUTF16(utf16dest, utf8dest, 1024);
-  if (len < 0)
-    return (1);
-  if (verbose)
-  {
-    print_utf16(" utf16src ", utf16src);
-    print_utf16(" utf16dest", utf16dest);
-  }
+  for (; *src; src ++)
+    printf(" %02x", *src);
 
- /*
-  * Test UTF-8 normalization NFC...
-  */
-  if (verbose)
-    printf("\ntesti18n: Testing UTF-8 normalization NFC...\n");
-  len = cupsUTF8Normalize(utf8dest, utf8src, 1024, CUPS_NORM_NFC);
-  if (len < 0)
-    return (1);
-  len = cupsUTF8ToUTF16(utf16dest, utf8dest, 1024);
-  if (len < 0)
-    return (1);
-  if (verbose)
-  {
-    print_utf16(" utf16src ", utf16src);
-    print_utf16(" utf16dest", utf16dest);
-  }
+  putchar('\n');
+}
 
- /*
-  * Test UTF-8 simple case folding...
-  */
-  if (verbose)
-    printf("\ntesti18n: Testing UTF-8 simple case folding...\n");
-  len = cupsUTF8CaseFold(utf8dest, utf8src, 1024, CUPS_FOLD_SIMPLE);
-  if (len < 0)
-    return (1);
-  len = cupsUTF8ToUTF16(utf16dest, utf8dest, 1024);
-  if (len < 0)
-    return (1);
-  if (verbose)
-  {
-    print_utf16(" utf16src ", utf16src);
-    print_utf16(" utf16dest", utf16dest);
-  }
 
- /*
-  * Test UTF-8 full case folding...
-  */
-  if (verbose)
-    printf("\ntesti18n: Testing UTF-8 full case folding...\n");
-  len = cupsUTF8CaseFold(utf8dest, utf8src, 1024, CUPS_FOLD_FULL);
-  if (len < 0)
-    return (1);
-  len = cupsUTF8ToUTF16(utf16dest, utf8dest, 1024);
-  if (len < 0)
-    return (1);
-  if (verbose)
-  {
-    print_utf16(" utf16src ", utf16src);
-    print_utf16(" utf16dest", utf16dest);
-  }
+/*
+ * 'print_utf32()' - Print UTF-32 string with (optional) message.
+ */
 
- /*
-  * Test UTF-8 caseless comparison...
-  */
-  if (verbose)
-    printf("\ntesti18n: Testing UTF-8 caseless comparison..\n");
-  diff = cupsUTF8CompareCaseless(utf8src, utf8dest);
-  if (verbose)
-    printf(" diff: %d\n", diff);
-  if (verbose)
-    printf("\ntesti18n: Testing UTF-8 identifier comparison..\n");
-  diff = cupsUTF8CompareIdentifier(utf8src, utf8dest);
-  if (verbose)
-    printf(" diff: %d\n", diff);
+static void
+print_utf32(const char        *msg,    /* I - Message String */
+           const cups_utf32_t *src)    /* I - UTF-32 Source String */
+{
+  if (msg)
+    printf("%s:", msg);
 
- /*
-  * Test UTF-32 character properties...
-  */
-  if (verbose)
-    printf("\ntesti18n: Testing UTF-32 character properties..\n");
-  utf32char = 0x02B0;
-  prop = cupsUTF32CharacterProperty (utf32char,
-    CUPS_PROP_GENERAL_CATEGORY);
-  if (verbose)
-    printf(" utf32char: %04lx  general category %d\n", utf32char, prop);
-  utf32char = 0x0621;
-  prop = cupsUTF32CharacterProperty (utf32char,
-    CUPS_PROP_BIDI_CATEGORY);
-  if (verbose)
-    printf(" utf32char: %04lx  bidi category   %d\n", utf32char, prop);
-  utf32char = 0x0308;
-  prop = cupsUTF32CharacterProperty (utf32char,
-    CUPS_PROP_COMBINING_CLASS);
-  if (verbose)
-    printf(" utf32char: %04lx  combining class %d\n", utf32char, prop);
-  utf32char = 0x0009;
-  prop = cupsUTF32CharacterProperty (utf32char,
-    CUPS_PROP_BREAK_CLASS);
-  if (verbose)
-    printf(" utf32char: %04lx  break class     %d\n", utf32char, prop);
+  for (; *src; src ++)
+    printf(" %04x", (int) *src);
 
- /*
-  * Test cupsNormalizeMapsFlush()...
-  */
-  if (verbose)
-    printf("\ntesti18n: Testing cupsNormalizeMapsFlush()...\n");
-  cupsNormalizeMapsFlush();
-  return (0);
+  putchar('\n');
 }
 
 
 /*
- * End of "$Id: testi18n.c 5195 2006-02-27 21:05:46Z mike $"
+ * End of "$Id: testi18n.c 5294 2006-03-15 21:09:32Z mike $"
  */