--- server/tests/test-listen.c | 46 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/server/tests/test-listen.c b/server/tests/test-listen.c index 052dc0b8f..562f07487 100644 --- a/server/tests/test-listen.c +++ b/server/tests/test-listen.c @@ -98,7 +98,27 @@ static gpointer check_magic_thread(gpointer data) return NULL; } -static GThread *fake_client_new(const char *hostname, int port) +static gpointer check_no_connect_thread(gpointer data) +{ + GError *error = NULL; + GSocketConnectable *connectable = G_SOCKET_CONNECTABLE(data); + GIOStream *stream; + SpiceTimer *exit_mainloop_timer; + + stream = fake_client_connect(connectable, &error); + g_assert(error != NULL); + g_assert(stream == NULL); + g_clear_error(&error); + + g_object_unref(connectable); + exit_mainloop_timer = core->timer_add(exit_mainloop_cb, NULL); + core->timer_start(exit_mainloop_timer, 0); + + return NULL; +} + + +static GThread *fake_client_new(GThreadFunc thread_func, const char *hostname, int port) { GSocketConnectable *connectable; @@ -107,7 +127,7 @@ static GThread *fake_client_new(const char *hostname, int port) connectable = g_network_address_new(hostname, port); /* check_magic_thread will assume ownership of 'connectable' */ - return g_thread_new("fake-client-thread", check_magic_thread, connectable); + return g_thread_new("fake-client-thread", thread_func, connectable); } static void test_connect_plain(void) @@ -125,7 +145,7 @@ static void test_connect_plain(void) g_assert_cmpint(result, ==, 0); /* fake client */ - thread = fake_client_new("localhost", 5701); + thread = fake_client_new(check_magic_thread, "localhost", 5701); basic_event_loop_mainloop(); @@ -137,10 +157,30 @@ static void test_connect_plain(void) spice_server_destroy(server); } +static void test_connect_ko(void) +{ + GThread *thread; + + core = basic_event_loop_init(); + + /* fake client */ + thread = fake_client_new(check_no_connect_thread, "localhost", 5701); + + basic_event_loop_mainloop(); + + g_assert_null(g_thread_join(thread)); + + g_thread_unref(thread); + basic_event_loop_destroy(); + core = NULL; +} + int main(int argc, char **argv) { g_test_init(&argc, &argv, NULL); + g_test_add_func("/server/listen/connect_plain", test_connect_plain); + g_test_add_func("/server/listen/connect_ko", test_connect_ko); return g_test_run(); } -- 2.14.3 _______________________________________________ Spice-devel mailing list Spice-devel@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/spice-devel