mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-04-22 15:19:16 +02:00
Move uri tests to the test framework
This commit is contained in:
parent
123ba622d3
commit
b720732059
@ -108,6 +108,9 @@ slist_LDADD = $(progs_ldadd)
|
|||||||
TEST_PROGS += tree
|
TEST_PROGS += tree
|
||||||
tree_LDADD = $(progs_ldadd)
|
tree_LDADD = $(progs_ldadd)
|
||||||
|
|
||||||
|
TEST_PROGS += uri
|
||||||
|
uri_LDADD = $(progs_ldadd)
|
||||||
|
|
||||||
if OS_UNIX
|
if OS_UNIX
|
||||||
|
|
||||||
# some testing of gtester funcitonality
|
# some testing of gtester funcitonality
|
||||||
|
@ -24,11 +24,6 @@
|
|||||||
* GLib at ftp://ftp.gtk.org/pub/gtk/.
|
* GLib at ftp://ftp.gtk.org/pub/gtk/.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#undef G_DISABLE_ASSERT
|
|
||||||
#undef G_LOG_DOMAIN
|
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -169,9 +164,6 @@ from_uri_tests[] = {
|
|||||||
{ "file://%2F/", NULL, NULL, G_CONVERT_ERROR_BAD_URI},
|
{ "file://%2F/", NULL, NULL, G_CONVERT_ERROR_BAD_URI},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static gboolean any_failed = FALSE;
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
run_to_uri_tests (void)
|
run_to_uri_tests (void)
|
||||||
{
|
{
|
||||||
@ -186,41 +178,11 @@ run_to_uri_tests (void)
|
|||||||
to_uri_tests[i].hostname,
|
to_uri_tests[i].hostname,
|
||||||
&error);
|
&error);
|
||||||
|
|
||||||
if (to_uri_tests[i].expected_result == NULL)
|
if (res)
|
||||||
{
|
g_assert_cmpstr (res, ==, to_uri_tests[i].expected_result);
|
||||||
if (res != NULL)
|
|
||||||
{
|
|
||||||
g_print ("\ng_filename_to_uri() test %d failed, expected to return NULL, actual result: %s\n", i, res);
|
|
||||||
any_failed = TRUE;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
g_assert_error (error, G_CONVERT_ERROR, to_uri_tests[i].expected_error);
|
||||||
if (error == NULL)
|
|
||||||
{
|
|
||||||
g_print ("\ng_filename_to_uri() test %d failed, returned NULL, but didn't set error\n", i);
|
|
||||||
any_failed = TRUE;
|
|
||||||
}
|
|
||||||
else if (error->domain != G_CONVERT_ERROR)
|
|
||||||
{
|
|
||||||
g_print ("\ng_filename_to_uri() test %d failed, returned NULL, set non G_CONVERT_ERROR error\n", i);
|
|
||||||
any_failed = TRUE;
|
|
||||||
}
|
|
||||||
else if (error->code != to_uri_tests[i].expected_error)
|
|
||||||
{
|
|
||||||
g_print ("\ng_filename_to_uri() test %d failed as expected, but set wrong errorcode %d instead of expected %d \n",
|
|
||||||
i, error->code, to_uri_tests[i].expected_error);
|
|
||||||
any_failed = TRUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (res == NULL || strcmp (res, to_uri_tests[i].expected_result) != 0)
|
|
||||||
{
|
|
||||||
g_print ("\ng_filename_to_uri() test %d failed, expected result: %s, actual result: %s\n",
|
|
||||||
i, to_uri_tests[i].expected_result, (res) ? res : "NULL");
|
|
||||||
if (error)
|
|
||||||
g_print ("Error message: %s\n", error->message);
|
|
||||||
any_failed = TRUE;
|
|
||||||
}
|
|
||||||
g_free (res);
|
g_free (res);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -240,86 +202,33 @@ run_from_uri_tests (void)
|
|||||||
&hostname,
|
&hostname,
|
||||||
&error);
|
&error);
|
||||||
|
|
||||||
if (from_uri_tests[i].expected_filename == NULL)
|
|
||||||
{
|
|
||||||
if (res != NULL)
|
|
||||||
{
|
|
||||||
g_print ("\ng_filename_from_uri() test %d failed, expected to return NULL, actual result: %s\n", i, res);
|
|
||||||
any_failed = TRUE;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (error == NULL)
|
|
||||||
{
|
|
||||||
g_print ("\ng_filename_from_uri() test %d failed, returned NULL, but didn't set error\n", i);
|
|
||||||
any_failed = TRUE;
|
|
||||||
}
|
|
||||||
else if (error->domain != G_CONVERT_ERROR)
|
|
||||||
{
|
|
||||||
g_print ("\ng_filename_from_uri() test %d failed, returned NULL, set non G_CONVERT_ERROR error\n", i);
|
|
||||||
any_failed = TRUE;
|
|
||||||
}
|
|
||||||
else if (error->code != from_uri_tests[i].expected_error)
|
|
||||||
{
|
|
||||||
g_print ("\ng_filename_from_uri() test %d failed as expected, but set wrong errorcode %d instead of expected %d \n",
|
|
||||||
i, error->code, from_uri_tests[i].expected_error);
|
|
||||||
any_failed = TRUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
#ifdef G_OS_WIN32
|
#ifdef G_OS_WIN32
|
||||||
gchar *slash, *p;
|
{
|
||||||
|
gchar *p, *slash;
|
||||||
p = from_uri_tests[i].expected_filename = g_strdup (from_uri_tests[i].expected_filename);
|
p = from_uri_tests[i].expected_filename = g_strdup (from_uri_tests[i].expected_filename);
|
||||||
while ((slash = strchr (p, '/')) != NULL)
|
while ((slash = strchr (p, '/')) != NULL)
|
||||||
{
|
{
|
||||||
*slash = '\\';
|
*slash = '\\';
|
||||||
p = slash + 1;
|
p = slash + 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
if (res == NULL || strcmp (res, from_uri_tests[i].expected_filename) != 0)
|
if (res)
|
||||||
{
|
g_assert_cmpstr (res, ==, from_uri_tests[i].expected_filename);
|
||||||
g_print ("\ng_filename_from_uri() test %d failed, expected result: %s, actual result: %s\n",
|
else
|
||||||
i, from_uri_tests[i].expected_filename, (res) ? res : "NULL");
|
g_assert_error (error, G_CONVERT_ERROR, from_uri_tests[i].expected_error);
|
||||||
any_failed = TRUE;
|
g_assert_cmpstr (hostname, ==, from_uri_tests[i].expected_hostname);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (from_uri_tests[i].expected_hostname == NULL)
|
|
||||||
{
|
|
||||||
if (hostname != NULL)
|
|
||||||
{
|
|
||||||
g_print ("\ng_filename_from_uri() test %d failed, expected no hostname, got: %s\n",
|
|
||||||
i, hostname);
|
|
||||||
any_failed = TRUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (hostname == NULL ||
|
|
||||||
strcmp (hostname, from_uri_tests[i].expected_hostname) != 0)
|
|
||||||
{
|
|
||||||
g_print ("\ng_filename_from_uri() test %d failed, expected hostname: %s, actual result: %s\n",
|
|
||||||
i, from_uri_tests[i].expected_hostname, (hostname) ? hostname : "NULL");
|
|
||||||
any_failed = TRUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static gint
|
|
||||||
safe_strcmp (const gchar *a, const gchar *b)
|
|
||||||
{
|
|
||||||
return strcmp (a ? a : "", b ? b : "");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gint
|
static gint
|
||||||
safe_strcmp_filename (const gchar *a, const gchar *b)
|
safe_strcmp_filename (const gchar *a, const gchar *b)
|
||||||
{
|
{
|
||||||
#ifndef G_OS_WIN32
|
#ifndef G_OS_WIN32
|
||||||
return safe_strcmp (a, b);
|
return g_strcmp0 (a, b);
|
||||||
#else
|
#else
|
||||||
if (!a || !b)
|
if (!a || !b)
|
||||||
return safe_strcmp (a, b);
|
return g_strcmp0 (a, b);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
while (*a && *b)
|
while (*a && *b)
|
||||||
@ -338,13 +247,17 @@ safe_strcmp_filename (const gchar *a, const gchar *b)
|
|||||||
static gint
|
static gint
|
||||||
safe_strcmp_hostname (const gchar *a, const gchar *b)
|
safe_strcmp_hostname (const gchar *a, const gchar *b)
|
||||||
{
|
{
|
||||||
|
if (a == NULL)
|
||||||
|
a = "";
|
||||||
|
if (b == NULL)
|
||||||
|
b = "";
|
||||||
#ifndef G_OS_WIN32
|
#ifndef G_OS_WIN32
|
||||||
return safe_strcmp (a, b);
|
return g_strcmp0 (a, b);
|
||||||
#else
|
#else
|
||||||
if (safe_strcmp (a, "localhost") == 0 && b == NULL)
|
if (g_strcmp0 (a, "localhost") == 0 && b == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
else
|
else
|
||||||
return safe_strcmp (a, b);
|
return g_strcmp0 (a, b);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -364,40 +277,14 @@ run_roundtrip_tests (void)
|
|||||||
uri = g_filename_to_uri (to_uri_tests[i].filename,
|
uri = g_filename_to_uri (to_uri_tests[i].filename,
|
||||||
to_uri_tests[i].hostname,
|
to_uri_tests[i].hostname,
|
||||||
&error);
|
&error);
|
||||||
|
g_assert_no_error (error);
|
||||||
|
|
||||||
if (error != NULL)
|
hostname = NULL;
|
||||||
{
|
|
||||||
g_print ("g_filename_to_uri failed unexpectedly: %s\n",
|
|
||||||
error->message);
|
|
||||||
any_failed = TRUE;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
error = NULL;
|
|
||||||
res = g_filename_from_uri (uri, &hostname, &error);
|
res = g_filename_from_uri (uri, &hostname, &error);
|
||||||
if (error != NULL)
|
g_assert_no_error (error);
|
||||||
{
|
|
||||||
g_print ("g_filename_from_uri failed unexpectedly: %s\n",
|
|
||||||
error->message);
|
|
||||||
any_failed = TRUE;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (safe_strcmp_filename (to_uri_tests[i].filename, res))
|
g_assert (safe_strcmp_filename (to_uri_tests[i].filename, res) == 0);
|
||||||
{
|
g_assert (safe_strcmp_hostname (to_uri_tests[i].hostname, hostname) == 0);
|
||||||
g_print ("roundtrip test %d failed, filename modified: "
|
|
||||||
" expected \"%s\", but got \"%s\"\n",
|
|
||||||
i, to_uri_tests[i].filename, res);
|
|
||||||
any_failed = TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (safe_strcmp_hostname (to_uri_tests[i].hostname, hostname))
|
|
||||||
{
|
|
||||||
g_print ("roundtrip test %d failed, hostname modified: "
|
|
||||||
" expected \"%s\", but got \"%s\"\n",
|
|
||||||
i, to_uri_tests[i].hostname, hostname);
|
|
||||||
any_failed = TRUE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -420,58 +307,27 @@ run_uri_list_tests (void)
|
|||||||
gint j;
|
gint j;
|
||||||
|
|
||||||
uris = g_uri_list_extract_uris (list);
|
uris = g_uri_list_extract_uris (list);
|
||||||
|
g_assert_cmpint (g_strv_length (uris), ==, 3);
|
||||||
if (g_strv_length (uris) != 3)
|
|
||||||
{
|
|
||||||
g_print ("uri list test failed: "
|
|
||||||
" expected %d uris, but got %d\n",
|
|
||||||
3, g_strv_length (uris));
|
|
||||||
any_failed = TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (j = 0; j < 3; j++)
|
for (j = 0; j < 3; j++)
|
||||||
{
|
g_assert_cmpstr (uris[j], ==, expected_uris[j]);
|
||||||
if (safe_strcmp (uris[j], expected_uris[j]))
|
|
||||||
{
|
|
||||||
g_print ("uri list test failed: "
|
|
||||||
" expected \"%s\", but got \"%s\"\n",
|
|
||||||
expected_uris[j], uris[j]);
|
|
||||||
any_failed = TRUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
g_strfreev (uris);
|
g_strfreev (uris);
|
||||||
|
|
||||||
uris = g_uri_list_extract_uris ("# just hot air\r\n# more hot air");
|
uris = g_uri_list_extract_uris ("# just hot air\r\n# more hot air");
|
||||||
if (g_strv_length (uris) != 0)
|
g_assert_cmpint (g_strv_length (uris), ==, 0);
|
||||||
{
|
|
||||||
g_print ("uri list test 2 failed: "
|
|
||||||
" expected %d uris, but got %d (first is \"%s\")\n",
|
|
||||||
0, g_strv_length (uris), uris[0]);
|
|
||||||
any_failed = TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc,
|
main (int argc,
|
||||||
char *argv[])
|
char *argv[])
|
||||||
{
|
{
|
||||||
#ifdef G_OS_UNIX
|
g_test_init (&argc, &argv, NULL);
|
||||||
# ifdef HAVE_UNSETENV
|
|
||||||
unsetenv ("G_BROKEN_FILENAMES");
|
|
||||||
# else
|
|
||||||
/* putenv with no = isn't standard, but works to unset the variable
|
|
||||||
* on some systems
|
|
||||||
*/
|
|
||||||
putenv ("G_BROKEN_FILENAMES");
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
run_to_uri_tests ();
|
g_test_add_func ("/uri/to-uri", run_to_uri_tests);
|
||||||
run_from_uri_tests ();
|
g_test_add_func ("/uri/from-uri", run_from_uri_tests);
|
||||||
run_roundtrip_tests ();
|
g_test_add_func ("/uri/roundtrip", run_roundtrip_tests);
|
||||||
run_uri_list_tests ();
|
g_test_add_func ("/uri/list", run_uri_list_tests);
|
||||||
|
|
||||||
return any_failed ? 1 : 0;
|
return g_test_run ();
|
||||||
}
|
}
|
@ -116,8 +116,7 @@ test_programs = \
|
|||||||
threadpool-test \
|
threadpool-test \
|
||||||
type-test \
|
type-test \
|
||||||
unicode-caseconv \
|
unicode-caseconv \
|
||||||
unicode-encoding \
|
unicode-encoding
|
||||||
uri-test
|
|
||||||
|
|
||||||
test_scripts = run-markup-tests.sh run-collate-tests.sh run-bookmark-test.sh run-assert-msg-test.sh
|
test_scripts = run-markup-tests.sh run-collate-tests.sh run-bookmark-test.sh run-assert-msg-test.sh
|
||||||
|
|
||||||
@ -174,7 +173,6 @@ type_test_LDADD = $(progs_ldadd)
|
|||||||
unicode_encoding_LDADD = $(progs_ldadd)
|
unicode_encoding_LDADD = $(progs_ldadd)
|
||||||
unicode_caseconv_LDADD = $(progs_ldadd)
|
unicode_caseconv_LDADD = $(progs_ldadd)
|
||||||
unicode_collate_LDADD = $(progs_ldadd)
|
unicode_collate_LDADD = $(progs_ldadd)
|
||||||
uri_test_LDADD = $(progs_ldadd)
|
|
||||||
markup_collect_LDADD = $(progs_ldadd)
|
markup_collect_LDADD = $(progs_ldadd)
|
||||||
|
|
||||||
noinst_LTLIBRARIES = libmoduletestplugin_a.la libmoduletestplugin_b.la
|
noinst_LTLIBRARIES = libmoduletestplugin_a.la libmoduletestplugin_b.la
|
||||||
|
Loading…
x
Reference in New Issue
Block a user