mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-16 09:16:15 +01:00
Move markup collect tests to the test framework
This commit is contained in:
parent
13ac9f94fd
commit
c4dd9fa41b
@ -134,6 +134,9 @@ markup_escape_LDADD = $(progs_ldadd)
|
|||||||
TEST_PROGS += logging
|
TEST_PROGS += logging
|
||||||
logging_LDADD = $(progs_ldadd)
|
logging_LDADD = $(progs_ldadd)
|
||||||
|
|
||||||
|
TEST_PROGS += markup-collect
|
||||||
|
markup_collect_LDADD = $(progs_ldadd)
|
||||||
|
|
||||||
if OS_UNIX
|
if OS_UNIX
|
||||||
|
|
||||||
# some testing of gtester funcitonality
|
# some testing of gtester funcitonality
|
||||||
|
@ -135,25 +135,11 @@ static struct test tests[] =
|
|||||||
G_MARKUP_ERROR_INVALID_CONTENT, "'mb'" }
|
G_MARKUP_ERROR_INVALID_CONTENT, "'mb'" }
|
||||||
};
|
};
|
||||||
|
|
||||||
int
|
static void
|
||||||
main (int argc, char **argv)
|
test_collect (gconstpointer d)
|
||||||
{
|
{
|
||||||
gboolean verbose = FALSE;
|
const struct test *test = d;
|
||||||
int i;
|
|
||||||
|
|
||||||
if (argc > 1)
|
|
||||||
{
|
|
||||||
if (argc != 2 || strcmp (argv[1], "-v") != 0)
|
|
||||||
{
|
|
||||||
g_print ("error: call with no arguments or '-v' for verbose\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
verbose = TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < G_N_ELEMENTS (tests); i++)
|
|
||||||
{
|
|
||||||
GMarkupParseContext *ctx;
|
GMarkupParseContext *ctx;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
GString *string;
|
GString *string;
|
||||||
@ -162,60 +148,41 @@ main (int argc, char **argv)
|
|||||||
string = g_string_new ("");
|
string = g_string_new ("");
|
||||||
ctx = g_markup_parse_context_new (&parser, 0, string, NULL);
|
ctx = g_markup_parse_context_new (&parser, 0, string, NULL);
|
||||||
result = g_markup_parse_context_parse (ctx,
|
result = g_markup_parse_context_parse (ctx,
|
||||||
tests[i].document,
|
test->document,
|
||||||
-1, &error);
|
-1, &error);
|
||||||
if (result)
|
if (result)
|
||||||
result = g_markup_parse_context_end_parse (ctx, &error);
|
result = g_markup_parse_context_end_parse (ctx, &error);
|
||||||
|
|
||||||
if (verbose)
|
|
||||||
g_print ("%d: %s:\n (error %d, \"%s\")\n %s\n\n",
|
|
||||||
i, tests[i].document,
|
|
||||||
error ? error->code : 0,
|
|
||||||
error ? error->message : "(no error)",
|
|
||||||
string->str);
|
|
||||||
|
|
||||||
if (result)
|
if (result)
|
||||||
{
|
{
|
||||||
if (error != NULL)
|
g_assert_no_error (error);
|
||||||
g_error ("parser successful but error is set: "
|
g_assert_cmpint (test->error_code, ==, 0);
|
||||||
"%s(%d) '%s'", g_quark_to_string (error->domain),
|
g_assert_cmpstr (test->result, ==, string->str);
|
||||||
error->code, error->message);
|
|
||||||
|
|
||||||
if (tests[i].error_code != 0)
|
|
||||||
g_error ("parser succeeded on test %d ('%s') but "
|
|
||||||
"we expected a failure with code %d\n", i,
|
|
||||||
tests[i].document, tests[i].error_code);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (error->domain != G_MARKUP_ERROR)
|
g_assert_error (error, G_MARKUP_ERROR, test->error_code);
|
||||||
g_error ("error occured on test %d ('%s') but is not in "
|
|
||||||
"the GMarkupError domain, but rather '%s'", i,
|
|
||||||
tests[i].document, g_quark_to_string (error->domain));
|
|
||||||
|
|
||||||
if (error->code != tests[i].error_code)
|
|
||||||
g_error ("failure expected with test %d ('%s') but it "
|
|
||||||
"has error code %d (we expected code %d)", i,
|
|
||||||
tests[i].document, error->code, tests[i].error_code);
|
|
||||||
|
|
||||||
if (strstr (error->message, tests[i].error_info) == NULL)
|
|
||||||
g_error ("failure message on test %d ('%s') fails "
|
|
||||||
"to mention '%s' in the error message", i,
|
|
||||||
tests[i].document, tests[i].error_info);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp (tests[i].result, string->str) != 0)
|
|
||||||
g_error ("result on test %d ('%s') expected to be '%s' "
|
|
||||||
"but came out as '%s'", i, tests[i].document,
|
|
||||||
tests[i].result, string->str);
|
|
||||||
|
|
||||||
g_markup_parse_context_free (ctx);
|
g_markup_parse_context_free (ctx);
|
||||||
g_string_free (string, TRUE);
|
g_string_free (string, TRUE);
|
||||||
g_clear_error (&error);
|
g_clear_error (&error);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
main (int argc, char **argv)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
gchar *path;
|
||||||
|
|
||||||
|
g_test_init (&argc, &argv, NULL);
|
||||||
|
|
||||||
|
for (i = 0; i < G_N_ELEMENTS (tests); i++)
|
||||||
|
{
|
||||||
|
path = g_strdup_printf ("/markup/collect/%d", i);
|
||||||
|
g_test_add_data_func (path, &tests[i], test_collect);
|
||||||
|
g_free (path);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (verbose)
|
return g_test_run ();
|
||||||
g_print ("\n*** all tests passed ***\n\n");
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user