|
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 #include <stdio.h> |
|
9 |
|
10 #ifdef __SYMBIAN32__ |
|
11 #include "mrt2_glib2_test.h" |
|
12 #endif /*__SYMBIAN32__*/ |
|
13 |
|
14 |
|
15 static void test_format (const gchar *format, |
|
16 const gchar *expected, ...) G_GNUC_PRINTF (1, 3); |
|
17 |
|
18 static gboolean error = FALSE; |
|
19 |
|
20 static void |
|
21 test (const gchar *original, |
|
22 const gchar *expected) |
|
23 { |
|
24 gchar *result = g_markup_escape_text (original, -1); |
|
25 |
|
26 if (strcmp (result, expected) != 0) |
|
27 { |
|
28 g_print ("g_markup_escape_text(): expected '%s', got '%s'\n", |
|
29 expected, result); |
|
30 error = TRUE; |
|
31 assert_failed = TRUE; |
|
32 } |
|
33 |
|
34 g_free (result); |
|
35 } |
|
36 |
|
37 static void |
|
38 test_format (const gchar *format, |
|
39 const gchar *expected, |
|
40 ...) |
|
41 { |
|
42 gchar *result; |
|
43 |
|
44 va_list args; |
|
45 |
|
46 va_start (args, expected); |
|
47 result = g_markup_vprintf_escaped (format, args); |
|
48 va_end (args); |
|
49 |
|
50 if (strcmp (result, expected) != 0) |
|
51 { |
|
52 g_print ("g_markup_printf_escaped(): expected '%s', got '%s'\n", |
|
53 expected, result); |
|
54 assert_failed = TRUE; |
|
55 error = TRUE; |
|
56 } |
|
57 |
|
58 g_free (result); |
|
59 } |
|
60 |
|
61 int main (int argc, char **argv) |
|
62 { |
|
63 #ifdef __SYMBIAN32__ |
|
64 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); |
|
65 g_set_print_handler(mrtPrintHandler); |
|
66 #endif /*__SYMBIAN32__*/ |
|
67 |
|
68 |
|
69 /* Tests for g_markup_escape_text() */ |
|
70 test ("&", "&"); |
|
71 test ("<", "<"); |
|
72 test (">", ">"); |
|
73 test ("'", "'"); |
|
74 test ("\"", """); |
|
75 |
|
76 test ("", ""); |
|
77 test ("A", "A"); |
|
78 test ("A&", "A&"); |
|
79 test ("&A", "&A"); |
|
80 test ("A&A", "A&A"); |
|
81 test ("&&A", "&&A"); |
|
82 test ("A&&", "A&&"); |
|
83 test ("A&&A", "A&&A"); |
|
84 test ("A&A&A", "A&A&A"); |
|
85 |
|
86 /* Tests for g_markup_printf_escaped() */ |
|
87 test_format ("A", "A"); |
|
88 test_format ("A%s", "A&", "&"); |
|
89 test_format ("%sA", "&A", "&"); |
|
90 test_format ("A%sA", "A&A", "&"); |
|
91 test_format ("%s%sA", "&&A", "&", "&"); |
|
92 test_format ("A%s%s", "A&&", "&", "&"); |
|
93 test_format ("A%s%sA", "A&&A", "&", "&"); |
|
94 test_format ("A%sA%sA", "A&A&A", "&", "&"); |
|
95 |
|
96 test_format ("%s", "<B>&", |
|
97 "<B>&"); |
|
98 test_format ("%c%c", "<&", |
|
99 '<', '&'); |
|
100 test_format (".%c.%c.", ".<.&.", |
|
101 '<', '&'); |
|
102 test_format ("%s", "", |
|
103 ""); |
|
104 test_format ("%-5s", "A ", |
|
105 "A"); |
|
106 test_format ("%2$s%1$s", "B.A.", |
|
107 "A.", "B."); |
|
108 |
|
109 |
|
110 #ifdef __SYMBIAN32__ |
|
111 testResultXml("markup-escape-test"); |
|
112 #endif /* EMULATOR */ |
|
113 |
|
114 return error ? 1 : 0; |
|
115 } |