First public contribution.
1 /* Portion Copyright © 2008-09 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.*/
2 #undef G_DISABLE_ASSERT
11 #include "mrt2_glib2_test.h"
15 static void test_format (const gchar *format,
16 const gchar *expected, ...) G_GNUC_PRINTF (1, 3);
18 static gboolean error = FALSE;
21 test (const gchar *original,
22 const gchar *expected)
24 gchar *result = g_markup_escape_text (original, -1);
26 if (strcmp (result, expected) != 0)
28 g_print ("g_markup_escape_text(): expected '%s', got '%s'\n",
38 test_format (const gchar *format,
39 const gchar *expected,
46 va_start (args, expected);
47 result = g_markup_vprintf_escaped (format, args);
50 if (strcmp (result, expected) != 0)
52 g_print ("g_markup_printf_escaped(): expected '%s', got '%s'\n",
61 int main (int argc, char **argv)
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);
69 /* Tests for g_markup_escape_text() */
74 test ("\"", """);
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");
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", "&", "&");
96 test_format ("%s", "<B>&",
98 test_format ("%c%c", "<&",
100 test_format (".%c.%c.", ".<.&.",
102 test_format ("%s", "",
104 test_format ("%-5s", "A ",
106 test_format ("%2$s%1$s", "B.A.",
111 testResultXml("markup-escape-test");
112 #endif /* EMULATOR */
114 return error ? 1 : 0;