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