Improve ABI checks
[glib.git] / tests / unicode-caseconv.c
blob8b949d45a9f090cdee3dafdb04387252ec1195c5
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 *srcdir = getenv ("srcdir");
16 char *filename;
17 const char *locale;
18 const char *test;
19 char *convert;
20 char *current_locale = setlocale (LC_CTYPE, NULL);
21 gint result = 0;
23 if (!srcdir)
24 srcdir = ".";
25 filename = g_strconcat (srcdir, G_DIR_SEPARATOR_S, "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 convert = g_utf8_strup (test, -1);
61 if (strcmp (convert, strings[4]) != 0)
63 fprintf (stderr, "Failure: toupper(%s) == %s, should have been %s\n",
64 test, convert, strings[4]);
65 result = 1;
67 g_free (convert);
69 convert = g_utf8_strdown (test, -1);
70 if (strcmp (convert, strings[2]) != 0)
72 fprintf (stderr, "Failure: tolower(%s) == %s, should have been %s\n",
73 test, convert, strings[2]);
74 result = 1;
76 g_free (convert);
78 next:
79 g_strfreev (strings);
82 fclose (infile);
84 g_free (filename);
85 filename = g_strconcat (srcdir, G_DIR_SEPARATOR_S, "casefold.txt", NULL);
87 infile = fopen (filename, "r");
88 if (!infile)
90 fprintf (stderr, "Failed to open %s\n", filename );
91 exit (1);
94 while (fgets (buffer, sizeof(buffer), infile))
96 if (buffer[0] == '#')
97 continue;
99 buffer[strlen(buffer) - 1] = '\0';
100 strings = g_strsplit (buffer, "\t", -1);
102 test = strings[0];
104 convert = g_utf8_casefold (test, -1);
105 if (strcmp (convert, strings[1]) != 0)
107 fprintf (stderr, "Failure: casefold(%s) == '%s', should have been '%s'\n",
108 test, convert, strings[1]);
109 result = 1;
111 g_free (convert);
113 g_strfreev (strings);
116 fclose (infile);
118 return result;