111
test_in_chunks (const gchar *contents,
111
test_in_chunks (const gchar *contents,
114
GMarkupParseFlags flags)
115
116
GMarkupParseContext *context;
118
context = g_markup_parse_context_new (&silent_parser, 0, NULL, NULL);
119
context = g_markup_parse_context_new (&silent_parser, flags, NULL, NULL);
120
121
while (i < length)
167
context = g_markup_parse_context_new (&parser, 0, NULL, NULL);
168
context = g_markup_parse_context_new (&parser, flags, NULL, NULL);
168
169
g_assert (g_markup_parse_context_get_user_data (context) == NULL);
169
170
g_markup_parse_context_get_position (context, &line, &col);
170
171
g_assert (line == 1 && col == 1);
186
187
g_markup_parse_context_free (context);
188
189
/* A byte at a time */
189
if (test_in_chunks (contents, length, 1) != 0)
190
if (test_in_chunks (contents, length, 1, flags) != 0)
191
192
g_free (contents);
196
if (test_in_chunks (contents, length, 2) != 0)
197
if (test_in_chunks (contents, length, 2, flags) != 0)
198
199
g_free (contents);
203
if (test_in_chunks (contents, length, 5) != 0)
204
if (test_in_chunks (contents, length, 5, flags) != 0)
205
206
g_free (contents);
210
if (test_in_chunks (contents, length, 12) != 0)
211
if (test_in_chunks (contents, length, 12, flags) != 0)
212
213
g_free (contents);
217
if (test_in_chunks (contents, length, 1024) != 0)
218
if (test_in_chunks (contents, length, 1024, flags) != 0)
219
220
g_free (contents);
234
236
p = strstr (f, ".gmarkup");
237
expected = g_strconcat (f, ".expected", NULL);
240
expected = g_strconcat (f, ".expected", NULL);
241
else if (flags == G_MARKUP_TREAT_CDATA_AS_TEXT)
242
expected = g_strconcat (f, ".cdata-as-text", NULL);
246
252
const gchar *filename = d;
247
253
gchar *expected_file;
255
gboolean valid_input;
249
256
GError *error = NULL;
259
valid_input = strstr (filename, "valid") != NULL;
260
expected_file = get_expected_filename (filename, 0);
253
263
string = g_string_sized_new (0);
255
res = test_file (filename);
257
if (strstr (filename, "valid"))
258
g_assert_cmpint (res, ==, 0);
260
g_assert_cmpint (res, ==, 1);
262
expected_file = get_expected_filename (filename);
265
res = test_file (filename, 0);
266
g_assert_cmpint (res, ==, valid_input ? 0 : 1);
263
268
g_file_get_contents (expected_file, &expected, NULL, &error);
264
269
g_assert_no_error (error);
265
270
g_assert_cmpstr (string->str, ==, expected);
266
271
g_free (expected);
267
g_free (expected_file);
269
273
g_string_free (string, TRUE);
275
g_free (expected_file);
277
expected_file = get_expected_filename (filename, G_MARKUP_TREAT_CDATA_AS_TEXT);
278
if (g_file_test (expected_file, G_FILE_TEST_EXISTS))
281
string = g_string_sized_new (0);
283
res = test_file (filename, G_MARKUP_TREAT_CDATA_AS_TEXT);
284
g_assert_cmpint (res, ==, valid_input ? 0 : 1);
286
g_file_get_contents (expected_file, &expected, NULL, &error);
287
g_assert_no_error (error);
288
g_assert_cmpstr (string->str, ==, expected);
291
g_string_free (string, TRUE);
294
g_free (expected_file);
285
310
/* allow to easily generate expected output for new test cases */
314
GMarkupParseFlags flags = 0;
316
if (strcmp (argv[1], "--cdata-as-text") == 0)
318
flags = G_MARKUP_TREAT_CDATA_AS_TEXT;
288
321
string = g_string_sized_new (0);
322
test_file (argv[arg], flags);
290
323
g_print ("%s", string->str);
298
331
g_assert_no_error (error);
299
332
while ((name = g_dir_read_name (dir)) != NULL)
301
if (strstr (name, "expected"))
334
if (!strstr (name, "gmarkup"))
304
337
path = g_strdup_printf ("/markup/parse/%s", name);