tests: Mark refcount/properties2 test as slow
[glib.git] / tests / unicode-caseconv.c
blobc124633d100f6ccc9b2ca72852a878c3dd0a37d6
1 #undef G_DISABLE_ASSERT
2 #undef G_LOG_DOMAIN
4 #include <locale.h>
5 #include <stdlib.h>
6 #include <stdio.h>
7 #include <glib.h>
8 #include <string.h>
10 int main (int argc, char **argv)
12 FILE *infile;
13 char buffer[1024];
14 char **strings;
15 char *filename;
16 const char *locale;
17 const char *test;
18 const char *expected;
19 char *convert;
20 char *current_locale = setlocale (LC_CTYPE, NULL);
21 gint result = 0;
23 g_test_init (&argc, &argv, NULL);
25 filename = g_test_build_filename (G_TEST_DIST, "casemap.txt", NULL);
27 infile = fopen (filename, "r");
28 if (!infile)
30 fprintf (stderr, "Failed to open %s\n", filename );
31 exit (1);
34 while (fgets (buffer, sizeof(buffer), infile))
36 if (buffer[0] == '#')
37 continue;
39 strings = g_strsplit (buffer, "\t", -1);
41 locale = strings[0];
43 if (!locale[0])
44 locale = "C";
46 if (strcmp (locale, current_locale) != 0)
48 setlocale (LC_CTYPE, locale);
49 current_locale = setlocale (LC_CTYPE, NULL);
51 if (strncmp (current_locale, locale, 2) != 0)
53 fprintf (stderr, "Cannot set locale to %s, skipping\n", locale);
54 goto next;
58 test = strings[1];
60 /* gen-casemap-txt.py uses an empty string when a single character
61 * doesn't have an equivalent in a particular case; since that behavior
62 * is nonsense for multicharacter strings, it would make more sense
63 * to put the expected result .. the original character unchanged. But
64 * for now, we just work around it here and take the empty string to mean
65 * "same as original"
68 convert = g_utf8_strup (test, -1);
69 expected = strings[4][0] ? strings[4] : test;
70 if (strcmp (convert, expected) != 0)
72 fprintf (stderr, "Failure: toupper(%s) == %s, should have been %s\n",
73 test, convert, expected);
74 result = 1;
76 g_free (convert);
78 convert = g_utf8_strdown (test, -1);
79 expected = strings[2][0] ? strings[2] : test;
80 if (strcmp (convert, expected) != 0)
82 fprintf (stderr, "Failure: tolower(%s) == %s, should have been %s\n",
83 test, convert, expected);
84 result = 1;
86 g_free (convert);
88 next:
89 g_strfreev (strings);
92 fclose (infile);
94 g_free (filename);
95 filename = g_test_build_filename (G_TEST_DIST, "casefold.txt", NULL);
97 infile = fopen (filename, "r");
98 if (!infile)
100 fprintf (stderr, "Failed to open %s\n", filename );
101 g_free (filename);
102 exit (1);
105 while (fgets (buffer, sizeof(buffer), infile))
107 if (buffer[0] == '#')
108 continue;
110 buffer[strlen(buffer) - 1] = '\0';
111 strings = g_strsplit (buffer, "\t", -1);
113 test = strings[0];
115 convert = g_utf8_casefold (test, -1);
116 if (strcmp (convert, strings[1]) != 0)
118 fprintf (stderr, "Failure: casefold(%s) == '%s', should have been '%s'\n",
119 test, convert, strings[1]);
120 result = 1;
122 g_free (convert);
124 g_strfreev (strings);
127 fclose (infile);
128 g_free (filename);
130 return result;