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 GMarkupParser parser = {
92 start_element_handler,
100 test_in_chunks (const gchar *contents,
104 GMarkupParseContext *context;
107 context = g_markup_parse_context_new (&parser, 0, NULL, NULL);
111 int this_chunk = MIN (length - i, chunk_size);
113 if (!g_markup_parse_context_parse (context,
118 g_markup_parse_context_free (context);
125 if (!g_markup_parse_context_end_parse (context, NULL))
127 g_markup_parse_context_free (context);
131 g_markup_parse_context_free (context);
137 test_file (const gchar *filename)
142 GMarkupParseContext *context;
145 if (!g_file_get_contents (filename,
150 fprintf (stderr, "%s\n", error->message);
151 g_error_free (error);
155 context = g_markup_parse_context_new (&parser, 0, NULL, NULL);
157 if (!g_markup_parse_context_parse (context, contents, length, NULL))
159 g_markup_parse_context_free (context);
163 if (!g_markup_parse_context_end_parse (context, NULL))
165 g_markup_parse_context_free (context);
169 g_markup_parse_context_free (context);
171 /* A byte at a time */
172 if (test_in_chunks (contents, length, 1) != 0)
176 if (test_in_chunks (contents, length, 2) != 0)
180 if (test_in_chunks (contents, length, 5) != 0)
184 if (test_in_chunks (contents, length, 12) != 0)
188 if (test_in_chunks (contents, length, 1024) != 0)
199 return test_file (argv[1]);
202 fprintf (stderr, "Give a markup file on the command line\n");