]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/testi18n.c
Remove all of the Subversion keywords from various source files.
[thirdparty/cups.git] / cups / testi18n.c
index 80fc9f6a5c91bb7f6d64b5a94a1d4834ee6d002e..a88f1e1f4544508f47068f8f96837ff05f4f6ec2 100644 (file)
 /*
- * "$Id: testi18n.c 5837 2006-08-17 14:37:40Z mike $"
+ * Internationalization test for CUPS.
  *
- *   Internationalization test for Common UNIX Printing System (CUPS).
+ * Copyright 2007-2014 by Apple Inc.
+ * Copyright 1997-2006 by Easy Software Products.
  *
- *   Copyright 1997-2006 by Easy Software Products.
+ * These coded instructions, statements, and computer programs are the
+ * property of Apple Inc. and are protected by Federal copyright
+ * law.  Distribution and use rights are outlined in the file "LICENSE.txt"
+ * which should have been included with this file.  If this file is
+ * file is missing or damaged, see the license at "http://www.cups.org/".
  *
- *   These coded instructions, statements, and computer programs are
- *   the property of Easy Software Products and are protected by Federal
- *   copyright law.  Distribution and use rights are outlined in the
- *   file "LICENSE.txt" which should have been included with this file.
- *   If this file is missing or damaged please contact Easy Software
- *   Products at:
- *
- *       Attn: CUPS Licensing Information
- *       Easy Software Products
- *       44141 Airport View Drive, Suite 204
- *       Hollywood, Maryland 20636 USA
- *
- *       Voice: (301) 373-9600
- *       EMail: cups-info@cups.org
- *         WWW: http://www.cups.org
- *
- * Contents:
- *
- *   main()       - Main entry for internationalization test module.
- *   print_utf8() - Print UTF-8 string with (optional) message.
+ * This file is subject to the Apple OS-Developed Software exception.
  */
 
 /*
  * Include necessary headers...
  */
 
-#include <stdio.h>
+#include "string-private.h"
+#include "language-private.h"
 #include <stdlib.h>
-#include <errno.h>
 #include <time.h>
 #include <unistd.h>
 
-#include "i18n.h"
-#include "string.h"
+
+/*
+ * Local globals...
+ */
+
+static const char * const lang_encodings[] =
+                       {               /* Encoding strings */
+                         "us-ascii",           "iso-8859-1",
+                         "iso-8859-2",         "iso-8859-3",
+                         "iso-8859-4",         "iso-8859-5",
+                         "iso-8859-6",         "iso-8859-7",
+                         "iso-8859-8",         "iso-8859-9",
+                         "iso-8859-10",        "utf-8",
+                         "iso-8859-13",        "iso-8859-14",
+                         "iso-8859-15",        "windows-874",
+                         "windows-1250",       "windows-1251",
+                         "windows-1252",       "windows-1253",
+                         "windows-1254",       "windows-1255",
+                         "windows-1256",       "windows-1257",
+                         "windows-1258",       "koi8-r",
+                         "koi8-u",             "iso-8859-11",
+                         "iso-8859-16",        "mac-roman",
+                         "unknown",            "unknown",
+                         "unknown",            "unknown",
+                         "unknown",            "unknown",
+                         "unknown",            "unknown",
+                         "unknown",            "unknown",
+                         "unknown",            "unknown",
+                         "unknown",            "unknown",
+                         "unknown",            "unknown",
+                         "unknown",            "unknown",
+                         "unknown",            "unknown",
+                         "unknown",            "unknown",
+                         "unknown",            "unknown",
+                         "unknown",            "unknown",
+                         "unknown",            "unknown",
+                         "unknown",            "unknown",
+                         "unknown",            "unknown",
+                         "unknown",            "unknown",
+                         "windows-932",        "windows-936",
+                         "windows-949",        "windows-950",
+                         "windows-1361",       "unknown",
+                         "unknown",            "unknown",
+                         "unknown",            "unknown",
+                         "unknown",            "unknown",
+                         "unknown",            "unknown",
+                         "unknown",            "unknown",
+                         "unknown",            "unknown",
+                         "unknown",            "unknown",
+                         "unknown",            "unknown",
+                         "unknown",            "unknown",
+                         "unknown",            "unknown",
+                         "unknown",            "unknown",
+                         "unknown",            "unknown",
+                         "unknown",            "unknown",
+                         "unknown",            "unknown",
+                         "unknown",            "unknown",
+                         "unknown",            "unknown",
+                         "unknown",            "unknown",
+                         "unknown",            "unknown",
+                         "unknown",            "unknown",
+                         "unknown",            "unknown",
+                         "unknown",            "unknown",
+                         "unknown",            "unknown",
+                         "unknown",            "unknown",
+                         "unknown",            "unknown",
+                         "unknown",            "unknown",
+                         "unknown",            "unknown",
+                         "unknown",            "unknown",
+                         "unknown",            "unknown",
+                         "unknown",            "unknown",
+                         "euc-cn",             "euc-jp",
+                         "euc-kr",             "euc-tw",
+                         "jis-x0213"
+                       };
 
 
 /*
@@ -84,15 +143,53 @@ main(int  argc,                            /* I - Argument Count */
   cups_utf32_t utf32dest[1024];        /* UTF-32 destination string */
 
 
- /*
-  * Make sure we have a symbolic link from the data directory to a
-  * "charmaps" directory, and then point the library at it...
-  */
+  if (argc > 1)
+  {
+    int                        i;              /* Looping var */
+    cups_encoding_t    encoding;       /* Source encoding */
+
+
+    if (argc != 3)
+    {
+      puts("Usage: ./testi18n [filename charset]");
+      return (1);
+    }
+
+    if ((fp = fopen(argv[1], "rb")) == NULL)
+    {
+      perror(argv[1]);
+      return (1);
+    }
+
+    for (i = 0, encoding = CUPS_AUTO_ENCODING;
+         i < (int)(sizeof(lang_encodings) / sizeof(lang_encodings[0]));
+        i ++)
+      if (!_cups_strcasecmp(lang_encodings[i], argv[2]))
+      {
+        encoding = (cups_encoding_t)i;
+       break;
+      }
+
+    if (encoding == CUPS_AUTO_ENCODING)
+    {
+      fprintf(stderr, "%s: Unknown character set!\n", argv[2]);
+      return (1);
+    }
 
-  if (access("charmaps", 0))
-    symlink("../data", "charmaps");
+    while (fgets(line, sizeof(line), fp))
+    {
+      if (cupsCharsetToUTF8(utf8dest, line, sizeof(utf8dest), encoding) < 0)
+      {
+        fprintf(stderr, "%s: Unable to convert line: %s", argv[1], line);
+       return (1);
+      }
+
+      fputs((char *)utf8dest, stdout);
+    }
 
-  putenv("CUPS_DATADIR=.");
+    fclose(fp);
+    return (0);
+  }
 
  /*
   * Start with some conversion tests from a UTF-8 test file.
@@ -100,7 +197,7 @@ main(int  argc,                             /* I - Argument Count */
 
   errors = 0;
 
-  if ((fp = fopen("utf8demo.txt", "r")) == NULL)
+  if ((fp = fopen("utf8demo.txt", "rb")) == NULL)
   {
     perror("utf8demo.txt");
     return (1);
@@ -155,62 +252,6 @@ main(int  argc,                            /* I - Argument Count */
 
   fclose(fp);
 
- /*
-  * 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 charmap load for Windows-932 (Shift-JIS)...
-  */
-
-  fputs("_cupsCharmapGet(CUPS_WINDOWS_932): ", stdout);
-
-  if (!_cupsCharmapGet(CUPS_WINDOWS_932))
-  {
-    errors ++;
-    puts("FAIL");
-  }
-  else
-    puts("PASS");
-
- /*
-  * Test VBCS charmap load for EUC-JP...
-  */
-
-  fputs("_cupsCharmapGet(CUPS_EUC_JP): ", stdout);
-
-  if (!_cupsCharmapGet(CUPS_EUC_JP))
-  {
-    errors ++;
-    puts("FAIL");
-  }
-  else
-    puts("PASS");
-
- /*
-  * Test VBCS charmap load for EUC-TW...
-  */
-
-  fputs("_cupsCharmapGet(CUPS_EUC_TW): ", stdout);
-
-  if (!_cupsCharmapGet(CUPS_EUC_TW))
-  {
-    errors ++;
-    puts("FAIL");
-  }
-  else
-    puts("PASS");
-
  /*
   * Test UTF-8 to legacy charset (ISO 8859-1)...
   */
@@ -234,17 +275,17 @@ main(int  argc,                           /* I - Argument Count */
 
   fputs("cupsCharsetToUTF8(CUPS_ISO8859_1): ", stdout);
 
-  strcpy(legsrc, legdest);
+  strlcpy(legsrc, legdest, sizeof(legsrc));
 
   len = cupsCharsetToUTF8(utf8dest, legsrc, 1024, CUPS_ISO8859_1);
-  if (len != strlen((char *)utf8latin))
+  if ((size_t)len != strlen((char *)utf8latin))
   {
     printf("FAIL (len=%d, expected %d)\n", len, (int)strlen((char *)utf8latin));
     print_utf8("    utf8latin", utf8latin);
     print_utf8("    utf8dest", utf8dest);
     errors ++;
   }
-  else if (memcmp(utf8latin, utf8dest, len))
+  else if (memcmp(utf8latin, utf8dest, (size_t)len))
   {
     puts("FAIL (results do not match)");
     print_utf8("    utf8latin", utf8latin);
@@ -285,17 +326,17 @@ main(int  argc,                           /* I - Argument Count */
 
   fputs("cupsCharsetToUTF8(CUPS_ISO8859_7): ", stdout);
 
-  strcpy(legsrc, legdest);
+  strlcpy(legsrc, legdest, sizeof(legsrc));
 
   len = cupsCharsetToUTF8(utf8dest, legsrc, 1024, CUPS_ISO8859_7);
-  if (len != strlen((char *)utf8greek))
+  if ((size_t)len != strlen((char *)utf8greek))
   {
     printf("FAIL (len=%d, expected %d)\n", len, (int)strlen((char *)utf8greek));
     print_utf8("    utf8greek", utf8greek);
     print_utf8("    utf8dest", utf8dest);
     errors ++;
   }
-  else if (memcmp(utf8greek, utf8dest, len))
+  else if (memcmp(utf8greek, utf8dest, (size_t)len))
   {
     puts("FAIL (results do not match)");
     print_utf8("    utf8greek", utf8greek);
@@ -331,17 +372,17 @@ main(int  argc,                           /* I - Argument Count */
 
   fputs("cupsCharsetToUTF8(CUPS_WINDOWS_932): ", stdout);
 
-  strcpy(legsrc, legdest);
+  strlcpy(legsrc, legdest, sizeof(legsrc));
 
   len = cupsCharsetToUTF8(utf8dest, legsrc, 1024, CUPS_WINDOWS_932);
-  if (len != strlen((char *)utf8japan))
+  if ((size_t)len != strlen((char *)utf8japan))
   {
     printf("FAIL (len=%d, expected %d)\n", len, (int)strlen((char *)utf8japan));
     print_utf8("    utf8japan", utf8japan);
     print_utf8("    utf8dest", utf8dest);
     errors ++;
   }
-  else if (memcmp(utf8japan, utf8dest, len))
+  else if (memcmp(utf8japan, utf8dest, (size_t)len))
   {
     puts("FAIL (results do not match)");
     print_utf8("    utf8japan", utf8japan);
@@ -375,19 +416,20 @@ main(int  argc,                           /* I - Argument Count */
       puts("PASS");
   }
 
+#ifndef __linux
   fputs("cupsCharsetToUTF8(CUPS_EUC_JP): ", stdout);
 
-  strcpy(legsrc, legdest);
+  strlcpy(legsrc, legdest, sizeof(legsrc));
 
   len = cupsCharsetToUTF8(utf8dest, legsrc, 1024, CUPS_EUC_JP);
-  if (len != strlen((char *)utf8japan))
+  if ((size_t)len != strlen((char *)utf8japan))
   {
     printf("FAIL (len=%d, expected %d)\n", len, (int)strlen((char *)utf8japan));
     print_utf8("    utf8japan", utf8japan);
     print_utf8("    utf8dest", utf8dest);
     errors ++;
   }
-  else if (memcmp(utf8japan, utf8dest, len))
+  else if (memcmp(utf8japan, utf8dest, (size_t)len))
   {
     puts("FAIL (results do not match)");
     print_utf8("    utf8japan", utf8japan);
@@ -396,6 +438,7 @@ main(int  argc,                             /* I - Argument Count */
   }
   else
     puts("PASS");
+#endif /* !__linux */
 
  /*
   * Test UTF-8 to/from legacy charset (Windows 950)...
@@ -423,17 +466,17 @@ main(int  argc,                           /* I - Argument Count */
 
   fputs("cupsCharsetToUTF8(CUPS_WINDOWS_950): ", stdout);
 
-  strcpy(legsrc, legdest);
+  strlcpy(legsrc, legdest, sizeof(legsrc));
 
   len = cupsCharsetToUTF8(utf8dest, legsrc, 1024, CUPS_WINDOWS_950);
-  if (len != strlen((char *)utf8taiwan))
+  if ((size_t)len != strlen((char *)utf8taiwan))
   {
     printf("FAIL (len=%d, expected %d)\n", len, (int)strlen((char *)utf8taiwan));
     print_utf8("    utf8taiwan", utf8taiwan);
     print_utf8("    utf8dest", utf8dest);
     errors ++;
   }
-  else if (memcmp(utf8taiwan, utf8dest, len))
+  else if (memcmp(utf8taiwan, utf8dest, (size_t)len))
   {
     puts("FAIL (results do not match)");
     print_utf8("    utf8taiwan", utf8taiwan);
@@ -469,17 +512,17 @@ main(int  argc,                           /* I - Argument Count */
 
   fputs("cupsCharsetToUTF8(CUPS_EUC_TW): ", stdout);
 
-  strcpy(legsrc, legdest);
+  strlcpy(legsrc, legdest, sizeof(legsrc));
 
   len = cupsCharsetToUTF8(utf8dest, legsrc, 1024, CUPS_EUC_TW);
-  if (len != strlen((char *)utf8taiwan))
+  if ((size_t)len != strlen((char *)utf8taiwan))
   {
     printf("FAIL (len=%d, expected %d)\n", len, (int)strlen((char *)utf8taiwan));
     print_utf8("    utf8taiwan", utf8taiwan);
     print_utf8("    utf8dest", utf8dest);
     errors ++;
   }
-  else if (memcmp(utf8taiwan, utf8dest, len))
+  else if (memcmp(utf8taiwan, utf8dest, (size_t)len))
   {
     puts("FAIL (results do not match)");
     print_utf8("    utf8taiwan", utf8taiwan);
@@ -503,7 +546,7 @@ main(int  argc,                             /* I - Argument Count */
     print_utf8(" utf8good ", utf8good);
     print_utf32(" utf32dest", utf32dest);
   }
-  memcpy (utf32src, utf32dest, (len + 1) * sizeof(cups_utf32_t));
+  memcpy(utf32src, utf32dest, (len + 1) * sizeof(cups_utf32_t));
   len = cupsUTF32ToUTF8(utf8dest, utf32src, 1024);
   if (len < 0)
     return (1);
@@ -544,16 +587,21 @@ static void
 print_utf8(const char       *msg,      /* I - Message String */
           const cups_utf8_t *src)      /* I - UTF-8 Source String */
 {
+  const char   *prefix;                /* Prefix string */
+
+
   if (msg)
     printf("%s:", msg);
 
-  for (; *src; src ++)
-    printf(" %02x", *src);
+  for (prefix = " "; *src; src ++)
+  {
+    printf("%s%02x", prefix, *src);
+
+    if ((src[0] & 0x80) && (src[1] & 0x80))
+      prefix = "";
+    else
+      prefix = " ";
+  }
 
   putchar('\n');
 }
-
-
-/*
- * End of "$Id: testi18n.c 5837 2006-08-17 14:37:40Z mike $"
- */