Update contrib.
1 /* Portion Copyright © 2008-09 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.*/
2 #undef G_DISABLE_ASSERT
9 #include "mrt2_glib2_test.h"
10 #endif /*__SYMBIAN32__*/
13 static void test_format (const gchar *format,
14 const gchar *expected, ...) G_GNUC_PRINTF (1, 3);
16 static gboolean error = FALSE;
19 test (const gchar *original,
20 const gchar *expected)
22 gchar *result = g_markup_escape_text (original, -1);
24 if (strcmp (result, expected) != 0)
26 g_printerr ("g_markup_escape_text(): expected '%s', got '%s'\n",
35 test_unichar (gunichar c,
39 gchar outbuf[7], expected[12];
41 len = g_unichar_to_utf8 (c, outbuf);
45 g_snprintf (expected, 12, "&#x%x;", c);
47 strcpy (expected, outbuf);
49 test (outbuf, expected);
53 test_format (const gchar *format,
54 const gchar *expected,
61 va_start (args, expected);
62 result = g_markup_vprintf_escaped (format, args);
65 if (strcmp (result, expected) != 0)
67 g_printerr ("g_markup_printf_escaped(): expected '%s', got '%s'\n",
75 int main (int argc, char **argv)
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__*/
83 /* Tests for g_markup_escape_text() */
88 test ("\"", """);
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", "AA");
100 test ("A
A", "A
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);
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", "&", "&");
129 test_format ("%s", "<B>&",
131 test_format ("%c%c", "<&",
133 test_format (".%c.%c.", ".<.&.",
135 test_format ("%s", "",
137 test_format ("%-5s", "A ",
139 test_format ("%2$s%1$s", "B.A.",
144 testResultXml("markup-escape-test");
145 #endif /* EMULATOR */
147 return error ? 1 : 0;