[kdbus] Do not set body message if signature field is empty
[platform/upstream/glib.git] / tests / unicode-encoding.c
index 498137b..75c982e 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
@@ -299,7 +308,6 @@ process (gint      line,
 int
 main (int argc, char **argv)
 {
-  gchar *srcdir = getenv ("srcdir");
   gchar *testfile;
   gchar *contents;
   GError *error = NULL;
@@ -312,11 +320,10 @@ main (int argc, char **argv)
   GArray *ucs4;
   Status status = VALID;       /* Quiet GCC */
 
-  if (!srcdir)
-    srcdir = ".";
-  
-  testfile = g_strconcat (srcdir, "/", "utf8.txt", NULL);
-  
+  g_test_init (&argc, &argv, NULL);
+
+  testfile = g_test_build_filename (G_TEST_DIST, "utf8.txt", NULL);
+
   g_file_get_contents (testfile, &contents, NULL, &error);
   if (error)
     croak ("Cannot open utf8.txt: %s", error->message);
@@ -332,10 +339,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 +408,16 @@ main (int argc, char **argv)
       
     next_line:
       p = end;
+      if (*p && *p == '\r')
+       p++;
       if (*p && *p == '\n')
        p++;
       
       line++;
     }
 
-  return 0;
+  g_free (testfile);
+  g_array_free (ucs4, TRUE);
+  g_free (contents);
+  return exit_status;
 }