18 start_element_handler (GMarkupParseContext *context,
19 const gchar *element_name,
20 const gchar **attribute_names,
21 const gchar **attribute_values,
28 printf ("ELEMENT '%s'\n", element_name);
31 while (attribute_names[i] != NULL)
35 printf ("%s=\"%s\"\n",
46 end_element_handler (GMarkupParseContext *context,
47 const gchar *element_name,
53 printf ("END '%s'\n", element_name);
57 text_handler (GMarkupParseContext *context,
64 printf ("TEXT '%s'\n", text);
69 passthrough_handler (GMarkupParseContext *context,
70 const gchar *passthrough_text,
77 printf ("PASS '%s'\n", passthrough_text);
81 error_handler (GMarkupParseContext *context,
85 fprintf (stderr, " %s\n", error->message);
88 static GMarkupParser parser = {
89 start_element_handler,
97 test_in_chunks (const gchar *contents,
101 GMarkupParseContext *context;
104 context = g_markup_parse_context_new (&parser, 0, NULL, NULL);
108 int this_chunk = MIN (length - i, chunk_size);
110 if (!g_markup_parse_context_parse (context,
115 g_markup_parse_context_free (context);
122 if (!g_markup_parse_context_end_parse (context, NULL))
124 g_markup_parse_context_free (context);
128 g_markup_parse_context_free (context);
134 test_file (const gchar *filename)
139 GMarkupParseContext *context;
142 if (!g_file_get_contents (filename,
147 fprintf (stderr, "%s\n", error->message);
148 g_error_free (error);
152 context = g_markup_parse_context_new (&parser, 0, NULL, NULL);
154 if (!g_markup_parse_context_parse (context, contents, length, NULL))
156 g_markup_parse_context_free (context);
160 if (!g_markup_parse_context_end_parse (context, NULL))
162 g_markup_parse_context_free (context);
166 g_markup_parse_context_free (context);
168 /* A byte at a time */
169 if (test_in_chunks (contents, length, 1) != 0)
173 if (test_in_chunks (contents, length, 2) != 0)
177 if (test_in_chunks (contents, length, 5) != 0)
181 if (test_in_chunks (contents, length, 12) != 0)
185 if (test_in_chunks (contents, length, 1024) != 0)
196 return test_file (argv[1]);
199 fprintf (stderr, "Give a markup file on the command line\n");