|
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 <stdarg.h> |
|
6 #include <string.h> |
|
7 #include <glib.h> |
|
8 #ifdef __SYMBIAN32__ |
|
9 #include "mrt2_glib2_test.h" |
|
10 #endif /*__SYMBIAN32__*/ |
|
11 |
|
12 |
|
13 static void test_format (const gchar *format, |
|
14 const gchar *expected, ...) G_GNUC_PRINTF (1, 3); |
|
15 |
|
16 static gboolean error = FALSE; |
|
17 |
|
18 static void |
|
19 test (const gchar *original, |
|
20 const gchar *expected) |
|
21 { |
|
22 gchar *result = g_markup_escape_text (original, -1); |
|
23 |
|
24 if (strcmp (result, expected) != 0) |
|
25 { |
|
26 g_printerr ("g_markup_escape_text(): expected '%s', got '%s'\n", |
|
27 expected, result); |
|
28 error = TRUE; |
|
29 } |
|
30 |
|
31 g_free (result); |
|
32 } |
|
33 |
|
34 static void |
|
35 test_unichar (gunichar c, |
|
36 gboolean entity) |
|
37 { |
|
38 gint len; |
|
39 gchar outbuf[7], expected[12]; |
|
40 |
|
41 len = g_unichar_to_utf8 (c, outbuf); |
|
42 outbuf[len] = 0; |
|
43 |
|
44 if (entity) |
|
45 g_snprintf (expected, 12, "&#x%x;", c); |
|
46 else |
|
47 strcpy (expected, outbuf); |
|
48 |
|
49 test (outbuf, expected); |
|
50 } |
|
51 |
|
52 static void |
|
53 test_format (const gchar *format, |
|
54 const gchar *expected, |
|
55 ...) |
|
56 { |
|
57 gchar *result; |
|
58 |
|
59 va_list args; |
|
60 |
|
61 va_start (args, expected); |
|
62 result = g_markup_vprintf_escaped (format, args); |
|
63 va_end (args); |
|
64 |
|
65 if (strcmp (result, expected) != 0) |
|
66 { |
|
67 g_printerr ("g_markup_printf_escaped(): expected '%s', got '%s'\n", |
|
68 expected, result); |
|
69 error = TRUE; |
|
70 } |
|
71 |
|
72 g_free (result); |
|
73 } |
|
74 |
|
75 int main (int argc, char **argv) |
|
76 { |
|
77 #ifdef __SYMBIAN32__ |
|
78 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); |
|
79 g_set_print_handler(mrtPrintHandler); |
|
80 #endif /*__SYMBIAN32__*/ |
|
81 |
|
82 |
|
83 /* Tests for g_markup_escape_text() */ |
|
84 test ("&", "&"); |
|
85 test ("<", "<"); |
|
86 test (">", ">"); |
|
87 test ("'", "'"); |
|
88 test ("\"", """); |
|
89 |
|
90 test ("", ""); |
|
91 test ("A", "A"); |
|
92 test ("A&", "A&"); |
|
93 test ("&A", "&A"); |
|
94 test ("A&A", "A&A"); |
|
95 test ("&&A", "&&A"); |
|
96 test ("A&&", "A&&"); |
|
97 test ("A&&A", "A&&A"); |
|
98 test ("A&A&A", "A&A&A"); |
|
99 test ("AA", "A&#23;A"); |
|
100 test ("A
A", "A&#xa;A"); |
|
101 test_unichar (0x1, TRUE); |
|
102 test_unichar (0x8, TRUE); |
|
103 test_unichar (0x9, FALSE); |
|
104 test_unichar (0xa, FALSE); |
|
105 test_unichar (0xb, TRUE); |
|
106 test_unichar (0xc, TRUE); |
|
107 test_unichar (0xd, FALSE); |
|
108 test_unichar (0xe, TRUE); |
|
109 test_unichar (0x1f, TRUE); |
|
110 test_unichar (0x20, FALSE); |
|
111 test_unichar (0x7e, FALSE); |
|
112 test_unichar (0x7f, TRUE); |
|
113 test_unichar (0x84, TRUE); |
|
114 test_unichar (0x85, FALSE); |
|
115 test_unichar (0x86, TRUE); |
|
116 test_unichar (0x9f, TRUE); |
|
117 test_unichar (0xa0, FALSE); |
|
118 |
|
119 /* Tests for g_markup_printf_escaped() */ |
|
120 test_format ("A", "A"); |
|
121 test_format ("A%s", "A&", "&"); |
|
122 test_format ("%sA", "&A", "&"); |
|
123 test_format ("A%sA", "A&A", "&"); |
|
124 test_format ("%s%sA", "&&A", "&", "&"); |
|
125 test_format ("A%s%s", "A&&", "&", "&"); |
|
126 test_format ("A%s%sA", "A&&A", "&", "&"); |
|
127 test_format ("A%sA%sA", "A&A&A", "&", "&"); |
|
128 |
|
129 test_format ("%s", "<B>&", |
|
130 "<B>&"); |
|
131 test_format ("%c%c", "<&", |
|
132 '<', '&'); |
|
133 test_format (".%c.%c.", ".<.&.", |
|
134 '<', '&'); |
|
135 test_format ("%s", "", |
|
136 ""); |
|
137 test_format ("%-5s", "A ", |
|
138 "A"); |
|
139 test_format ("%2$s%1$s", "B.A.", |
|
140 "A.", "B."); |
|
141 |
|
142 |
|
143 #ifdef __SYMBIAN32__ |
|
144 testResultXml("markup-escape-test"); |
|
145 #endif /* EMULATOR */ |
|
146 |
|
147 return error ? 1 : 0; |
|
148 } |