|
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 #define UNICODE_VALID(Char) \ |
|
39 ((Char) < 0x110000 && \ |
|
40 (((Char) & 0xFFFFF800) != 0xD800) && \ |
|
41 ((Char) < 0xFDD0 || (Char) > 0xFDEF) && \ |
|
42 ((Char) & 0xFFFE) != 0xFFFE) |
|
43 |
|
44 |
|
45 |
|
46 EXPORT_C int do_test (gint index, |
|
47 const gchar *text, |
|
48 gint max_len, |
|
49 gint offset, |
|
50 gboolean valid) |
|
51 { |
|
52 const gchar *end; |
|
53 gboolean result; |
|
54 int failed =0; |
|
55 |
|
56 result = g_utf8_validate (text, max_len, &end); |
|
57 |
|
58 if (result != valid || end - text != offset) |
|
59 { |
|
60 GString *str; |
|
61 const gchar *p; |
|
62 |
|
63 failed++; |
|
64 |
|
65 str = g_string_new (0); |
|
66 for (p = text; *p; p++) |
|
67 g_string_append_printf (str, "\\x%02hhx", *p); |
|
68 g_print ("%d: g_utf8_validate (\"%s\", %d) failed, " |
|
69 "expected %s %d, got %s %d\n", |
|
70 index, |
|
71 str->str, max_len, |
|
72 valid ? "TRUE" : "FALSE", offset, |
|
73 result ? "TRUE" : "FALSE", (gint) (end - text)); |
|
74 g_string_free (str, FALSE); |
|
75 } |
|
76 return failed; |
|
77 } |
|
78 |