|
1 /* Portion Copyright © 2008-09 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.*/ |
|
2 #undef G_DISABLE_ASSERT |
|
3 #undef G_LOG_DOMAIN |
|
4 |
|
5 #include <locale.h> |
|
6 #include <stdlib.h> |
|
7 #include <stdio.h> |
|
8 #include <glib.h> |
|
9 #include <string.h> |
|
10 |
|
11 #ifdef SYMBIAN |
|
12 #include "mrt2_glib2_test.h" |
|
13 #endif /*SYMBIAN*/ |
|
14 |
|
15 |
|
16 int main (int argc, char **argv) |
|
17 { |
|
18 FILE *infile; |
|
19 char buffer[1024]; |
|
20 char **strings; |
|
21 char *srcdir = getenv ("srcdir"); |
|
22 char *filename; |
|
23 const char *locale; |
|
24 const char *test; |
|
25 char *convert; |
|
26 #define true 1 |
|
27 #define false 0 |
|
28 char passed = true; |
|
29 int lines = 0; |
|
30 |
|
31 |
|
32 |
|
33 char *current_locale = setlocale (LC_CTYPE, NULL); |
|
34 gint result = 0; |
|
35 |
|
36 #ifdef SYMBIAN |
|
37 |
|
38 g_log_set_handler (NULL, G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING | G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG, &mrtLogHandler, NULL); |
|
39 g_set_print_handler(mrtPrintHandler); |
|
40 #endif /*SYMBIAN*/ |
|
41 |
|
42 |
|
43 if (!srcdir) |
|
44 srcdir = "c:"; |
|
45 filename = g_strconcat (srcdir, G_DIR_SEPARATOR_S, "casemap.bin", NULL); |
|
46 |
|
47 infile = fopen (filename, "r"); |
|
48 if (!infile) |
|
49 { |
|
50 g_print("Failed to open %s\n", filename ); |
|
51 g_assert(FALSE && "unicode-caseconv failed"); |
|
52 |
|
53 #ifdef SYMBIAN |
|
54 testResultXml("unicode-caseconv"); |
|
55 #endif /* EMULATOR */ |
|
56 |
|
57 exit (1); |
|
58 } |
|
59 |
|
60 while (fgets (buffer, sizeof(buffer), infile)) |
|
61 { |
|
62 lines++; |
|
63 if (buffer[0] == '#') |
|
64 continue; |
|
65 |
|
66 strings = g_strsplit (buffer, "\t", -1); |
|
67 |
|
68 locale = strings[0]; |
|
69 |
|
70 if (!locale[0]) |
|
71 locale = "C"; |
|
72 |
|
73 if (strcmp (locale, current_locale) != 0) |
|
74 { |
|
75 setlocale (LC_CTYPE, locale); |
|
76 current_locale = setlocale (LC_CTYPE, NULL); |
|
77 |
|
78 if (strncmp (current_locale, locale, 2) != 0) |
|
79 { |
|
80 g_print("Cannot set locale to %s, skipping\n", locale); |
|
81 g_assert(FALSE && "unicode-caseconv failed"); |
|
82 goto next; |
|
83 } |
|
84 } |
|
85 |
|
86 test = strings[1]; |
|
87 |
|
88 convert = g_utf8_strup (test, -1); |
|
89 if (strcmp (convert, strings[4]) != 0) |
|
90 { |
|
91 g_print("Failure: strup of line %d of casemap.bin toupper(%s) == %s, should have been %s\n", |
|
92 lines,test, convert, strings[4]); |
|
93 passed = false; |
|
94 //g_assert(FALSE && "unicode-caseconv failed"); |
|
95 result = 1; |
|
96 } |
|
97 g_free (convert); |
|
98 |
|
99 convert = g_utf8_strdown (test, -1); |
|
100 if (strcmp (convert, strings[2]) != 0) |
|
101 { |
|
102 g_print("Failure: strdown of line %d of casemap.bin tolower(%s) == %s, should have been %s\n", |
|
103 lines,test, convert, strings[2]); |
|
104 //g_assert(FALSE && "unicode-caseconv failed"); |
|
105 passed = false; |
|
106 result = 1; |
|
107 } |
|
108 g_free (convert); |
|
109 |
|
110 next: |
|
111 g_strfreev (strings); |
|
112 } |
|
113 |
|
114 fclose (infile); |
|
115 |
|
116 g_free (filename); |
|
117 |
|
118 g_assert(passed && "unicode-caseconv failed"); |
|
119 passed = true; |
|
120 filename = g_strconcat (srcdir, G_DIR_SEPARATOR_S, "casefold.bin", NULL); |
|
121 |
|
122 infile = fopen (filename, "r"); |
|
123 if (!infile) |
|
124 { |
|
125 g_print("Failed to open %s\n", filename ); |
|
126 g_assert(FALSE && "unicode-caseconv failed"); |
|
127 |
|
128 #ifdef SYMBIAN |
|
129 testResultXml("unicode-caseconv"); |
|
130 #endif /* EMULATOR */ |
|
131 |
|
132 exit (1); |
|
133 } |
|
134 |
|
135 lines = 0; |
|
136 while (fgets(buffer, sizeof(buffer), infile)) |
|
137 { |
|
138 lines++; |
|
139 if (buffer[0] == '#') |
|
140 continue; |
|
141 |
|
142 buffer[strlen(buffer) - 1] = '\0'; |
|
143 strings = g_strsplit (buffer, "\t", -1); |
|
144 |
|
145 test = strings[0]; |
|
146 |
|
147 convert = g_utf8_casefold (test, -1); |
|
148 if (strcmp (convert, strings[1]) != 0) |
|
149 { |
|
150 g_print("Failure: line %d casefold(%s) == '%s', should have been '%s'\n", |
|
151 lines,test, convert, strings[1]); |
|
152 //g_assert(FALSE && "unicode-caseconv failed"); |
|
153 passed = false; |
|
154 result = 1; |
|
155 } |
|
156 g_free (convert); |
|
157 |
|
158 g_strfreev (strings); |
|
159 } |
|
160 |
|
161 fclose (infile); |
|
162 |
|
163 g_assert(passed && "unicode-caseconv failed"); |
|
164 |
|
165 #ifdef SYMBIAN |
|
166 testResultXml("unicode-caseconv"); |
|
167 #endif /* EMULATOR */ |
|
168 |
|
169 return result; |
|
170 } |