mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-25 15:06:14 +01:00
GSimpleProxyResolver: Add test case for broken hostname
https://bugzilla.gnome.org/show_bug.cgi?id=772989
This commit is contained in:
parent
132cf9a9d4
commit
88366621ee
@ -19,6 +19,15 @@
|
||||
|
||||
#include <gio/gio.h>
|
||||
|
||||
static void
|
||||
async_result_cb (GObject *obj,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
{
|
||||
GAsyncResult **result_out = user_data;
|
||||
*result_out = g_object_ref (result);
|
||||
}
|
||||
|
||||
static void
|
||||
test_uris (void)
|
||||
{
|
||||
@ -26,6 +35,51 @@ test_uris (void)
|
||||
gchar *ignore_hosts[2] = { "127.0.0.1", NULL };
|
||||
gchar **proxies;
|
||||
GError *error = NULL;
|
||||
const gchar *uri;
|
||||
gchar *str = NULL;
|
||||
GAsyncResult *result = NULL;
|
||||
|
||||
/* Valid URI. */
|
||||
uri = "http://%E0%B4%A8%E0%B4%B2:80/";
|
||||
resolver = g_simple_proxy_resolver_new (NULL, ignore_hosts);
|
||||
|
||||
proxies = g_proxy_resolver_lookup (resolver, uri, NULL, &error);
|
||||
g_assert_no_error (error);
|
||||
g_strfreev (proxies);
|
||||
|
||||
g_proxy_resolver_lookup_async (resolver, uri, NULL, async_result_cb, &result);
|
||||
while (result == NULL)
|
||||
g_main_context_iteration (NULL, TRUE);
|
||||
proxies = g_proxy_resolver_lookup_finish (resolver, result, &error);
|
||||
g_assert_no_error (error);
|
||||
g_strfreev (proxies);
|
||||
g_clear_object (&result);
|
||||
|
||||
g_object_unref (resolver);
|
||||
|
||||
/* Invalid URI. */
|
||||
uri = "%E0%B4%A8%E0%B4%B2";
|
||||
str = g_strdup_printf ("Invalid URI ‘%s’", uri);
|
||||
resolver = g_simple_proxy_resolver_new (NULL, ignore_hosts);
|
||||
|
||||
proxies = g_proxy_resolver_lookup (resolver, uri, NULL, &error);
|
||||
g_assert_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT);
|
||||
g_assert_cmpstr (error->message, ==, str);
|
||||
g_clear_error (&error);
|
||||
g_assert_null (proxies);
|
||||
g_clear_object (&result);
|
||||
|
||||
g_proxy_resolver_lookup_async (resolver, uri, NULL, async_result_cb, &result);
|
||||
while (result == NULL)
|
||||
g_main_context_iteration (NULL, TRUE);
|
||||
proxies = g_proxy_resolver_lookup_finish (resolver, result, &error);
|
||||
g_assert_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT);
|
||||
g_assert_cmpstr (error->message, ==, str);
|
||||
g_clear_error (&error);
|
||||
g_assert_null (proxies);
|
||||
|
||||
g_object_unref (resolver);
|
||||
g_free (str);
|
||||
|
||||
resolver = g_simple_proxy_resolver_new ("default://", ignore_hosts);
|
||||
g_simple_proxy_resolver_set_uri_proxy (G_SIMPLE_PROXY_RESOLVER (resolver),
|
||||
|
Loading…
Reference in New Issue
Block a user