sl@0: /* Portion Copyright © 2008-09 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.*/ sl@0: #undef G_DISABLE_ASSERT sl@0: #undef G_LOG_DOMAIN sl@0: sl@0: #include sl@0: #include sl@0: sl@0: #ifdef __SYMBIAN32__ sl@0: #include "mrt2_glib2_test.h" sl@0: #endif /*__SYMBIAN32__*/ sl@0: sl@0: sl@0: static int depth = 0; sl@0: sl@0: static void sl@0: indent (int extra) sl@0: { sl@0: int i = 0; sl@0: while (i < depth) sl@0: { sl@0: fputs (" ", stdout); sl@0: ++i; sl@0: } sl@0: } sl@0: sl@0: static void sl@0: start_element_handler (GMarkupParseContext *context, sl@0: const gchar *element_name, sl@0: const gchar **attribute_names, sl@0: const gchar **attribute_values, sl@0: gpointer user_data, sl@0: GError **error) sl@0: { sl@0: int i; sl@0: sl@0: indent (0); sl@0: printf ("ELEMENT '%s'\n", element_name); sl@0: sl@0: i = 0; sl@0: while (attribute_names[i] != NULL) sl@0: { sl@0: indent (1); sl@0: sl@0: printf ("%s=\"%s\"\n", sl@0: attribute_names[i], sl@0: attribute_values[i]); sl@0: sl@0: ++i; sl@0: } sl@0: sl@0: ++depth; sl@0: } sl@0: sl@0: static void sl@0: end_element_handler (GMarkupParseContext *context, sl@0: const gchar *element_name, sl@0: gpointer user_data, sl@0: GError **error) sl@0: { sl@0: --depth; sl@0: indent (0); sl@0: printf ("END '%s'\n", element_name); sl@0: } sl@0: sl@0: static void sl@0: text_handler (GMarkupParseContext *context, sl@0: const gchar *text, sl@0: gsize text_len, sl@0: gpointer user_data, sl@0: GError **error) sl@0: { sl@0: indent (0); sl@0: printf ("TEXT '%.*s'\n", (int)text_len, text); sl@0: } sl@0: sl@0: sl@0: static void sl@0: passthrough_handler (GMarkupParseContext *context, sl@0: const gchar *passthrough_text, sl@0: gsize text_len, sl@0: gpointer user_data, sl@0: GError **error) sl@0: { sl@0: indent (0); sl@0: sl@0: printf ("PASS '%.*s'\n", (int)text_len, passthrough_text); sl@0: } sl@0: sl@0: static void sl@0: error_handler (GMarkupParseContext *context, sl@0: GError *error, sl@0: gpointer user_data) sl@0: { sl@0: fprintf (stderr, " %s\n", error->message); sl@0: } sl@0: sl@0: static const GMarkupParser parser = { sl@0: start_element_handler, sl@0: end_element_handler, sl@0: text_handler, sl@0: passthrough_handler, sl@0: error_handler sl@0: }; sl@0: sl@0: static const GMarkupParser silent_parser = { sl@0: NULL, sl@0: NULL, sl@0: NULL, sl@0: NULL, sl@0: error_handler sl@0: }; sl@0: sl@0: static int sl@0: test_in_chunks (const gchar *contents, sl@0: gint length, sl@0: gint chunk_size) sl@0: { sl@0: GMarkupParseContext *context; sl@0: int i = 0; sl@0: sl@0: context = g_markup_parse_context_new (&silent_parser, 0, NULL, NULL); sl@0: sl@0: while (i < length) sl@0: { sl@0: int this_chunk = MIN (length - i, chunk_size); sl@0: sl@0: if (!g_markup_parse_context_parse (context, sl@0: contents + i, sl@0: this_chunk, sl@0: NULL)) sl@0: { sl@0: g_markup_parse_context_free (context); sl@0: return 1; sl@0: } sl@0: sl@0: i += this_chunk; sl@0: } sl@0: sl@0: if (!g_markup_parse_context_end_parse (context, NULL)) sl@0: { sl@0: g_markup_parse_context_free (context); sl@0: return 1; sl@0: } sl@0: sl@0: g_markup_parse_context_free (context); sl@0: sl@0: return 0; sl@0: } sl@0: sl@0: static int sl@0: test_file (const gchar *filename) sl@0: { sl@0: gchar *contents; sl@0: gsize length; sl@0: GError *error; sl@0: GMarkupParseContext *context; sl@0: sl@0: error = NULL; sl@0: if (!g_file_get_contents (filename, sl@0: &contents, sl@0: &length, sl@0: &error)) sl@0: { sl@0: fprintf (stderr, "%s\n", error->message); sl@0: g_error_free (error); sl@0: return 1; sl@0: } sl@0: sl@0: context = g_markup_parse_context_new (&parser, 0, NULL, NULL); sl@0: sl@0: if (!g_markup_parse_context_parse (context, contents, length, NULL)) sl@0: { sl@0: g_markup_parse_context_free (context); sl@0: return 1; sl@0: } sl@0: sl@0: if (!g_markup_parse_context_end_parse (context, NULL)) sl@0: { sl@0: g_markup_parse_context_free (context); sl@0: return 1; sl@0: } sl@0: sl@0: g_markup_parse_context_free (context); sl@0: sl@0: /* A byte at a time */ sl@0: if (test_in_chunks (contents, length, 1) != 0) sl@0: return 1; sl@0: sl@0: /* 2 bytes */ sl@0: if (test_in_chunks (contents, length, 2) != 0) sl@0: return 1; sl@0: sl@0: /*5 bytes */ sl@0: if (test_in_chunks (contents, length, 5) != 0) sl@0: return 1; sl@0: sl@0: /* 12 bytes */ sl@0: if (test_in_chunks (contents, length, 12) != 0) sl@0: return 1; sl@0: sl@0: /* 1024 bytes */ sl@0: if (test_in_chunks (contents, length, 1024) != 0) sl@0: return 1; sl@0: sl@0: return 0; sl@0: } sl@0: sl@0: int sl@0: main (int argc, sl@0: char *argv[]) sl@0: { sl@0: int retval; sl@0: sl@0: #ifdef __SYMBIAN32__ sl@0: 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); sl@0: g_set_print_handler(mrtPrintHandler); sl@0: #endif /*__SYMBIAN32__*/ sl@0: sl@0: if (argc > 1) sl@0: { sl@0: retval = test_file (argv[1]); sl@0: #ifdef __SYMBIAN32__ sl@0: testResultXml("markup-test"); sl@0: #endif /* EMULATOR */ sl@0: return retval; sl@0: } sl@0: else sl@0: { sl@0: fprintf (stderr, "Give a markup file on the command line\n"); sl@0: return 1; sl@0: } sl@0: } sl@0: