X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=test%2Fcorrupt.c;h=1a7d44607f4e0d86ee5419c6290d0eac19c5a226;hb=16ed767007722d7450e6f5a4e23fff0166f466dc;hp=02495901e86566dcd1f146eae333c1755e55b51c;hpb=88498b706a39bbe520f9591d8d52b54fb1f8e378;p=platform%2Fupstream%2Fdbus.git diff --git a/test/corrupt.c b/test/corrupt.c index 0249590..1a7d446 100644 --- a/test/corrupt.c +++ b/test/corrupt.c @@ -30,10 +30,12 @@ #include #include -#include + +#include "test-utils.h" typedef struct { DBusError e; + TestMainContext *ctx; DBusServer *server; DBusConnection *server_conn; @@ -72,13 +74,14 @@ new_conn_cb (DBusServer *server, g_assert (f->server_conn == NULL); f->server_conn = dbus_connection_ref (server_conn); - dbus_connection_setup_with_g_main (server_conn, NULL); + test_connection_setup (f->ctx, server_conn); } static void setup (Fixture *f, gconstpointer addr) { + f->ctx = test_main_context_get (); dbus_error_init (&f->e); g_queue_init (&f->client_messages); @@ -88,7 +91,7 @@ setup (Fixture *f, dbus_server_set_new_connection_function (f->server, new_conn_cb, f, NULL); - dbus_server_setup_with_g_main (f->server, NULL); + test_server_setup (f->ctx, f->server); } static void @@ -103,12 +106,12 @@ test_connect (Fixture *f, dbus_server_get_address (f->server), &f->e); assert_no_error (&f->e); g_assert (f->client_conn != NULL); - dbus_connection_setup_with_g_main (f->client_conn, NULL); + test_connection_setup (f->ctx, f->client_conn); while (f->server_conn == NULL) { g_print ("."); - g_main_context_iteration (NULL, TRUE); + test_main_context_iterate (f->ctx, TRUE); } have_mem = dbus_connection_add_filter (f->client_conn, @@ -137,7 +140,7 @@ test_message (Fixture *f, while (g_queue_is_empty (&f->client_messages)) { g_print ("."); - g_main_context_iteration (NULL, TRUE); + test_main_context_iterate (f->ctx, TRUE); } g_assert_cmpuint (g_queue_get_length (&f->client_messages), ==, 1); @@ -229,7 +232,7 @@ test_corrupt (Fixture *f, while (g_queue_is_empty (&f->client_messages)) { g_print ("."); - g_main_context_iteration (NULL, TRUE); + test_main_context_iterate (f->ctx, TRUE); } incoming = g_queue_pop_head (&f->client_messages); @@ -246,6 +249,16 @@ test_corrupt (Fixture *f, "/org/freedesktop/DBus/Local"); dbus_message_unref (incoming); + + /* Free the DBusConnection before the GSocket, because GSocket is + * going to close our fd. GSocket tolerates closing an already-closed + * fd, whereas DBusLoop + DBusSocketSetEpoll doesn't. On Unix + * we could use dup() but that isn't portable to Windows :-( + */ + dbus_connection_close (f->server_conn); + dbus_connection_unref (f->server_conn); + f->server_conn = NULL; + g_object_unref (socket); } @@ -308,7 +321,7 @@ test_byte_order (Fixture *f, while (g_queue_is_empty (&f->client_messages)) { g_print ("."); - g_main_context_iteration (NULL, TRUE); + test_main_context_iterate (f->ctx, TRUE); } message = g_queue_pop_head (&f->client_messages); @@ -325,6 +338,12 @@ test_byte_order (Fixture *f, "/org/freedesktop/DBus/Local"); dbus_message_unref (message); + + /* Free the DBusConnection before the GSocket, as above. */ + dbus_connection_close (f->server_conn); + dbus_connection_unref (f->server_conn); + f->server_conn = NULL; + g_object_unref (socket); } @@ -352,6 +371,8 @@ teardown (Fixture *f, dbus_server_unref (f->server); f->server = NULL; } + + test_main_context_unref (f->ctx); } int