|
1 /* |
|
2 * ============================================================================== |
|
3 * Name : gcce-validate.c |
|
4 * Part of : internal/gcce |
|
5 * Description : This is a test program to test the cross linking of openc libraries with |
|
6 * programs compiled using the gcce compiler |
|
7 Copyright © 2006 Nokia Corporation |
|
8 All rights reserved. |
|
9 Redistribution and use in source and binary forms, with or without |
|
10 modification, are permitted provided that the following conditions are met: |
|
11 * Redistributions of source code must retain the above copyright notice, this |
|
12 list of conditions and the following disclaimer. |
|
13 * Redistributions in binary form must reproduce the above copyright notice, |
|
14 this list of conditions and the following disclaimer in the documentation |
|
15 and/or other materials provided with the distribution. |
|
16 * Neither the name of the <ORGANIZATION> nor the names of its contributors |
|
17 may be used to endorse or promote products derived from this software |
|
18 without specific prior written permission. |
|
19 |
|
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
21 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
22 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
|
23 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE |
|
24 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
|
25 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
|
26 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
|
27 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
|
28 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
29 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
30 * ============================================================================== |
|
31 */ |
|
32 |
|
33 #include <glib.h> |
|
34 #include <stdio.h> |
|
35 |
|
36 #include "result_log.h" |
|
37 |
|
38 void mrtLogHandler(const gchar* log_domain, GLogLevelFlags log_level, |
|
39 const gchar* message, gpointer user_data) |
|
40 { |
|
41 FILE *fp; |
|
42 fp = fopen("c:\\logtests.txt","a"); |
|
43 |
|
44 if(fp) |
|
45 { |
|
46 fprintf(fp,message); |
|
47 fprintf(fp,"\n"); |
|
48 fclose(fp); |
|
49 } |
|
50 } |
|
51 |
|
52 void mrtPrintHandler(const gchar *message) |
|
53 { |
|
54 FILE *fp; |
|
55 fp = fopen("c:\\logtests.txt","a"); |
|
56 |
|
57 if(fp) |
|
58 { |
|
59 fprintf(fp,message); |
|
60 fprintf(fp,"\n"); |
|
61 fclose(fp); |
|
62 } |
|
63 } |
|
64 |
|
65 |
|
66 |
|
67 #define UNICODE_VALID(Char) \ |
|
68 ((Char) < 0x110000 && \ |
|
69 (((Char) & 0xFFFFF800) != 0xD800) && \ |
|
70 ((Char) < 0xFDD0 || (Char) > 0xFDEF) && \ |
|
71 ((Char) & 0xFFFE) != 0xFFFE) |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 struct { |
|
77 const gchar *text; |
|
78 gint max_len; |
|
79 gint offset; |
|
80 gboolean valid; |
|
81 } test[] = { |
|
82 /* some tests to check max_len handling */ |
|
83 /* length 1 */ |
|
84 { "abcde", -1, 5, TRUE }, |
|
85 { "abcde", 3, 3, TRUE }, |
|
86 { "abcde", 5, 5, TRUE }, |
|
87 { "abcde", 7, 5, FALSE }, |
|
88 /* length 2 */ |
|
89 { "\xc2\xa9\xc2\xa9\xc2\xa9", -1, 6, TRUE }, |
|
90 { "\xc2\xa9\xc2\xa9\xc2\xa9", 1, 0, FALSE }, |
|
91 { "\xc2\xa9\xc2\xa9\xc2\xa9", 2, 2, TRUE }, |
|
92 { "\xc2\xa9\xc2\xa9\xc2\xa9", 3, 2, FALSE }, |
|
93 { "\xc2\xa9\xc2\xa9\xc2\xa9", 4, 4, TRUE }, |
|
94 { "\xc2\xa9\xc2\xa9\xc2\xa9", 5, 4, FALSE }, |
|
95 { "\xc2\xa9\xc2\xa9\xc2\xa9", 6, 6, TRUE }, |
|
96 { "\xc2\xa9\xc2\xa9\xc2\xa9", 7, 6, FALSE }, |
|
97 /* length 3 */ |
|
98 { "\xe2\x89\xa0\xe2\x89\xa0", -1, 6, TRUE }, |
|
99 { "\xe2\x89\xa0\xe2\x89\xa0", 1, 0, FALSE }, |
|
100 { "\xe2\x89\xa0\xe2\x89\xa0", 2, 0, FALSE }, |
|
101 { "\xe2\x89\xa0\xe2\x89\xa0", 3, 3, TRUE }, |
|
102 { "\xe2\x89\xa0\xe2\x89\xa0", 4, 3, FALSE }, |
|
103 { "\xe2\x89\xa0\xe2\x89\xa0", 5, 3, FALSE }, |
|
104 { "\xe2\x89\xa0\xe2\x89\xa0", 6, 6, TRUE }, |
|
105 { "\xe2\x89\xa0\xe2\x89\xa0", 7, 6, FALSE }, |
|
106 |
|
107 /* examples from http://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt */ |
|
108 /* greek 'kosme' */ |
|
109 { "\xce\xba\xe1\xbd\xb9\xcf\x83\xce\xbc\xce\xb5", -1, 11, TRUE }, |
|
110 /* first sequence of each length */ |
|
111 { "\x00", -1, 0, TRUE }, |
|
112 { "\xc2\x80", -1, 2, TRUE }, |
|
113 { "\xe0\xa0\x80", -1, 3, TRUE }, |
|
114 { "\xf0\x90\x80\x80", -1, 4, TRUE }, |
|
115 { "\xf8\x88\x80\x80\x80", -1, 0, FALSE }, |
|
116 { "\xfc\x84\x80\x80\x80\x80", -1, 0, FALSE }, |
|
117 /* last sequence of each length */ |
|
118 { "\x7f", -1, 1, TRUE }, |
|
119 { "\xdf\xbf", -1, 2, TRUE }, |
|
120 { "\xef\xbf\xbf", -1, 0, FALSE }, |
|
121 { "\xf7\xbf\xbf\xbf", -1, 0, FALSE }, |
|
122 { "\xfb\xbf\xbf\xbf\xbf", -1, 0, FALSE }, |
|
123 { "\xfd\xbf\xbf\xbf\xbf\xbf", -1, 0, FALSE }, |
|
124 /* other boundary conditions */ |
|
125 { "\xed\x9f\xbf", -1, 3, TRUE }, |
|
126 { "\xee\x80\x80", -1, 3, TRUE }, |
|
127 { "\xef\xbf\xbd", -1, 3, TRUE }, |
|
128 { "\xf4\x8f\xbf\xbf", -1, 0, FALSE }, |
|
129 { "\xf4\x90\x80\x80", -1, 0, FALSE }, |
|
130 /* malformed sequences */ |
|
131 /* continuation bytes */ |
|
132 { "\x80", -1, 0, FALSE }, |
|
133 { "\xbf", -1, 0, FALSE }, |
|
134 { "\x80\xbf", -1, 0, FALSE }, |
|
135 { "\x80\xbf\x80", -1, 0, FALSE }, |
|
136 { "\x80\xbf\x80\xbf", -1, 0, FALSE }, |
|
137 { "\x80\xbf\x80\xbf\x80", -1, 0, FALSE }, |
|
138 { "\x80\xbf\x80\xbf\x80\xbf", -1, 0, FALSE }, |
|
139 { "\x80\xbf\x80\xbf\x80\xbf\x80", -1, 0, FALSE }, |
|
140 |
|
141 /* all possible continuation byte */ |
|
142 { "\x80", -1, 0, FALSE }, |
|
143 { "\x81", -1, 0, FALSE }, |
|
144 { "\x82", -1, 0, FALSE }, |
|
145 { "\x83", -1, 0, FALSE }, |
|
146 { "\x84", -1, 0, FALSE }, |
|
147 { "\x85", -1, 0, FALSE }, |
|
148 { "\x86", -1, 0, FALSE }, |
|
149 { "\x87", -1, 0, FALSE }, |
|
150 { "\x88", -1, 0, FALSE }, |
|
151 { "\x89", -1, 0, FALSE }, |
|
152 { "\x8a", -1, 0, FALSE }, |
|
153 { "\x8b", -1, 0, FALSE }, |
|
154 { "\x8c", -1, 0, FALSE }, |
|
155 { "\x8d", -1, 0, FALSE }, |
|
156 { "\x8e", -1, 0, FALSE }, |
|
157 { "\x8f", -1, 0, FALSE }, |
|
158 { "\x90", -1, 0, FALSE }, |
|
159 { "\x91", -1, 0, FALSE }, |
|
160 { "\x92", -1, 0, FALSE }, |
|
161 { "\x93", -1, 0, FALSE }, |
|
162 { "\x94", -1, 0, FALSE }, |
|
163 { "\x95", -1, 0, FALSE }, |
|
164 { "\x96", -1, 0, FALSE }, |
|
165 { "\x97", -1, 0, FALSE }, |
|
166 { "\x98", -1, 0, FALSE }, |
|
167 { "\x99", -1, 0, FALSE }, |
|
168 { "\x9a", -1, 0, FALSE }, |
|
169 { "\x9b", -1, 0, FALSE }, |
|
170 { "\x9c", -1, 0, FALSE }, |
|
171 { "\x9d", -1, 0, FALSE }, |
|
172 { "\x9e", -1, 0, FALSE }, |
|
173 { "\x9f", -1, 0, FALSE }, |
|
174 { "\xa0", -1, 0, FALSE }, |
|
175 { "\xa1", -1, 0, FALSE }, |
|
176 { "\xa2", -1, 0, FALSE }, |
|
177 { "\xa3", -1, 0, FALSE }, |
|
178 { "\xa4", -1, 0, FALSE }, |
|
179 { "\xa5", -1, 0, FALSE }, |
|
180 { "\xa6", -1, 0, FALSE }, |
|
181 { "\xa7", -1, 0, FALSE }, |
|
182 { "\xa8", -1, 0, FALSE }, |
|
183 { "\xa9", -1, 0, FALSE }, |
|
184 { "\xaa", -1, 0, FALSE }, |
|
185 { "\xab", -1, 0, FALSE }, |
|
186 { "\xac", -1, 0, FALSE }, |
|
187 { "\xad", -1, 0, FALSE }, |
|
188 { "\xae", -1, 0, FALSE }, |
|
189 { "\xaf", -1, 0, FALSE }, |
|
190 { "\xb0", -1, 0, FALSE }, |
|
191 { "\xb1", -1, 0, FALSE }, |
|
192 { "\xb2", -1, 0, FALSE }, |
|
193 { "\xb3", -1, 0, FALSE }, |
|
194 { "\xb4", -1, 0, FALSE }, |
|
195 { "\xb5", -1, 0, FALSE }, |
|
196 { "\xb6", -1, 0, FALSE }, |
|
197 { "\xb7", -1, 0, FALSE }, |
|
198 { "\xb8", -1, 0, FALSE }, |
|
199 { "\xb9", -1, 0, FALSE }, |
|
200 { "\xba", -1, 0, FALSE }, |
|
201 { "\xbb", -1, 0, FALSE }, |
|
202 { "\xbc", -1, 0, FALSE }, |
|
203 { "\xbd", -1, 0, FALSE }, |
|
204 { "\xbe", -1, 0, FALSE }, |
|
205 { "\xbf", -1, 0, FALSE }, |
|
206 /* lone start characters */ |
|
207 { "\xc0\x20", -1, 0, FALSE }, |
|
208 { "\xc1\x20", -1, 0, FALSE }, |
|
209 { "\xc2\x20", -1, 0, FALSE }, |
|
210 { "\xc3\x20", -1, 0, FALSE }, |
|
211 { "\xc4\x20", -1, 0, FALSE }, |
|
212 { "\xc5\x20", -1, 0, FALSE }, |
|
213 { "\xc6\x20", -1, 0, FALSE }, |
|
214 { "\xc7\x20", -1, 0, FALSE }, |
|
215 { "\xc8\x20", -1, 0, FALSE }, |
|
216 { "\xc9\x20", -1, 0, FALSE }, |
|
217 { "\xca\x20", -1, 0, FALSE }, |
|
218 { "\xcb\x20", -1, 0, FALSE }, |
|
219 { "\xcc\x20", -1, 0, FALSE }, |
|
220 { "\xcd\x20", -1, 0, FALSE }, |
|
221 { "\xce\x20", -1, 0, FALSE }, |
|
222 { "\xcf\x20", -1, 0, FALSE }, |
|
223 { "\xd0\x20", -1, 0, FALSE }, |
|
224 { "\xd1\x20", -1, 0, FALSE }, |
|
225 { "\xd2\x20", -1, 0, FALSE }, |
|
226 { "\xd3\x20", -1, 0, FALSE }, |
|
227 { "\xd4\x20", -1, 0, FALSE }, |
|
228 { "\xd5\x20", -1, 0, FALSE }, |
|
229 { "\xd6\x20", -1, 0, FALSE }, |
|
230 { "\xd7\x20", -1, 0, FALSE }, |
|
231 { "\xd8\x20", -1, 0, FALSE }, |
|
232 { "\xd9\x20", -1, 0, FALSE }, |
|
233 { "\xda\x20", -1, 0, FALSE }, |
|
234 { "\xdb\x20", -1, 0, FALSE }, |
|
235 { "\xdc\x20", -1, 0, FALSE }, |
|
236 { "\xdd\x20", -1, 0, FALSE }, |
|
237 { "\xde\x20", -1, 0, FALSE }, |
|
238 { "\xdf\x20", -1, 0, FALSE }, |
|
239 { "\xe0\x20", -1, 0, FALSE }, |
|
240 { "\xe1\x20", -1, 0, FALSE }, |
|
241 { "\xe2\x20", -1, 0, FALSE }, |
|
242 { "\xe3\x20", -1, 0, FALSE }, |
|
243 { "\xe4\x20", -1, 0, FALSE }, |
|
244 { "\xe5\x20", -1, 0, FALSE }, |
|
245 { "\xe6\x20", -1, 0, FALSE }, |
|
246 { "\xe7\x20", -1, 0, FALSE }, |
|
247 { "\xe8\x20", -1, 0, FALSE }, |
|
248 { "\xe9\x20", -1, 0, FALSE }, |
|
249 { "\xea\x20", -1, 0, FALSE }, |
|
250 { "\xeb\x20", -1, 0, FALSE }, |
|
251 { "\xec\x20", -1, 0, FALSE }, |
|
252 { "\xed\x20", -1, 0, FALSE }, |
|
253 { "\xee\x20", -1, 0, FALSE }, |
|
254 { "\xef\x20", -1, 0, FALSE }, |
|
255 { "\xf0\x20", -1, 0, FALSE }, |
|
256 { "\xf1\x20", -1, 0, FALSE }, |
|
257 { "\xf2\x20", -1, 0, FALSE }, |
|
258 { "\xf3\x20", -1, 0, FALSE }, |
|
259 { "\xf4\x20", -1, 0, FALSE }, |
|
260 { "\xf5\x20", -1, 0, FALSE }, |
|
261 { "\xf6\x20", -1, 0, FALSE }, |
|
262 { "\xf7\x20", -1, 0, FALSE }, |
|
263 { "\xf8\x20", -1, 0, FALSE }, |
|
264 { "\xf9\x20", -1, 0, FALSE }, |
|
265 { "\xfa\x20", -1, 0, FALSE }, |
|
266 { "\xfb\x20", -1, 0, FALSE }, |
|
267 { "\xfc\x20", -1, 0, FALSE }, |
|
268 { "\xfd\x20", -1, 0, FALSE }, |
|
269 /* missing continuation bytes */ |
|
270 { "\x20\xc0", -1, 1, FALSE }, |
|
271 { "\x20\xe0\x80", -1, 1, FALSE }, |
|
272 { "\x20\xf0\x80\x80", -1, 1, FALSE }, |
|
273 { "\x20\xf8\x80\x80\x80", -1, 1, FALSE }, |
|
274 { "\x20\xfc\x80\x80\x80\x80", -1, 1, FALSE }, |
|
275 { "\x20\xdf", -1, 1, FALSE }, |
|
276 { "\x20\xef\xbf", -1, 1, FALSE }, |
|
277 { "\x20\xf7\xbf\xbf", -1, 1, FALSE }, |
|
278 { "\x20\xfb\xbf\xbf\xbf", -1, 1, FALSE }, |
|
279 { "\x20\xfd\xbf\xbf\xbf\xbf", -1, 1, FALSE }, |
|
280 /* impossible bytes */ |
|
281 { "\x20\xfe\x20", -1, 1, FALSE }, |
|
282 { "\x20\xff\x20", -1, 1, FALSE }, |
|
283 /* overlong sequences */ |
|
284 { "\x20\xc0\xaf\x20", -1, 1, FALSE }, |
|
285 { "\x20\xe0\x80\xaf\x20", -1, 1, FALSE }, |
|
286 { "\x20\xf0\x80\x80\xaf\x20", -1, 1, FALSE }, |
|
287 { "\x20\xf8\x80\x80\x80\xaf\x20", -1, 1, FALSE }, |
|
288 { "\x20\xfc\x80\x80\x80\x80\xaf\x20", -1, 1, FALSE }, |
|
289 { "\x20\xc1\xbf\x20", -1, 1, FALSE }, |
|
290 { "\x20\xe0\x9f\xbf\x20", -1, 1, FALSE }, |
|
291 { "\x20\xf0\x8f\xbf\xbf\x20", -1, 1, FALSE }, |
|
292 { "\x20\xf8\x87\xbf\xbf\xbf\x20", -1, 1, FALSE }, |
|
293 { "\x20\xfc\x83\xbf\xbf\xbf\xbf\x20", -1, 1, FALSE }, |
|
294 { "\x20\xc0\x80\x20", -1, 1, FALSE }, |
|
295 { "\x20\xe0\x80\x80\x20", -1, 1, FALSE }, |
|
296 { "\x20\xf0\x80\x80\x80\x20", -1, 1, FALSE }, |
|
297 { "\x20\xf8\x80\x80\x80\x80\x20", -1, 1, FALSE }, |
|
298 { "\x20\xfc\x80\x80\x80\x80\x80\x20", -1, 1, FALSE }, |
|
299 /* illegal code positions */ |
|
300 { "\x20\xed\xa0\x80\x20", -1, 1, FALSE }, |
|
301 { "\x20\xed\xad\xbf\x20", -1, 1, FALSE }, |
|
302 { "\x20\xed\xae\x80\x20", -1, 1, FALSE }, |
|
303 { "\x20\xed\xaf\xbf\x20", -1, 1, FALSE }, |
|
304 { "\x20\xed\xb0\x80\x20", -1, 1, FALSE }, |
|
305 { "\x20\xed\xbe\x80\x20", -1, 1, FALSE }, |
|
306 { "\x20\xed\xbf\xbf\x20", -1, 1, FALSE }, |
|
307 { "\x20\xed\xa0\x80\xed\xb0\x80\x20", -1, 1, FALSE }, |
|
308 { "\x20\xed\xa0\x80\xed\xbf\xbf\x20", -1, 1, FALSE }, |
|
309 { "\x20\xed\xad\xbf\xed\xb0\x80\x20", -1, 1, FALSE }, |
|
310 { "\x20\xed\xad\xbf\xed\xbf\xbf\x20", -1, 1, FALSE }, |
|
311 { "\x20\xed\xae\x80\xed\xb0\x80\x20", -1, 1, FALSE }, |
|
312 { "\x20\xed\xae\x80\xed\xbf\xbf\x20", -1, 1, FALSE }, |
|
313 { "\x20\xed\xaf\xbf\xed\xb0\x80\x20", -1, 1, FALSE }, |
|
314 { "\x20\xed\xaf\xbf\xed\xbf\xbf\x20", -1, 1, FALSE }, |
|
315 { "\x20\xef\xbf\xbe\x20", -1, 1, FALSE }, |
|
316 { "\x20\xef\xbf\xbf\x20", -1, 1, FALSE }, |
|
317 |
|
318 { NULL, } |
|
319 }; |
|
320 |
|
321 extern int do_test (gint index, const gchar *text, gint max_len, gint offset, gboolean valid); |
|
322 |
|
323 int |
|
324 main (int argc, char *argv[]) |
|
325 { |
|
326 gint i; |
|
327 |
|
328 int any_failed = 0; |
|
329 int ret; |
|
330 for (i = 0; test[i].text; i++) |
|
331 { |
|
332 ret = do_test (i, test[i].text, test[i].max_len, |
|
333 test[i].offset, test[i].valid); |
|
334 any_failed += ret; |
|
335 |
|
336 } |
|
337 |
|
338 |
|
339 #ifdef SYMBIAN |
|
340 testResultXml("gcce-load",any_failed); |
|
341 #endif /* EMULATOR */ |
|
342 |
|
343 return any_failed ? 1 : 0; |
|
344 } |