diff options
author | DongHun Kwak <dh0128.kwak@samsung.com> | 2021-10-29 10:30:56 +0900 |
---|---|---|
committer | DongHun Kwak <dh0128.kwak@samsung.com> | 2021-10-29 10:30:56 +0900 |
commit | 12500068fcfd930af96d75506201fda8d829220b (patch) | |
tree | 84c49eeeae1de699480669d815d01ad1f5c888d3 /gio/tests/gdbus-peer.c | |
parent | 71ffb6083fde389da869fa671affd9da39c40984 (diff) | |
download | glib-12500068fcfd930af96d75506201fda8d829220b.tar.gz glib-12500068fcfd930af96d75506201fda8d829220b.tar.bz2 glib-12500068fcfd930af96d75506201fda8d829220b.zip |
Imported Upstream version 2.67.0upstream/2.67.0
Diffstat (limited to 'gio/tests/gdbus-peer.c')
-rw-r--r-- | gio/tests/gdbus-peer.c | 394 |
1 files changed, 68 insertions, 326 deletions
diff --git a/gio/tests/gdbus-peer.c b/gio/tests/gdbus-peer.c index a03ebbbbe..ca53528d2 100644 --- a/gio/tests/gdbus-peer.c +++ b/gio/tests/gdbus-peer.c @@ -76,12 +76,6 @@ typedef struct gboolean signal_received; } PeerData; -/* This needs to be enough to usually take more than one write(), - * to reproduce - * <https://gitlab.gnome.org/GNOME/glib/-/issues/2074>. - * 1 MiB ought to be enough. */ -#define BIG_MESSAGE_ARRAY_SIZE (1024 * 1024) - static const gchar *test_interface_introspection_xml = "<node>" " <interface name='org.gtk.GDBus.PeerTestInterface'>" @@ -94,11 +88,6 @@ static const gchar *test_interface_introspection_xml = " <method name='OpenFile'>" " <arg type='s' name='path' direction='in'/>" " </method>" - " <method name='OpenFileWithBigMessage'>" - " <arg type='s' name='path' direction='in'/>" - " <arg type='h' name='handle' direction='out'/>" - " <arg type='ay' name='junk' direction='out'/>" - " </method>" " <signal name='PeerSignal'>" " <arg type='s' name='a_string'/>" " </signal>" @@ -175,8 +164,7 @@ test_interface_method_call (GDBusConnection *connection, g_dbus_method_invocation_return_value (invocation, NULL); } - else if (g_strcmp0 (method_name, "OpenFile") == 0 || - g_strcmp0 (method_name, "OpenFileWithBigMessage") == 0) + else if (g_strcmp0 (method_name, "OpenFile") == 0) { #ifdef G_OS_UNIX const gchar *path; @@ -202,21 +190,6 @@ test_interface_method_call (GDBusConnection *connection, g_object_unref (fd_list); g_object_unref (invocation); - if (g_strcmp0 (method_name, "OpenFileWithBigMessage") == 0) - { - char *junk; - - junk = g_new0 (char, BIG_MESSAGE_ARRAY_SIZE); - g_dbus_message_set_body (reply, - g_variant_new ("(h@ay)", - 0, - g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE, - junk, - BIG_MESSAGE_ARRAY_SIZE, - 1))); - g_free (junk); - } - error = NULL; g_dbus_connection_send_message (connection, reply, @@ -671,7 +644,7 @@ check_connection (gpointer user_data) } } - return FALSE; + return G_SOURCE_REMOVE; } static gboolean @@ -681,7 +654,7 @@ on_do_disconnect_in_idle (gpointer data) g_debug ("GDC %p has ref_count %d", c, G_OBJECT (c)->ref_count); g_dbus_connection_disconnect (c); g_object_unref (c); - return FALSE; + return G_SOURCE_REMOVE; } #endif @@ -750,7 +723,6 @@ do_test_peer (void) const gchar *s; GThread *service_thread; gulong signal_handler_id; - gsize i; memset (&data, '\0', sizeof (PeerData)); data.current_connections = g_ptr_array_new_with_free_func (g_object_unref); @@ -871,116 +843,73 @@ do_test_peer (void) g_assert_cmpint (data.num_method_calls, ==, 3); g_signal_handler_disconnect (proxy, signal_handler_id); - /* - * Check for UNIX fd passing. - * - * The first time through, we use a very simple method call. Note that - * because this does not have a G_VARIANT_TYPE_HANDLE in the message body - * to refer to the fd, it is a GDBus-specific idiom that would not - * interoperate with libdbus or sd-bus - * (see <https://gitlab.gnome.org/GNOME/glib/-/merge_requests/1726>). - * - * The second time, we call a method that returns a fd attached to a - * large message, to reproduce - * <https://gitlab.gnome.org/GNOME/glib/-/issues/2074>. It also happens - * to follow the more usual pattern for D-Bus messages containing a - * G_VARIANT_TYPE_HANDLE to refer to attached fds. - */ - for (i = 0; i < 2; i++) - { + /* check for UNIX fd passing */ #ifdef G_OS_UNIX - GDBusMessage *method_call_message; - GDBusMessage *method_reply_message; - GUnixFDList *fd_list; - gint fd; - gchar *buf; - gsize len; - gchar *buf2; - gsize len2; - const char *testfile = g_test_get_filename (G_TEST_DIST, "file.c", NULL); - const char *method = "OpenFile"; - GVariant *body; - - if (i == 1) - method = "OpenFileWithBigMessage"; - - method_call_message = g_dbus_message_new_method_call (NULL, /* name */ - "/org/gtk/GDBus/PeerTestObject", - "org.gtk.GDBus.PeerTestInterface", - method); - g_dbus_message_set_body (method_call_message, g_variant_new ("(s)", testfile)); - error = NULL; - method_reply_message = g_dbus_connection_send_message_with_reply_sync (c, - method_call_message, - G_DBUS_SEND_MESSAGE_FLAGS_NONE, - -1, - NULL, /* out_serial */ - NULL, /* cancellable */ - &error); - g_assert_no_error (error); - g_assert (g_dbus_message_get_message_type (method_reply_message) == G_DBUS_MESSAGE_TYPE_METHOD_RETURN); - - body = g_dbus_message_get_body (method_reply_message); - - if (i == 1) - { - gint32 handle = -1; - GVariant *junk = NULL; - - g_assert_cmpstr (g_variant_get_type_string (body), ==, "(hay)"); - g_variant_get (body, "(h@ay)", &handle, &junk); - g_assert_cmpint (handle, ==, 0); - g_assert_cmpuint (g_variant_n_children (junk), ==, BIG_MESSAGE_ARRAY_SIZE); - g_variant_unref (junk); - } - else - { - g_assert_null (body); - } - - fd_list = g_dbus_message_get_unix_fd_list (method_reply_message); - g_assert (fd_list != NULL); - g_assert_cmpint (g_unix_fd_list_get_length (fd_list), ==, 1); - error = NULL; - fd = g_unix_fd_list_get (fd_list, 0, &error); - g_assert_no_error (error); - g_object_unref (method_call_message); - g_object_unref (method_reply_message); + { + GDBusMessage *method_call_message; + GDBusMessage *method_reply_message; + GUnixFDList *fd_list; + gint fd; + gchar *buf; + gsize len; + gchar *buf2; + gsize len2; + const char *testfile = g_test_get_filename (G_TEST_DIST, "file.c", NULL); + + method_call_message = g_dbus_message_new_method_call (NULL, /* name */ + "/org/gtk/GDBus/PeerTestObject", + "org.gtk.GDBus.PeerTestInterface", + "OpenFile"); + g_dbus_message_set_body (method_call_message, g_variant_new ("(s)", testfile)); + error = NULL; + method_reply_message = g_dbus_connection_send_message_with_reply_sync (c, + method_call_message, + G_DBUS_SEND_MESSAGE_FLAGS_NONE, + -1, + NULL, /* out_serial */ + NULL, /* cancellable */ + &error); + g_assert_no_error (error); + g_assert (g_dbus_message_get_message_type (method_reply_message) == G_DBUS_MESSAGE_TYPE_METHOD_RETURN); + fd_list = g_dbus_message_get_unix_fd_list (method_reply_message); + g_assert (fd_list != NULL); + g_assert_cmpint (g_unix_fd_list_get_length (fd_list), ==, 1); + error = NULL; + fd = g_unix_fd_list_get (fd_list, 0, &error); + g_assert_no_error (error); + g_object_unref (method_call_message); + g_object_unref (method_reply_message); - error = NULL; - len = 0; - buf = read_all_from_fd (fd, &len, &error); - g_assert_no_error (error); - g_assert (buf != NULL); - close (fd); + error = NULL; + len = 0; + buf = read_all_from_fd (fd, &len, &error); + g_assert_no_error (error); + g_assert (buf != NULL); + close (fd); - error = NULL; - g_file_get_contents (testfile, - &buf2, - &len2, - &error); - g_assert_no_error (error); - g_assert_cmpmem (buf, len, buf2, len2); - g_free (buf2); - g_free (buf); + error = NULL; + g_file_get_contents (testfile, + &buf2, + &len2, + &error); + g_assert_no_error (error); + g_assert_cmpmem (buf, len, buf2, len2); + g_free (buf2); + g_free (buf); + } #else - /* We do the same number of iterations on non-Unix, so that - * the method call count will match. In this case we use - * OpenFile both times, because the difference between this - * and OpenFileWithBigMessage is only relevant on Unix. */ - error = NULL; - result = g_dbus_proxy_call_sync (proxy, - "OpenFile", - g_variant_new ("(s)", "boo"), - G_DBUS_CALL_FLAGS_NONE, - -1, - NULL, /* GCancellable */ - &error); - g_assert_error (error, G_IO_ERROR, G_IO_ERROR_DBUS_ERROR); - g_assert (result == NULL); - g_error_free (error); + error = NULL; + result = g_dbus_proxy_call_sync (proxy, + "OpenFile", + g_variant_new ("(s)", "boo"), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, /* GCancellable */ + &error); + g_assert_error (error, G_IO_ERROR, G_IO_ERROR_DBUS_ERROR); + g_assert (result == NULL); + g_error_free (error); #endif /* G_OS_UNIX */ - } /* Check that g_socket_get_credentials() work - (though this really * should be in socket.c) @@ -1088,7 +1017,7 @@ do_test_peer (void) g_variant_get (result, "(&s)", &s); g_assert_cmpstr (s, ==, "You greeted me with 'Hey Again Peer!'."); g_variant_unref (result); - g_assert_cmpint (data.num_method_calls, ==, 6); + g_assert_cmpint (data.num_method_calls, ==, 5); #if 0 /* TODO: THIS TEST DOESN'T WORK YET */ @@ -1139,183 +1068,6 @@ test_peer (void) /* ---------------------------------------------------------------------------------------------------- */ -#define VALID_GUID "0123456789abcdef0123456789abcdef" - -static void -test_peer_invalid_server (void) -{ - GDBusServer *server; - - if (!g_test_undefined ()) - { - g_test_skip ("Not exercising programming errors"); - return; - } - - if (g_test_subprocess ()) - { - /* This assumes we are not going to run out of GDBusServerFlags - * any time soon */ - server = g_dbus_server_new_sync ("tcp:", (GDBusServerFlags) (1 << 30), - VALID_GUID, - NULL, NULL, NULL); - g_assert_null (server); - } - else - { - g_test_trap_subprocess (NULL, 0, 0); - g_test_trap_assert_failed (); - g_test_trap_assert_stderr ("*CRITICAL*G_DBUS_SERVER_FLAGS_ALL*"); - } -} - -static void -test_peer_invalid_conn_stream_sync (void) -{ - GSocket *sock; - GSocketConnection *socket_conn; - GIOStream *iostream; - GDBusConnection *conn; - - if (!g_test_undefined ()) - { - g_test_skip ("Not exercising programming errors"); - return; - } - - sock = g_socket_new (G_SOCKET_FAMILY_IPV4, - G_SOCKET_TYPE_STREAM, - G_SOCKET_PROTOCOL_TCP, - NULL); - - if (sock == NULL) - { - g_test_skip ("TCP not available?"); - return; - } - - socket_conn = g_socket_connection_factory_create_connection (sock); - g_assert_nonnull (socket_conn); - iostream = G_IO_STREAM (socket_conn); - g_assert_nonnull (iostream); - - if (g_test_subprocess ()) - { - /* This assumes we are not going to run out of GDBusConnectionFlags - * any time soon */ - conn = g_dbus_connection_new_sync (iostream, VALID_GUID, - (GDBusConnectionFlags) (1 << 30), - NULL, NULL, NULL); - g_assert_null (conn); - } - else - { - g_test_trap_subprocess (NULL, 0, 0); - g_test_trap_assert_failed (); - g_test_trap_assert_stderr ("*CRITICAL*G_DBUS_CONNECTION_FLAGS_ALL*"); - } - - g_clear_object (&sock); - g_clear_object (&socket_conn); -} - -static void -test_peer_invalid_conn_stream_async (void) -{ - GSocket *sock; - GSocketConnection *socket_conn; - GIOStream *iostream; - - if (!g_test_undefined ()) - { - g_test_skip ("Not exercising programming errors"); - return; - } - - sock = g_socket_new (G_SOCKET_FAMILY_IPV4, - G_SOCKET_TYPE_STREAM, - G_SOCKET_PROTOCOL_TCP, - NULL); - - if (sock == NULL) - { - g_test_skip ("TCP not available?"); - return; - } - - socket_conn = g_socket_connection_factory_create_connection (sock); - g_assert_nonnull (socket_conn); - iostream = G_IO_STREAM (socket_conn); - g_assert_nonnull (iostream); - - if (g_test_subprocess ()) - { - g_dbus_connection_new (iostream, VALID_GUID, - (GDBusConnectionFlags) (1 << 30), - NULL, NULL, NULL, NULL); - } - else - { - g_test_trap_subprocess (NULL, 0, 0); - g_test_trap_assert_failed (); - g_test_trap_assert_stderr ("*CRITICAL*G_DBUS_CONNECTION_FLAGS_ALL*"); - } - - g_clear_object (&sock); - g_clear_object (&socket_conn); -} - -static void -test_peer_invalid_conn_addr_sync (void) -{ - GDBusConnection *conn; - - if (!g_test_undefined ()) - { - g_test_skip ("Not exercising programming errors"); - return; - } - - if (g_test_subprocess ()) - { - conn = g_dbus_connection_new_for_address_sync ("tcp:", - (GDBusConnectionFlags) (1 << 30), - NULL, NULL, NULL); - g_assert_null (conn); - } - else - { - g_test_trap_subprocess (NULL, 0, 0); - g_test_trap_assert_failed (); - g_test_trap_assert_stderr ("*CRITICAL*G_DBUS_CONNECTION_FLAGS_ALL*"); - } -} - -static void -test_peer_invalid_conn_addr_async (void) -{ - if (!g_test_undefined ()) - { - g_test_skip ("Not exercising programming errors"); - return; - } - - if (g_test_subprocess ()) - { - g_dbus_connection_new_for_address ("tcp:", - (GDBusConnectionFlags) (1 << 30), - NULL, NULL, NULL, NULL); - } - else - { - g_test_trap_subprocess (NULL, 0, 0); - g_test_trap_assert_failed (); - g_test_trap_assert_stderr ("*CRITICAL*G_DBUS_CONNECTION_FLAGS_ALL*"); - } -} - -/* ---------------------------------------------------------------------------------------------------- */ - static void test_peer_signals (void) { @@ -1967,7 +1719,7 @@ codegen_on_animal_poke (ExampleAnimal *animal, g_assert_not_reached (); out: - return TRUE; /* to indicate that the method was handled */ + return G_DBUS_METHOD_INVOCATION_HANDLED; } /* Runs in thread we created GDBusServer in (since we didn't pass G_DBUS_SERVER_FLAGS_RUN_IN_THREAD) */ @@ -2042,7 +1794,7 @@ static gboolean codegen_quit_mainloop_timeout (gpointer data) { g_main_loop_quit (loop); - return FALSE; + return G_SOURCE_REMOVE; } static void @@ -2187,16 +1939,6 @@ main (int argc, test_interface_introspection_data = introspection_data->interfaces[0]; g_test_add_func ("/gdbus/peer-to-peer", test_peer); - g_test_add_func ("/gdbus/peer-to-peer/invalid/server", - test_peer_invalid_server); - g_test_add_func ("/gdbus/peer-to-peer/invalid/conn/stream/async", - test_peer_invalid_conn_stream_async); - g_test_add_func ("/gdbus/peer-to-peer/invalid/conn/stream/sync", - test_peer_invalid_conn_stream_sync); - g_test_add_func ("/gdbus/peer-to-peer/invalid/conn/addr/async", - test_peer_invalid_conn_addr_async); - g_test_add_func ("/gdbus/peer-to-peer/invalid/conn/addr/sync", - test_peer_invalid_conn_addr_sync); g_test_add_func ("/gdbus/peer-to-peer/signals", test_peer_signals); g_test_add_func ("/gdbus/delayed-message-processing", delayed_message_processing); g_test_add_func ("/gdbus/nonce-tcp", test_nonce_tcp); |