~ubuntu-branches/ubuntu/trusty/glib2.0/trusty-proposed

« back to all changes in this revision

Viewing changes to glib/tests/markup-parse.c

  • Committer: Package Import Robot
  • Author(s): Iain Lane
  • Date: 2014-03-04 13:08:00 UTC
  • mfrom: (1.63.34)
  • Revision ID: package-import@ubuntu.com-20140304130800-6f4fs4s8iri00blg
Tags: 2.39.91-0ubuntu1
* New upstream release 2.39.91
* revert-0001-Improve-GAsyncQueue-test-coverage.patch: Drop, fixed upstream.
* Re-enable test_timer_stop to gather more information about the failure.
* debian/libglib2.0-0.symbols: Update with new symbols in this release. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
108
108
};
109
109
 
110
110
static int
111
 
test_in_chunks (const gchar *contents,
112
 
                gint         length,
113
 
                gint         chunk_size)
 
111
test_in_chunks (const gchar       *contents,
 
112
                gint               length,
 
113
                gint               chunk_size,
 
114
                GMarkupParseFlags  flags)
114
115
{
115
116
  GMarkupParseContext *context;
116
117
  int i = 0;
117
118
  
118
 
  context = g_markup_parse_context_new (&silent_parser, 0, NULL, NULL);
 
119
  context = g_markup_parse_context_new (&silent_parser, flags, NULL, NULL);
119
120
 
120
121
  while (i < length)
121
122
    {
145
146
}
146
147
 
147
148
static int
148
 
test_file (const gchar *filename)
 
149
test_file (const gchar *filename, GMarkupParseFlags flags)
149
150
{
150
151
  gchar *contents;
151
152
  gsize  length;
164
165
      return 1;
165
166
    }
166
167
 
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);
187
188
 
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)
190
191
    {
191
192
      g_free (contents);
192
193
      return 1;
193
194
    }
194
195
 
195
196
  /* 2 bytes */
196
 
  if (test_in_chunks (contents, length, 2) != 0)
 
197
  if (test_in_chunks (contents, length, 2, flags) != 0)
197
198
    {
198
199
      g_free (contents);
199
200
      return 1;
200
201
    }
201
202
 
202
 
  /*5 bytes */
203
 
  if (test_in_chunks (contents, length, 5) != 0)
 
203
  /* 5 bytes */
 
204
  if (test_in_chunks (contents, length, 5, flags) != 0)
204
205
    {
205
206
      g_free (contents);
206
207
      return 1;
207
208
    }
208
209
 
209
210
  /* 12 bytes */
210
 
  if (test_in_chunks (contents, length, 12) != 0)
 
211
  if (test_in_chunks (contents, length, 12, flags) != 0)
211
212
    {
212
213
      g_free (contents);
213
214
      return 1;
214
215
    }
215
216
 
216
217
  /* 1024 bytes */
217
 
  if (test_in_chunks (contents, length, 1024) != 0)
 
218
  if (test_in_chunks (contents, length, 1024, flags) != 0)
218
219
    {
219
220
      g_free (contents);
220
221
      return 1;
226
227
}
227
228
 
228
229
static gchar *
229
 
get_expected_filename (const gchar *filename)
 
230
get_expected_filename (const gchar       *filename,
 
231
                       GMarkupParseFlags  flags)
230
232
{
231
233
  gchar *f, *p, *expected;
232
234
 
234
236
  p = strstr (f, ".gmarkup");
235
237
  if (p)
236
238
    *p = 0;
237
 
  expected = g_strconcat (f, ".expected", NULL);
 
239
  if (flags == 0)
 
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);
 
243
 
238
244
  g_free (f);
239
245
 
240
246
  return expected;
246
252
  const gchar *filename = d;
247
253
  gchar *expected_file;
248
254
  gchar *expected;
 
255
  gboolean valid_input;
249
256
  GError *error = NULL;
250
257
  gint res;
251
258
 
 
259
  valid_input = strstr (filename, "valid") != NULL;
 
260
  expected_file = get_expected_filename (filename, 0);
 
261
 
252
262
  depth = 0;
253
263
  string = g_string_sized_new (0);
254
264
 
255
 
  res = test_file (filename);
256
 
 
257
 
  if (strstr (filename, "valid"))
258
 
    g_assert_cmpint (res, ==, 0);
259
 
  else
260
 
    g_assert_cmpint (res, ==, 1);
261
 
 
262
 
  expected_file = get_expected_filename (filename);
 
265
  res = test_file (filename, 0);
 
266
  g_assert_cmpint (res, ==, valid_input ? 0 : 1);
 
267
 
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);
268
272
 
269
273
  g_string_free (string, TRUE);
 
274
 
 
275
  g_free (expected_file);
 
276
 
 
277
  expected_file = get_expected_filename (filename, G_MARKUP_TREAT_CDATA_AS_TEXT);
 
278
  if (g_file_test (expected_file, G_FILE_TEST_EXISTS))
 
279
    {
 
280
      depth = 0;
 
281
      string = g_string_sized_new (0);
 
282
 
 
283
      res = test_file (filename, G_MARKUP_TREAT_CDATA_AS_TEXT);
 
284
      g_assert_cmpint (res, ==, valid_input ? 0 : 1);
 
285
 
 
286
      g_file_get_contents (expected_file, &expected, NULL, &error);
 
287
      g_assert_no_error (error);
 
288
      g_assert_cmpstr (string->str, ==, expected);
 
289
      g_free (expected);
 
290
 
 
291
      g_string_free (string, TRUE);
 
292
    }
 
293
 
 
294
  g_free (expected_file);
270
295
}
271
296
 
272
297
int
285
310
  /* allow to easily generate expected output for new test cases */
286
311
  if (argc > 1)
287
312
    {
 
313
      gint arg = 1;
 
314
      GMarkupParseFlags flags = 0;
 
315
 
 
316
      if (strcmp (argv[1], "--cdata-as-text") == 0)
 
317
        {
 
318
          flags = G_MARKUP_TREAT_CDATA_AS_TEXT;
 
319
          arg = 2;
 
320
        }
288
321
      string = g_string_sized_new (0);
289
 
      test_file (argv[1]);
 
322
      test_file (argv[arg], flags);
290
323
      g_print ("%s", string->str);
291
324
      return 0;
292
325
    }
298
331
  g_assert_no_error (error);
299
332
  while ((name = g_dir_read_name (dir)) != NULL)
300
333
    {
301
 
      if (strstr (name, "expected"))
 
334
      if (!strstr (name, "gmarkup"))
302
335
        continue;
303
336
 
304
337
      path = g_strdup_printf ("/markup/parse/%s", name);