static int depth = 0;
static GString *string;
-static const gchar *datapath;
static void
indent (int extra)
};
static int
-test_in_chunks (const gchar *contents,
- gint length,
- gint chunk_size)
+test_in_chunks (const gchar *contents,
+ gint length,
+ gint chunk_size,
+ GMarkupParseFlags flags)
{
GMarkupParseContext *context;
int i = 0;
- context = g_markup_parse_context_new (&silent_parser, 0, NULL, NULL);
+ context = g_markup_parse_context_new (&silent_parser, flags, NULL, NULL);
while (i < length)
{
}
static int
-test_file (const gchar *filename)
+test_file (const gchar *filename, GMarkupParseFlags flags)
{
gchar *contents;
gsize length;
return 1;
}
- context = g_markup_parse_context_new (&parser, 0, NULL, NULL);
+ context = g_markup_parse_context_new (&parser, flags, NULL, NULL);
g_assert (g_markup_parse_context_get_user_data (context) == NULL);
g_markup_parse_context_get_position (context, &line, &col);
g_assert (line == 1 && col == 1);
g_markup_parse_context_free (context);
/* A byte at a time */
- if (test_in_chunks (contents, length, 1) != 0)
+ if (test_in_chunks (contents, length, 1, flags) != 0)
{
g_free (contents);
return 1;
}
/* 2 bytes */
- if (test_in_chunks (contents, length, 2) != 0)
+ if (test_in_chunks (contents, length, 2, flags) != 0)
{
g_free (contents);
return 1;
}
- /*5 bytes */
- if (test_in_chunks (contents, length, 5) != 0)
+ /* 5 bytes */
+ if (test_in_chunks (contents, length, 5, flags) != 0)
{
g_free (contents);
return 1;
}
/* 12 bytes */
- if (test_in_chunks (contents, length, 12) != 0)
+ if (test_in_chunks (contents, length, 12, flags) != 0)
{
g_free (contents);
return 1;
}
/* 1024 bytes */
- if (test_in_chunks (contents, length, 1024) != 0)
+ if (test_in_chunks (contents, length, 1024, flags) != 0)
{
g_free (contents);
return 1;
}
static gchar *
-get_expected_filename (const gchar *filename)
+get_expected_filename (const gchar *filename,
+ GMarkupParseFlags flags)
{
gchar *f, *p, *expected;
p = strstr (f, ".gmarkup");
if (p)
*p = 0;
- expected = g_strconcat (f, ".expected", NULL);
+ if (flags == 0)
+ expected = g_strconcat (f, ".expected", NULL);
+ else if (flags == G_MARKUP_TREAT_CDATA_AS_TEXT)
+ expected = g_strconcat (f, ".cdata-as-text", NULL);
+
g_free (f);
return expected;
const gchar *filename = d;
gchar *expected_file;
gchar *expected;
+ gboolean valid_input;
GError *error = NULL;
gint res;
+ valid_input = strstr (filename, "valid") != NULL;
+ expected_file = get_expected_filename (filename, 0);
+
depth = 0;
string = g_string_sized_new (0);
- res = test_file (filename);
-
- if (strstr (filename, "valid"))
- g_assert_cmpint (res, ==, 0);
- else
- g_assert_cmpint (res, ==, 1);
+ res = test_file (filename, 0);
+ g_assert_cmpint (res, ==, valid_input ? 0 : 1);
- expected_file = get_expected_filename (filename);
g_file_get_contents (expected_file, &expected, NULL, &error);
g_assert_no_error (error);
g_assert_cmpstr (string->str, ==, expected);
g_free (expected);
- g_free (expected_file);
g_string_free (string, TRUE);
+
+ g_free (expected_file);
+
+ expected_file = get_expected_filename (filename, G_MARKUP_TREAT_CDATA_AS_TEXT);
+ if (g_file_test (expected_file, G_FILE_TEST_EXISTS))
+ {
+ depth = 0;
+ string = g_string_sized_new (0);
+
+ res = test_file (filename, G_MARKUP_TREAT_CDATA_AS_TEXT);
+ g_assert_cmpint (res, ==, valid_input ? 0 : 1);
+
+ g_file_get_contents (expected_file, &expected, NULL, &error);
+ g_assert_no_error (error);
+ g_assert_cmpstr (string->str, ==, expected);
+ g_free (expected);
+
+ g_string_free (string, TRUE);
+ }
+
+ g_free (expected_file);
}
int
const gchar *name;
gchar *path;
- if (g_getenv ("G_TEST_DATA"))
- datapath = g_getenv ("G_TEST_DATA");
- else
- datapath = SRCDIR;
-
- g_setenv ("LANG", "en_US.utf-8", TRUE);
+ g_setenv ("LC_ALL", "C", TRUE);
setlocale (LC_ALL, "");
g_test_init (&argc, &argv, NULL);
/* allow to easily generate expected output for new test cases */
if (argc > 1)
{
+ gint arg = 1;
+ GMarkupParseFlags flags = 0;
+
+ if (strcmp (argv[1], "--cdata-as-text") == 0)
+ {
+ flags = G_MARKUP_TREAT_CDATA_AS_TEXT;
+ arg = 2;
+ }
string = g_string_sized_new (0);
- test_file (argv[1]);
+ test_file (argv[arg], flags);
g_print ("%s", string->str);
return 0;
}
error = NULL;
- path = g_build_filename (datapath, "markups", NULL);
+ path = g_test_build_filename (G_TEST_DIST, "markups", NULL);
dir = g_dir_open (path, 0, &error);
g_free (path);
g_assert_no_error (error);
while ((name = g_dir_read_name (dir)) != NULL)
{
- if (strstr (name, "expected"))
+ if (!strstr (name, "gmarkup"))
continue;
path = g_strdup_printf ("/markup/parse/%s", name);
- g_test_add_data_func_full (path, g_build_filename (datapath, "markups", name, NULL),
+ g_test_add_data_func_full (path, g_test_build_filename (G_TEST_DIST, "markups", name, NULL),
test_parse, g_free);
g_free (path);
}