[kdbus] Update kdbus interface header (commit: c34e65633b4e)
[platform/upstream/glib.git] / tests / unicode-caseconv.c
index 6b65a70..affb558 100644 (file)
@@ -1,3 +1,6 @@
+#undef G_DISABLE_ASSERT
+#undef G_LOG_DOMAIN
+
 #include <locale.h>
 #include <stdlib.h>
 #include <stdio.h>
@@ -9,18 +12,18 @@ int main (int argc, char **argv)
   FILE *infile;
   char buffer[1024];
   char **strings;
-  char *srcdir = getenv ("srcdir");
   char *filename;
   const char *locale;
   const char *test;
+  const char *expected;
   char *convert;
   char *current_locale = setlocale (LC_CTYPE, NULL);
   gint result = 0;
 
-  if (!srcdir)
-    srcdir = ".";
-  filename = g_strconcat (srcdir, G_DIR_SEPARATOR_S, "casemap.txt", NULL);
-  
+  g_test_init (&argc, &argv, NULL);
+
+  filename = g_test_build_filename (G_TEST_DIST, "casemap.txt", NULL);
+
   infile = fopen (filename, "r");
   if (!infile)
     {
@@ -54,20 +57,30 @@ int main (int argc, char **argv)
       
       test = strings[1];
 
-      convert = g_utf8_strup (test);
-      if (strcmp (convert, strings[4]) != 0)
+      /* gen-casemap-txt.pl uses an empty string when a single character
+       * doesn't have an equivalent in a particular case; since that behavior
+       * is nonsense for multicharacter strings, it would make more sense
+       * to put the expected result .. the original character unchanged. But 
+       * for now, we just work around it here and take the empty string to mean
+       * "same as original"
+       */
+
+      convert = g_utf8_strup (test, -1);
+      expected = strings[4][0] ? strings[4] : test;
+      if (strcmp (convert, expected) != 0)
        {
          fprintf (stderr, "Failure: toupper(%s) == %s, should have been %s\n",
-                  test, convert, strings[4]);
+                  test, convert, expected);
          result = 1;
        }
       g_free (convert);
 
-      convert = g_utf8_strdown (test);
-      if (strcmp (convert, strings[2]) != 0)
+      convert = g_utf8_strdown (test, -1);
+      expected = strings[2][0] ? strings[2] : test;
+      if (strcmp (convert, expected) != 0)
        {
          fprintf (stderr, "Failure: tolower(%s) == %s, should have been %s\n",
-                  test, convert, strings[2]);
+                  test, convert, expected);
          result = 1;
        }
       g_free (convert);
@@ -79,12 +92,13 @@ int main (int argc, char **argv)
   fclose (infile);
 
   g_free (filename);
-  filename = g_strconcat (srcdir, G_DIR_SEPARATOR_S, "casefold.txt", NULL);
+  filename = g_test_build_filename (G_TEST_DIST, "casefold.txt", NULL);
   
   infile = fopen (filename, "r");
   if (!infile)
     {
       fprintf (stderr, "Failed to open %s\n", filename );
+      g_free (filename);
       exit (1);
     }
   
@@ -98,7 +112,7 @@ int main (int argc, char **argv)
 
       test = strings[0];
 
-      convert = g_utf8_casefold (test);
+      convert = g_utf8_casefold (test, -1);
       if (strcmp (convert, strings[1]) != 0)
        {
          fprintf (stderr, "Failure: casefold(%s) == '%s', should have been '%s'\n",
@@ -111,6 +125,7 @@ int main (int argc, char **argv)
     }
 
   fclose (infile);
+  g_free (filename);
 
   return result;
 }