[glib/wip/tingping/gsocket-unknown-error] WIP: gsocketclient: Add test of unknown error



commit 04066c5176243c96f3aa0a81bed35ad3f0e859cd
Author: Patrick Griffis <tingping tingping se>
Date:   Sat Nov 23 11:42:16 2019 -0800

    WIP: gsocketclient: Add test of unknown error

 gio/tests/gsocketclient.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 gio/tests/meson.build     |  1 +
 2 files changed, 47 insertions(+)
---
diff --git a/gio/tests/gsocketclient.c b/gio/tests/gsocketclient.c
new file mode 100644
index 000000000..7a9d515ca
--- /dev/null
+++ b/gio/tests/gsocketclient.c
@@ -0,0 +1,46 @@
+#include "config.h"
+#include "mock-resolver.h"
+
+#include <gio/gio.h>
+
+static void
+on_connected (GObject *client, GAsyncResult *res, gpointer user_data)
+{
+  GError *error = NULL;
+  GSocketConnection *connection = g_socket_client_connect_finish (G_SOCKET_CLIENT (client), res, &error);
+  g_main_loop_quit (user_data);
+  g_assert_no_error (error);
+  g_assert_nonnull (connection);
+}
+
+static void
+test_out_of_addresses (void)
+{
+  GMainLoop *loop = g_main_loop_new (NULL, FALSE);
+  GSocketClient *client = g_socket_client_new ();
+  GSocketConnectable *connectable = g_network_address_new ("gnome.fake", 1234);
+  GResolver *original_resolver = g_resolver_get_default ();
+  MockResolver *mock_resolver = mock_resolver_new ();
+  GList *ipv4_results = NULL;
+
+  g_resolver_set_default (G_RESOLVER (mock_resolver));
+  ipv4_results = g_list_append (ipv4_results, g_inet_address_new_from_string ("123.123.123.123"));
+  mock_resolver_set_ipv4_results (mock_resolver, ipv4_results);
+  mock_resolver_set_ipv4_delay_ms (mock_resolver, 100);
+
+  g_socket_client_set_timeout (client, 5);
+  g_socket_client_connect_async (client, connectable, NULL, on_connected, loop);
+  g_main_loop_run (loop);
+
+  // FIXME: cleanup
+}
+
+int
+main (int argc, char *argv[])
+{
+  g_test_init (&argc, &argv, NULL);
+  g_test_bug_base ("https://gitlab.gnome.org/GNOME/glib/";);
+
+  g_test_add_func ("/socket-client/basic", test_out_of_addresses);
+  return g_test_run ();
+}
diff --git a/gio/tests/meson.build b/gio/tests/meson.build
index 8b5d105f5..32f10e294 100644
--- a/gio/tests/meson.build
+++ b/gio/tests/meson.build
@@ -79,6 +79,7 @@ gio_tests = {
   'tls-interaction' : {'extra_sources' : ['gtesttlsbackend.c']},
   'tls-database' : {'extra_sources' : ['gtesttlsbackend.c']},
   'gdbus-address-get-session' : {},
+  'gsocketclient' : {'extra_sources' : ['mock-resolver.c']},
 }
 
 test_extra_programs = {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]