Convert more tests to installed tests
[platform/upstream/glib.git] / tests / unicode-encoding.c
index 498137b..09b3392 100644 (file)
@@ -1,3 +1,6 @@
+#undef G_DISABLE_ASSERT
+#undef G_LOG_DOMAIN
+
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -6,7 +9,7 @@
 
 static gint exit_status = 0;
 
-void
+static void
 croak (char *format, ...)
 {
   va_list va;
@@ -18,7 +21,7 @@ croak (char *format, ...)
   exit (1);
 }
 
-void
+static void
 fail (char *format, ...)
 {
   va_list va;
@@ -84,7 +87,7 @@ process (gint      line,
   const gchar *end;
   gboolean is_valid = g_utf8_validate (utf8, -1, &end);
   GError *error = NULL;
-  gint items_read, items_written;
+  glong items_read, items_written;
 
   switch (status)
     {
@@ -188,11 +191,17 @@ process (gint      line,
       gunichar2 *utf16_from_utf8;
       gunichar2 *utf16_from_ucs4;
       gunichar *ucs4_result;
-      gint bytes_written;
+      gsize bytes_written;
       gint n_chars;
       gchar *utf8_result;
 
-      if (!(utf16_expected_tmp = (gunichar2 *)g_convert (utf8, -1, "UTF-16", "UTF-8",
+#if G_BYTE_ORDER == G_LITTLE_ENDIAN
+#define TARGET "UTF-16LE"
+#else
+#define TARGET "UTF-16"
+#endif
+
+      if (!(utf16_expected_tmp = (gunichar2 *)g_convert (utf8, -1, TARGET, "UTF-8",
                                                         NULL, &bytes_written, NULL)))
        {
          fail ("line %d: could not convert to UTF-16 via g_convert\n", line);
@@ -210,7 +219,7 @@ process (gint      line,
        }
       else if (utf16_expected_tmp[0] == 0xfffe) /* ANTI-BOM */
        {
-         fail ("line %d: conversion via iconv to \"UTF-16\" is not native-endian\n");
+         fail ("line %d: conversion via iconv to \"UTF-16\" is not native-endian\n", line);
          return;
        }
       else
@@ -315,7 +324,7 @@ main (int argc, char **argv)
   if (!srcdir)
     srcdir = ".";
   
-  testfile = g_strconcat (srcdir, "/", "utf8.txt", NULL);
+  testfile = g_strconcat (srcdir, G_DIR_SEPARATOR_S "utf8.txt", NULL);
   
   g_file_get_contents (testfile, &contents, NULL, &error);
   if (error)
@@ -332,10 +341,10 @@ main (int argc, char **argv)
        p++;
 
       end = p;
-      while (*end && *end != '\n')
+      while (*end && (*end != '\r' && *end != '\n'))
        end++;
       
-      if (!*p || *p == '#' || *p == '\n')
+      if (!*p || *p == '#' || *p == '\r' || *p == '\n')
        goto next_line;
 
       tmp = g_strstrip (g_strndup (p, end - p));
@@ -401,11 +410,13 @@ main (int argc, char **argv)
       
     next_line:
       p = end;
+      if (*p && *p == '\r')
+       p++;
       if (*p && *p == '\n')
        p++;
       
       line++;
     }
 
-  return 0;
+  return exit_status;
 }