|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 #undef G_DISABLE_ASSERT |
|
18 #undef G_LOG_DOMAIN |
|
19 |
|
20 #include <stdarg.h> |
|
21 #include <string.h> |
|
22 #include <glib.h> |
|
23 #include <stdio.h> |
|
24 |
|
25 #ifdef SYMBIAN |
|
26 #include "mrt2_glib2_test.h" |
|
27 #endif /*SYMBIAN*/ |
|
28 |
|
29 |
|
30 static void test_format (const gchar *format, |
|
31 const gchar *expected, ...) G_GNUC_PRINTF (1, 3); |
|
32 |
|
33 static gboolean error = FALSE; |
|
34 |
|
35 static void |
|
36 test (const gchar *original, |
|
37 const gchar *expected) |
|
38 { |
|
39 gchar *result = g_markup_escape_text (original, -1); |
|
40 |
|
41 if (strcmp (result, expected) != 0) |
|
42 { |
|
43 g_print ("g_markup_escape_text(): expected '%s', got '%s'\n", |
|
44 expected, result); |
|
45 error = TRUE; |
|
46 assert_failed = TRUE; |
|
47 } |
|
48 |
|
49 g_free (result); |
|
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_print ("g_markup_printf_escaped(): expected '%s', got '%s'\n", |
|
68 expected, result); |
|
69 assert_failed = TRUE; |
|
70 error = TRUE; |
|
71 } |
|
72 |
|
73 g_free (result); |
|
74 } |
|
75 |
|
76 int main (int argc, char **argv) |
|
77 { |
|
78 #ifdef SYMBIAN |
|
79 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); |
|
80 g_set_print_handler(mrtPrintHandler); |
|
81 #endif /*SYMBIAN*/ |
|
82 |
|
83 |
|
84 /* Tests for g_markup_escape_text() */ |
|
85 test ("&", "&"); |
|
86 test ("<", "<"); |
|
87 test (">", ">"); |
|
88 test ("'", "'"); |
|
89 test ("\"", """); |
|
90 |
|
91 test ("", ""); |
|
92 test ("A", "A"); |
|
93 test ("A&", "A&"); |
|
94 test ("&A", "&A"); |
|
95 test ("A&A", "A&A"); |
|
96 test ("&&A", "&&A"); |
|
97 test ("A&&", "A&&"); |
|
98 test ("A&&A", "A&&A"); |
|
99 test ("A&A&A", "A&A&A"); |
|
100 |
|
101 /* Tests for g_markup_printf_escaped() */ |
|
102 test_format ("A", "A"); |
|
103 test_format ("A%s", "A&", "&"); |
|
104 test_format ("%sA", "&A", "&"); |
|
105 test_format ("A%sA", "A&A", "&"); |
|
106 test_format ("%s%sA", "&&A", "&", "&"); |
|
107 test_format ("A%s%s", "A&&", "&", "&"); |
|
108 test_format ("A%s%sA", "A&&A", "&", "&"); |
|
109 test_format ("A%sA%sA", "A&A&A", "&", "&"); |
|
110 |
|
111 test_format ("%s", "<B>&", |
|
112 "<B>&"); |
|
113 test_format ("%c%c", "<&", |
|
114 '<', '&'); |
|
115 test_format (".%c.%c.", ".<.&.", |
|
116 '<', '&'); |
|
117 test_format ("%s", "", |
|
118 ""); |
|
119 test_format ("%-5s", "A ", |
|
120 "A"); |
|
121 test_format ("%2$s%1$s", "B.A.", |
|
122 "A.", "B."); |
|
123 |
|
124 |
|
125 #ifdef SYMBIAN |
|
126 testResultXml("markup-escape-test"); |
|
127 #endif /* EMULATOR */ |
|
128 |
|
129 return error ? 1 : 0; |
|
130 } |