1 #undef G_DISABLE_ASSERT
21 start_element_handler (GMarkupParseContext *context,
22 const gchar *element_name,
23 const gchar **attribute_names,
24 const gchar **attribute_values,
31 printf ("ELEMENT '%s'\n", element_name);
34 while (attribute_names[i] != NULL)
38 printf ("%s=\"%s\"\n",
49 end_element_handler (GMarkupParseContext *context,
50 const gchar *element_name,
56 printf ("END '%s'\n", element_name);
60 text_handler (GMarkupParseContext *context,
67 printf ("TEXT '%.*s'\n", (int)text_len, text);
72 passthrough_handler (GMarkupParseContext *context,
73 const gchar *passthrough_text,
80 printf ("PASS '%.*s'\n", (int)text_len, passthrough_text);
84 error_handler (GMarkupParseContext *context,
88 fprintf (stderr, " %s\n", error->message);
91 static const GMarkupParser parser = {
92 start_element_handler,
99 static const GMarkupParser silent_parser = {
108 test_in_chunks (const gchar *contents,
112 GMarkupParseContext *context;
115 context = g_markup_parse_context_new (&silent_parser, 0, NULL, NULL);
119 int this_chunk = MIN (length - i, chunk_size);
121 if (!g_markup_parse_context_parse (context,
126 g_markup_parse_context_free (context);
133 if (!g_markup_parse_context_end_parse (context, NULL))
135 g_markup_parse_context_free (context);
139 g_markup_parse_context_free (context);
145 test_file (const gchar *filename)
150 GMarkupParseContext *context;
153 if (!g_file_get_contents (filename,
158 fprintf (stderr, "%s\n", error->message);
159 g_error_free (error);
163 context = g_markup_parse_context_new (&parser, 0, NULL, NULL);
165 if (!g_markup_parse_context_parse (context, contents, length, NULL))
167 g_markup_parse_context_free (context);
171 if (!g_markup_parse_context_end_parse (context, NULL))
173 g_markup_parse_context_free (context);
177 g_markup_parse_context_free (context);
179 /* A byte at a time */
180 if (test_in_chunks (contents, length, 1) != 0)
184 if (test_in_chunks (contents, length, 2) != 0)
188 if (test_in_chunks (contents, length, 5) != 0)
192 if (test_in_chunks (contents, length, 12) != 0)
196 if (test_in_chunks (contents, length, 1024) != 0)
207 return test_file (argv[1]);
210 fprintf (stderr, "Give a markup file on the command line\n");