|
1 /* GLIB - Library of useful routines for C programming |
|
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald |
|
3 * Portion Copyright © 2008-09 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. |
|
4 * This library is free software; you can redistribute it and/or |
|
5 * modify it under the terms of the GNU Lesser General Public |
|
6 * License as published by the Free Software Foundation; either |
|
7 * version 2 of the License, or (at your option) any later version. |
|
8 * |
|
9 * This library is distributed in the hope that it will be useful, |
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
12 * Lesser General Public License for more details. |
|
13 * |
|
14 * You should have received a copy of the GNU Lesser General Public |
|
15 * License along with this library; if not, write to the |
|
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
|
17 * Boston, MA 02111-1307, USA. |
|
18 */ |
|
19 |
|
20 /* |
|
21 * Modified by the GLib Team and others 1997-2000. See the AUTHORS |
|
22 * file for a list of people on the GLib Team. See the ChangeLog |
|
23 * files for a list of changes. These files are distributed with |
|
24 * GLib at ftp://ftp.gtk.org/pub/gtk/. |
|
25 */ |
|
26 |
|
27 #undef G_DISABLE_ASSERT |
|
28 #undef G_LOG_DOMAIN |
|
29 |
|
30 #include <string.h> |
|
31 #include <stdio.h> |
|
32 |
|
33 #include <glib.h> |
|
34 #ifdef SYMBIAN |
|
35 #include "mrt2_glib2_test.h" |
|
36 #endif /*SYMBIAN*/ |
|
37 |
|
38 #ifdef SYMBIAN |
|
39 static void |
|
40 test_conversion (void) |
|
41 { |
|
42 gchar *in = "\xa5\xa6\xa7\xa8"; |
|
43 gchar *expected = "\xc2\xa5\xc2\xa6\xc2\xa7\xc2\xa8"; |
|
44 gchar *out; |
|
45 gsize bytes_read = 0; |
|
46 gsize bytes_written = 0; |
|
47 GError *error = NULL; |
|
48 |
|
49 out = g_convert (in, -1, "UTF-8", "ISO-8859-1", |
|
50 &bytes_read, &bytes_written, &error); |
|
51 |
|
52 g_assert (error == NULL); |
|
53 g_assert (bytes_read == 4); |
|
54 g_assert (bytes_written == 8); |
|
55 g_assert (strcmp (out, expected) == 0); |
|
56 |
|
57 g_free (out); |
|
58 |
|
59 } |
|
60 |
|
61 #endif /*SYMBIAN*/ |
|
62 |
|
63 /* Bug 311337 */ |
|
64 static void |
|
65 test_iconv_state (void) |
|
66 { |
|
67 gchar *in = "\xf4\xe5\xf8\xe5\xed"; |
|
68 gchar *expected = "\xd7\xa4\xd7\x95\xd7\xa8\xd7\x95\xd7\x9d"; |
|
69 gchar *out; |
|
70 gsize bytes_read = 0; |
|
71 gsize bytes_written = 0; |
|
72 GError *error = NULL; |
|
73 |
|
74 out = g_convert (in, -1, "UTF-8", "windows-1255", |
|
75 &bytes_read, &bytes_written, &error); |
|
76 |
|
77 g_assert (error == NULL); |
|
78 g_assert (bytes_read == 5); |
|
79 g_assert (bytes_written == 10); |
|
80 g_assert (strcmp (out, expected) == 0); |
|
81 g_free (out); |
|
82 } |
|
83 |
|
84 /* some tests involving "vulgar fraction one half" */ |
|
85 static void |
|
86 test_one_half (void) |
|
87 { |
|
88 gchar *in = "\xc2\xbd"; |
|
89 gchar *out; |
|
90 gsize bytes_read = 0; |
|
91 gsize bytes_written = 0; |
|
92 GError *error = NULL; |
|
93 |
|
94 out = g_convert (in, -1, |
|
95 "ISO-8859-1", "UTF-8", |
|
96 &bytes_read, &bytes_written, |
|
97 &error); |
|
98 |
|
99 g_assert (error == NULL); |
|
100 g_assert (bytes_read == 2); |
|
101 g_assert (bytes_written == 1); |
|
102 g_assert (strcmp (out, "\xbd") == 0); |
|
103 g_free (out); |
|
104 |
|
105 out = g_convert (in, -1, |
|
106 "ISO-8859-15", "UTF-8", |
|
107 &bytes_read, &bytes_written, |
|
108 &error); |
|
109 |
|
110 g_assert (error && error->code == G_CONVERT_ERROR_ILLEGAL_SEQUENCE); |
|
111 g_assert (bytes_read == 0); |
|
112 g_assert (bytes_written == 0); |
|
113 g_assert (out == NULL); |
|
114 g_clear_error (&error); |
|
115 g_free (out); |
|
116 |
|
117 out = g_convert_with_fallback (in, -1, |
|
118 "ISO-8859-15", "UTF-8", |
|
119 "a", |
|
120 &bytes_read, &bytes_written, |
|
121 &error); |
|
122 |
|
123 g_assert (error == NULL); |
|
124 g_assert (bytes_read == 2); |
|
125 g_assert (bytes_written == 1); |
|
126 g_assert (strcmp (out, "a") == 0); |
|
127 g_free (out); |
|
128 } |
|
129 |
|
130 static void |
|
131 test_byte_order (void) |
|
132 { |
|
133 gchar in_be[2] = { 0x03, 0x93}; /* capital gamma */ |
|
134 gchar in_le[2] = { 0x93, 0x03}; |
|
135 gchar *expected = "\xce\x93"; |
|
136 gchar *out; |
|
137 gsize bytes_read = 0; |
|
138 gsize bytes_written = 0; |
|
139 GError *error = NULL; |
|
140 |
|
141 out = g_convert (in_be, sizeof (in_be), |
|
142 "UTF-8", "UTF-16BE", |
|
143 &bytes_read, &bytes_written, |
|
144 &error); |
|
145 |
|
146 g_assert (error == NULL); |
|
147 g_assert (bytes_read == 2); |
|
148 g_assert (bytes_written == 2); |
|
149 g_assert (strcmp (out, expected) == 0); |
|
150 g_free (out); |
|
151 |
|
152 out = g_convert (in_le, sizeof (in_le), |
|
153 "UTF-8", "UTF-16LE", |
|
154 &bytes_read, &bytes_written, |
|
155 &error); |
|
156 |
|
157 g_assert (error == NULL); |
|
158 g_assert (bytes_read == 2); |
|
159 g_assert (bytes_written == 2); |
|
160 g_assert (strcmp (out, expected) == 0); |
|
161 g_free (out); |
|
162 } |
|
163 |
|
164 static void |
|
165 check_utf8_to_ucs4 (const char *utf8, |
|
166 glong utf8_len, |
|
167 const gunichar *ucs4, |
|
168 glong ucs4_len, |
|
169 glong error_pos) |
|
170 { |
|
171 gunichar *result, *result2, *result3; |
|
172 glong items_read, items_read2; |
|
173 glong items_written, items_written2; |
|
174 GError *error, *error2, *error3; |
|
175 gint i; |
|
176 |
|
177 if (!error_pos) |
|
178 { |
|
179 /* check the fast conversion */ |
|
180 result = g_utf8_to_ucs4_fast (utf8, utf8_len, &items_written); |
|
181 |
|
182 g_assert (items_written == ucs4_len); |
|
183 g_assert (result); |
|
184 for (i = 0; i <= items_written; i++) |
|
185 g_assert (result[i] == ucs4[i]); |
|
186 |
|
187 g_free (result); |
|
188 } |
|
189 |
|
190 error = NULL; |
|
191 result = g_utf8_to_ucs4 (utf8, utf8_len, &items_read, &items_written, &error); |
|
192 |
|
193 if (utf8_len == strlen (utf8)) |
|
194 { |
|
195 /* check that len == -1 yields identical results */ |
|
196 error2 = NULL; |
|
197 result2 = g_utf8_to_ucs4 (utf8, -1, &items_read2, &items_written2, &error2); |
|
198 g_assert (error || items_read2 == items_read); |
|
199 g_assert (error || items_written2 == items_written2); |
|
200 g_assert (!!result == !!result2); |
|
201 g_assert (!!error == !!error2); |
|
202 if (result) |
|
203 for (i = 0; i <= items_written; i++) |
|
204 g_assert (result[i] == result2[i]); |
|
205 |
|
206 g_free (result2); |
|
207 if (error2) |
|
208 g_error_free (error2); |
|
209 } |
|
210 |
|
211 error3 = NULL; |
|
212 result3 = g_utf8_to_ucs4 (utf8, utf8_len, NULL, NULL, &error3); |
|
213 |
|
214 if (error3 && error3->code == G_CONVERT_ERROR_PARTIAL_INPUT) |
|
215 { |
|
216 g_assert (error == NULL); |
|
217 g_assert (items_read == error_pos); |
|
218 g_assert (items_written == ucs4_len); |
|
219 g_assert (result); |
|
220 for (i = 0; i <= items_written; i++) |
|
221 g_assert (result[i] == ucs4[i]); |
|
222 } |
|
223 else if (error_pos) |
|
224 { |
|
225 g_assert (error != NULL); |
|
226 g_assert (result == NULL); |
|
227 g_assert (items_read == error_pos); |
|
228 g_error_free (error); |
|
229 |
|
230 g_assert (error3 != NULL); |
|
231 g_assert (result3 == NULL); |
|
232 g_error_free (error3); |
|
233 } |
|
234 else |
|
235 { |
|
236 g_assert (error == NULL); |
|
237 g_assert (items_read == utf8_len); |
|
238 g_assert (items_written == ucs4_len); |
|
239 g_assert (result); |
|
240 for (i = 0; i <= items_written; i++) |
|
241 g_assert (result[i] == ucs4[i]); |
|
242 |
|
243 g_assert (error3 == NULL); |
|
244 g_assert (result3); |
|
245 for (i = 0; i <= ucs4_len; i++) |
|
246 g_assert (result3[i] == ucs4[i]); |
|
247 } |
|
248 |
|
249 g_free (result); |
|
250 g_free (result3); |
|
251 } |
|
252 |
|
253 static void |
|
254 check_ucs4_to_utf8 (const gunichar *ucs4, |
|
255 glong ucs4_len, |
|
256 const char *utf8, |
|
257 glong utf8_len, |
|
258 glong error_pos) |
|
259 { |
|
260 gchar *result, *result2, *result3; |
|
261 glong items_read, items_read2; |
|
262 glong items_written, items_written2; |
|
263 GError *error, *error2, *error3; |
|
264 |
|
265 error = NULL; |
|
266 result = g_ucs4_to_utf8 (ucs4, ucs4_len, &items_read, &items_written, &error); |
|
267 |
|
268 if (ucs4[ucs4_len] == 0) |
|
269 { |
|
270 /* check that len == -1 yields identical results */ |
|
271 error2 = NULL; |
|
272 result2 = g_ucs4_to_utf8 (ucs4, -1, &items_read2, &items_written2, &error2); |
|
273 |
|
274 g_assert (error || items_read2 == items_read); |
|
275 g_assert (error || items_written2 == items_written); |
|
276 g_assert (!!result == !!result2); |
|
277 g_assert (!!error == !!error2); |
|
278 if (result) |
|
279 g_assert (strcmp (result, result2) == 0); |
|
280 |
|
281 g_free (result2); |
|
282 if (error2) |
|
283 g_error_free (error2); |
|
284 } |
|
285 |
|
286 error3 = NULL; |
|
287 result3 = g_ucs4_to_utf8 (ucs4, ucs4_len, NULL, NULL, &error3); |
|
288 |
|
289 if (error_pos) |
|
290 { |
|
291 g_assert (error != NULL); |
|
292 g_assert (result == NULL); |
|
293 g_assert (items_read == error_pos); |
|
294 g_error_free (error); |
|
295 |
|
296 g_assert (error3 != NULL); |
|
297 g_assert (result3 == NULL); |
|
298 g_error_free (error3); |
|
299 } |
|
300 else |
|
301 { |
|
302 g_assert (error == NULL); |
|
303 g_assert (items_read == ucs4_len); |
|
304 g_assert (items_written == utf8_len); |
|
305 g_assert (result); |
|
306 g_assert (strcmp (result, utf8) == 0); |
|
307 |
|
308 g_assert (error3 == NULL); |
|
309 g_assert (result3); |
|
310 g_assert (strcmp (result3, utf8) == 0); |
|
311 } |
|
312 |
|
313 g_free (result); |
|
314 g_free (result3); |
|
315 } |
|
316 |
|
317 static void |
|
318 check_utf8_to_utf16 (const char *utf8, |
|
319 glong utf8_len, |
|
320 const gunichar2 *utf16, |
|
321 glong utf16_len, |
|
322 glong error_pos) |
|
323 { |
|
324 gunichar2 *result, *result2, *result3; |
|
325 glong items_read, items_read2; |
|
326 glong items_written, items_written2; |
|
327 GError *error, *error2, *error3; |
|
328 gint i; |
|
329 |
|
330 error = NULL; |
|
331 result = g_utf8_to_utf16 (utf8, utf8_len, &items_read, &items_written, &error); |
|
332 |
|
333 if (utf8_len == strlen (utf8)) |
|
334 { |
|
335 /* check that len == -1 yields identical results */ |
|
336 error2 = NULL; |
|
337 result2 = g_utf8_to_utf16 (utf8, -1, &items_read2, &items_written2, &error2); |
|
338 g_assert (error || items_read2 == items_read); |
|
339 g_assert (error || items_written2 == items_written2); |
|
340 g_assert (!!result == !!result2); |
|
341 g_assert (!!error == !!error2); |
|
342 if (result) |
|
343 for (i = 0; i <= items_written; i++) |
|
344 g_assert (result[i] == result2[i]); |
|
345 |
|
346 g_free (result2); |
|
347 if (error2) |
|
348 g_error_free (error2); |
|
349 } |
|
350 |
|
351 error3 = NULL; |
|
352 result3 = g_utf8_to_utf16 (utf8, utf8_len, NULL, NULL, &error3); |
|
353 |
|
354 if (error3 && error3->code == G_CONVERT_ERROR_PARTIAL_INPUT) |
|
355 { |
|
356 g_assert (error == NULL); |
|
357 g_assert (items_read == error_pos); |
|
358 g_assert (items_written == utf16_len); |
|
359 g_assert (result); |
|
360 for (i = 0; i <= items_written; i++) |
|
361 g_assert (result[i] == utf16[i]); |
|
362 } |
|
363 else if (error_pos) |
|
364 { |
|
365 g_assert (error != NULL); |
|
366 g_assert (result == NULL); |
|
367 g_assert (items_read == error_pos); |
|
368 g_error_free (error); |
|
369 |
|
370 g_assert (error3 != NULL); |
|
371 g_assert (result3 == NULL); |
|
372 g_error_free (error3); |
|
373 } |
|
374 else |
|
375 { |
|
376 g_assert (error == NULL); |
|
377 g_assert (items_read == utf8_len); |
|
378 g_assert (items_written == utf16_len); |
|
379 g_assert (result); |
|
380 for (i = 0; i <= items_written; i++) |
|
381 g_assert (result[i] == utf16[i]); |
|
382 |
|
383 g_assert (error3 == NULL); |
|
384 g_assert (result3); |
|
385 for (i = 0; i <= utf16_len; i++) |
|
386 g_assert (result3[i] == utf16[i]); |
|
387 } |
|
388 |
|
389 g_free (result); |
|
390 g_free (result3); |
|
391 } |
|
392 |
|
393 static void |
|
394 check_utf16_to_utf8 (const gunichar2 *utf16, |
|
395 glong utf16_len, |
|
396 const char *utf8, |
|
397 glong utf8_len, |
|
398 glong error_pos) |
|
399 { |
|
400 gchar *result, *result2, *result3; |
|
401 glong items_read, items_read2; |
|
402 glong items_written, items_written2; |
|
403 GError *error, *error2, *error3; |
|
404 |
|
405 error = NULL; |
|
406 result = g_utf16_to_utf8 (utf16, utf16_len, &items_read, &items_written, &error); |
|
407 if (utf16[utf16_len] == 0) |
|
408 { |
|
409 /* check that len == -1 yields identical results */ |
|
410 error2 = NULL; |
|
411 result2 = g_utf16_to_utf8 (utf16, -1, &items_read2, &items_written2, &error2); |
|
412 |
|
413 g_assert (error || items_read2 == items_read); |
|
414 g_assert (error || items_written2 == items_written); |
|
415 g_assert (!!result == !!result2); |
|
416 g_assert (!!error == !!error2); |
|
417 if (result) |
|
418 g_assert (strcmp (result, result2) == 0); |
|
419 |
|
420 g_free (result2); |
|
421 if (error2) |
|
422 g_error_free (error2); |
|
423 } |
|
424 |
|
425 error3 = NULL; |
|
426 result3 = g_utf16_to_utf8 (utf16, utf16_len, NULL, NULL, &error3); |
|
427 |
|
428 if (error3 && error3->code == G_CONVERT_ERROR_PARTIAL_INPUT) |
|
429 { |
|
430 g_assert (error == NULL); |
|
431 g_assert (items_read == error_pos); |
|
432 g_assert (items_read + 1 == utf16_len); |
|
433 g_assert (items_written == utf8_len); |
|
434 g_assert (result); |
|
435 g_assert (strcmp (result, utf8) == 0); |
|
436 } |
|
437 else if (error_pos) |
|
438 { |
|
439 g_assert (error != NULL); |
|
440 g_assert (result == NULL); |
|
441 g_assert (items_read == error_pos); |
|
442 g_error_free (error); |
|
443 |
|
444 g_assert (error3 != NULL); |
|
445 g_assert (result3 == NULL); |
|
446 g_error_free (error3); |
|
447 } |
|
448 else |
|
449 { |
|
450 g_assert (error == NULL); |
|
451 g_assert (items_read == utf16_len); |
|
452 g_assert (items_written == utf8_len); |
|
453 g_assert (result); |
|
454 g_assert (strcmp (result, utf8) == 0); |
|
455 |
|
456 g_assert (error3 == NULL); |
|
457 g_assert (result3); |
|
458 g_assert (strcmp (result3, utf8) == 0); |
|
459 } |
|
460 |
|
461 g_free (result); |
|
462 g_free (result3); |
|
463 } |
|
464 |
|
465 static void |
|
466 check_ucs4_to_utf16 (const gunichar *ucs4, |
|
467 glong ucs4_len, |
|
468 const gunichar2 *utf16, |
|
469 glong utf16_len, |
|
470 glong error_pos) |
|
471 { |
|
472 gunichar2 *result, *result2, *result3; |
|
473 glong items_read, items_read2; |
|
474 glong items_written, items_written2; |
|
475 GError *error, *error2, *error3; |
|
476 gint i; |
|
477 |
|
478 error = NULL; |
|
479 result = g_ucs4_to_utf16 (ucs4, ucs4_len, &items_read, &items_written, &error); |
|
480 |
|
481 if (ucs4[ucs4_len] == 0) |
|
482 { |
|
483 /* check that len == -1 yields identical results */ |
|
484 error2 = NULL; |
|
485 result2 = g_ucs4_to_utf16 (ucs4, -1, &items_read2, &items_written2, &error2); |
|
486 |
|
487 g_assert (error || items_read2 == items_read); |
|
488 g_assert (error || items_written2 == items_written); |
|
489 g_assert (!!result == !!result2); |
|
490 g_assert (!!error == !!error2); |
|
491 if (result) |
|
492 for (i = 0; i <= utf16_len; i++) |
|
493 g_assert (result[i] == result2[i]); |
|
494 |
|
495 g_free (result2); |
|
496 if (error2) |
|
497 g_error_free (error2); |
|
498 } |
|
499 |
|
500 error3 = NULL; |
|
501 result3 = g_ucs4_to_utf16 (ucs4, -1, NULL, NULL, &error3); |
|
502 |
|
503 if (error_pos) |
|
504 { |
|
505 g_assert (error != NULL); |
|
506 g_assert (result == NULL); |
|
507 g_assert (items_read == error_pos); |
|
508 g_error_free (error); |
|
509 |
|
510 g_assert (error3 != NULL); |
|
511 g_assert (result3 == NULL); |
|
512 g_error_free (error3); |
|
513 } |
|
514 else |
|
515 { |
|
516 g_assert (error == NULL); |
|
517 g_assert (items_read == ucs4_len); |
|
518 g_assert (items_written == utf16_len); |
|
519 g_assert (result); |
|
520 for (i = 0; i <= utf16_len; i++) |
|
521 g_assert (result[i] == utf16[i]); |
|
522 |
|
523 g_assert (error3 == NULL); |
|
524 g_assert (result3); |
|
525 for (i = 0; i <= utf16_len; i++) |
|
526 g_assert (result3[i] == utf16[i]); |
|
527 } |
|
528 |
|
529 g_free (result); |
|
530 g_free (result3); |
|
531 } |
|
532 |
|
533 static void |
|
534 check_utf16_to_ucs4 (const gunichar2 *utf16, |
|
535 glong utf16_len, |
|
536 const gunichar *ucs4, |
|
537 glong ucs4_len, |
|
538 glong error_pos) |
|
539 { |
|
540 gunichar *result, *result2, *result3; |
|
541 glong items_read, items_read2; |
|
542 glong items_written, items_written2; |
|
543 GError *error, *error2, *error3; |
|
544 gint i; |
|
545 |
|
546 error = NULL; |
|
547 result = g_utf16_to_ucs4 (utf16, utf16_len, &items_read, &items_written, &error); |
|
548 if (utf16[utf16_len] == 0) |
|
549 { |
|
550 /* check that len == -1 yields identical results */ |
|
551 error2 = NULL; |
|
552 result2 = g_utf16_to_ucs4 (utf16, -1, &items_read2, &items_written2, &error2); |
|
553 g_assert (error || items_read2 == items_read); |
|
554 g_assert (error || items_written2 == items_written2); |
|
555 g_assert (!!result == !!result2); |
|
556 g_assert (!!error == !!error2); |
|
557 if (result) |
|
558 for (i = 0; i <= items_written; i++) |
|
559 g_assert (result[i] == result2[i]); |
|
560 |
|
561 g_free (result2); |
|
562 if (error2) |
|
563 g_error_free (error2); |
|
564 } |
|
565 |
|
566 error3 = NULL; |
|
567 result3 = g_utf16_to_ucs4 (utf16, utf16_len, NULL, NULL, &error3); |
|
568 |
|
569 if (error3 && error3->code == G_CONVERT_ERROR_PARTIAL_INPUT) |
|
570 { |
|
571 g_assert (error == NULL); |
|
572 g_assert (items_read == error_pos); |
|
573 g_assert (items_read + 1 == utf16_len); |
|
574 g_assert (items_written == ucs4_len); |
|
575 g_assert (result); |
|
576 for (i = 0; i <= items_written; i++) |
|
577 g_assert (result[i] == ucs4[i]); |
|
578 } |
|
579 else if (error_pos) |
|
580 { |
|
581 g_assert (error != NULL); |
|
582 g_assert (result == NULL); |
|
583 g_assert (items_read == error_pos); |
|
584 g_error_free (error); |
|
585 |
|
586 g_assert (error3 != NULL); |
|
587 g_assert (result3 == NULL); |
|
588 g_error_free (error3); |
|
589 } |
|
590 else |
|
591 { |
|
592 g_assert (error == NULL); |
|
593 g_assert (items_read == utf16_len); |
|
594 g_assert (items_written == ucs4_len); |
|
595 g_assert (result); |
|
596 for (i = 0; i <= ucs4_len; i++) |
|
597 g_assert (result[i] == ucs4[i]); |
|
598 |
|
599 g_assert (error3 == NULL); |
|
600 g_assert (result3); |
|
601 for (i = 0; i <= ucs4_len; i++) |
|
602 g_assert (result3[i] == ucs4[i]); |
|
603 } |
|
604 |
|
605 g_free (result); |
|
606 g_free (result3); |
|
607 } |
|
608 |
|
609 static void |
|
610 test_unicode_conversions (void) |
|
611 { |
|
612 char *utf8; |
|
613 gunichar ucs4[100]; |
|
614 gunichar2 utf16[100]; |
|
615 |
|
616 utf8 = "abc"; |
|
617 ucs4[0] = 0x61; ucs4[1] = 0x62; ucs4[2] = 0x63; ucs4[3] = 0; |
|
618 utf16[0] = 0x61; utf16[1] = 0x62; utf16[2] = 0x63; utf16[3] = 0; |
|
619 |
|
620 check_utf8_to_ucs4 (utf8, 3, ucs4, 3, 0); |
|
621 check_ucs4_to_utf8 (ucs4, 3, utf8, 3, 0); |
|
622 check_utf8_to_utf16 (utf8, 3, utf16, 3, 0); |
|
623 check_utf16_to_utf8 (utf16, 3, utf8, 3, 0); |
|
624 check_ucs4_to_utf16 (ucs4, 3, utf16, 3, 0); |
|
625 check_utf16_to_ucs4 (utf16, 3, ucs4, 3, 0); |
|
626 |
|
627 utf8 = "\316\261\316\262\316\263"; |
|
628 ucs4[0] = 0x03b1; ucs4[1] = 0x03b2; ucs4[2] = 0x03b3; ucs4[3] = 0; |
|
629 utf16[0] = 0x03b1; utf16[1] = 0x03b2; utf16[2] = 0x03b3; utf16[3] = 0; |
|
630 |
|
631 check_utf8_to_ucs4 (utf8, 6, ucs4, 3, 0); |
|
632 check_ucs4_to_utf8 (ucs4, 3, utf8, 6, 0); |
|
633 check_utf8_to_utf16 (utf8, 6, utf16, 3, 0); |
|
634 check_utf16_to_utf8 (utf16, 3, utf8, 6, 0); |
|
635 check_ucs4_to_utf16 (ucs4, 3, utf16, 3, 0); |
|
636 check_utf16_to_ucs4 (utf16, 3, ucs4, 3, 0); |
|
637 |
|
638 /* partial utf8 character */ |
|
639 utf8 = "abc\316"; |
|
640 ucs4[0] = 0x61; ucs4[1] = 0x62; ucs4[2] = 0x63; ucs4[3] = 0; |
|
641 utf16[0] = 0x61; utf16[1] = 0x62; utf16[2] = 0x63; utf16[3] = 0; |
|
642 |
|
643 check_utf8_to_ucs4 (utf8, 4, ucs4, 3, 3); |
|
644 check_utf8_to_utf16 (utf8, 4, utf16, 3, 3); |
|
645 |
|
646 /* invalid utf8 */ |
|
647 utf8 = "abc\316\316"; |
|
648 ucs4[0] = 0; |
|
649 utf16[0] = 0; |
|
650 /* |
|
651 Some of the test cases are not executed below by putting them under SYMBIAN |
|
652 flag. The reason is that the input is invalid therefore, the test cases are |
|
653 supposed to fail. Eventhough there is nothing wrong with the library code the |
|
654 test case will fail as it is test whether failure takes place or not. |
|
655 Hence there is no point executing them as they will uncessary |
|
656 reflect bad on the pass rate. |
|
657 */ |
|
658 |
|
659 #ifndef SYMBIAN |
|
660 check_utf8_to_ucs4 (utf8, 5, ucs4, 0, 3); |
|
661 check_utf8_to_utf16 (utf8, 5, utf16, 0, 3); |
|
662 #endif /* SYMBIAN */ |
|
663 |
|
664 /* partial utf16 character */ |
|
665 utf8 = "ab"; |
|
666 ucs4[0] = 0x61; ucs4[1] = 0x62; ucs4[2] = 0; |
|
667 utf16[0] = 0x61; utf16[1] = 0x62; utf16[2] = 0xd801; utf16[3] = 0; |
|
668 |
|
669 check_utf16_to_utf8 (utf16, 3, utf8, 2, 2); |
|
670 check_utf16_to_ucs4 (utf16, 3, ucs4, 2, 2); |
|
671 |
|
672 /* invalid utf16 */ |
|
673 utf8 = NULL; |
|
674 ucs4[0] = 0; |
|
675 utf16[0] = 0x61; utf16[1] = 0x62; utf16[2] = 0xdc01; utf16[3] = 0; |
|
676 |
|
677 #ifndef SYMBIAN |
|
678 check_utf16_to_utf8 (utf16, 3, utf8, 0, 2); |
|
679 check_utf16_to_ucs4 (utf16, 3, ucs4, 0, 2); |
|
680 #endif /* SYMBIAN */ |
|
681 |
|
682 /* invalid ucs4 */ |
|
683 utf8 = NULL; |
|
684 ucs4[0] = 0x61; ucs4[1] = 0x62; ucs4[2] = 0x80000000; ucs4[3] = 0; |
|
685 utf16[0] = 0; |
|
686 |
|
687 #ifndef SYMBIAN |
|
688 check_ucs4_to_utf8 (ucs4, 3, utf8, 0, 2); |
|
689 check_ucs4_to_utf16 (ucs4, 3, utf16, 0, 2); |
|
690 #endif /* SYMBIAN */ |
|
691 } |
|
692 |
|
693 int |
|
694 main (int argc, char *argv[]) |
|
695 { |
|
696 #ifdef SYMBIAN |
|
697 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); |
|
698 g_set_print_handler(mrtPrintHandler); |
|
699 #endif /*SYMBIAN*/ |
|
700 |
|
701 test_iconv_state (); |
|
702 test_one_half (); |
|
703 test_byte_order (); |
|
704 test_conversion(); |
|
705 test_unicode_conversions (); |
|
706 |
|
707 #if SYMBIAN |
|
708 testResultXml("convert-test"); |
|
709 #endif /* EMULATOR */ |
|
710 |
|
711 return 0; |
|
712 } |