From 8246bf4bdebb1a12e40111b483e7d6a474ec6b58 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sat, 31 Jul 2010 00:13:02 -0400 Subject: [PATCH] Improve gdbus test coverage --- gio/tests/gdbus-connection.c | 61 ++++++++++++++++++++-- gio/tests/gdbus-proxy.c | 118 +++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 171 insertions(+), 8 deletions(-) diff --git a/gio/tests/gdbus-connection.c b/gio/tests/gdbus-connection.c index c25bf48..6d3c483 100644 --- a/gio/tests/gdbus-connection.c +++ b/gio/tests/gdbus-connection.c @@ -865,6 +865,56 @@ test_connection_flush (void) session_bus_down (); } +static void +test_connection_basic (void) +{ + GDBusConnection *connection; + GError *error; + GDBusCapabilityFlags flags; + const gchar *guid; + const gchar *name; + gboolean closed; + gboolean exit_on_close; + GIOStream *stream; + GCredentials *credentials; + + session_bus_up (); + + error = NULL; + connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error); + g_assert_no_error (error); + g_assert (connection != NULL); + + flags = g_dbus_connection_get_capabilities (connection); + g_assert (flags == G_DBUS_CAPABILITY_FLAGS_NONE || + flags == G_DBUS_CAPABILITY_FLAGS_UNIX_FD_PASSING); + + credentials = g_dbus_connection_get_peer_credentials (connection); + g_assert (credentials == NULL); + + g_object_get (connection, + "stream", &stream, + "guid", &guid, + "unique-name", &name, + "closed", &closed, + "exit-on-close", &exit_on_close, + "capabilities", &flags, + NULL); + + g_assert (G_IS_IO_STREAM (stream)); + g_assert (g_dbus_is_guid (guid)); + g_assert (g_dbus_is_unique_name (name)); + g_assert (!closed); + g_assert (exit_on_close); + g_assert (flags == G_DBUS_CAPABILITY_FLAGS_NONE || + flags == G_DBUS_CAPABILITY_FLAGS_UNIX_FD_PASSING); + + g_object_unref (stream); + g_object_unref (connection); + + session_bus_down (); +} + /* ---------------------------------------------------------------------------------------------------- */ int @@ -883,10 +933,11 @@ main (int argc, g_unsetenv ("DISPLAY"); g_setenv ("DBUS_SESSION_BUS_ADDRESS", session_bus_get_temporary_address (), TRUE); - g_test_add_func ("/gdbus/connection-life-cycle", test_connection_life_cycle); - g_test_add_func ("/gdbus/connection-send", test_connection_send); - g_test_add_func ("/gdbus/connection-signals", test_connection_signals); - g_test_add_func ("/gdbus/connection-filter", test_connection_filter); - g_test_add_func ("/gdbus/connection-flush", test_connection_flush); + g_test_add_func ("/gdbus/connection/basic", test_connection_basic); + g_test_add_func ("/gdbus/connection/life-cycle", test_connection_life_cycle); + g_test_add_func ("/gdbus/connection/send", test_connection_send); + g_test_add_func ("/gdbus/connection/signals", test_connection_signals); + g_test_add_func ("/gdbus/connection/filter", test_connection_filter); + g_test_add_func ("/gdbus/connection/flush", test_connection_flush); return g_test_run(); } diff --git a/gio/tests/gdbus-proxy.c b/gio/tests/gdbus-proxy.c index 3efef6c..98e0855 100644 --- a/gio/tests/gdbus-proxy.c +++ b/gio/tests/gdbus-proxy.c @@ -126,7 +126,7 @@ test_methods (GDBusProxy *proxy) } static gboolean -strv_equal (const gchar **strv, ...) +strv_equal (gchar **strv, ...) { gint count; va_list list; @@ -151,7 +151,7 @@ strv_equal (const gchar **strv, ...) va_end (list); if (res) - res = g_strv_length ((gchar**)strv) == count; + res = g_strv_length (strv) == count; return res; } @@ -171,6 +171,12 @@ test_properties (GDBusProxy *proxy) error = NULL; + if (g_dbus_proxy_get_flags (proxy) & G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES) + { + g_assert (g_dbus_proxy_get_cached_property_names (proxy) == NULL); + return; + } + /* * Check that we can list all cached properties. */ @@ -200,7 +206,8 @@ test_properties (GDBusProxy *proxy) "t", "u", "x", - "y")); + "y", + NULL)); g_strfreev (names); @@ -491,6 +498,51 @@ test_expected_interface (GDBusProxy *proxy) } static void +test_basic (GDBusProxy *proxy) +{ + GDBusConnection *connection; + GDBusConnection *conn; + GDBusProxyFlags flags; + GDBusInterfaceInfo *info; + const gchar *name; + const gchar *path; + const gchar *interface; + gint timeout; + + connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL); + + g_assert (g_dbus_proxy_get_connection (proxy) == connection); + g_assert (g_dbus_proxy_get_flags (proxy) == G_DBUS_PROXY_FLAGS_NONE); + g_assert (g_dbus_proxy_get_interface_info (proxy) == NULL); + g_assert_cmpstr (g_dbus_proxy_get_name (proxy), ==, "com.example.TestService"); + g_assert_cmpstr (g_dbus_proxy_get_object_path (proxy), ==, "/com/example/TestObject"); + g_assert_cmpstr (g_dbus_proxy_get_interface_name (proxy), ==, "com.example.Frob"); + g_assert_cmpint (g_dbus_proxy_get_default_timeout (proxy), ==, -1); + + g_object_get (proxy, + "g-connection", &conn, + "g-interface-info", &info, + "g-flags", &flags, + "g-name", &name, + "g-object-path", &path, + "g-interface-name", &interface, + "g-default-timeout", &timeout, + NULL); + + g_assert (conn == connection); + g_assert (info == NULL); + g_assert_cmpint (flags, ==, G_DBUS_PROXY_FLAGS_NONE); + g_assert_cmpstr (name, ==, "com.example.TestService"); + g_assert_cmpstr (path, ==, "/com/example/TestObject"); + g_assert_cmpstr (interface, ==, "com.example.Frob"); + g_assert_cmpint (timeout, ==, -1); + + g_object_unref (conn); + + g_object_unref (connection); +} + +static void test_proxy (void) { GDBusProxy *proxy; @@ -525,6 +577,7 @@ test_proxy (void) _g_assert_property_notify (proxy, "g-name-owner"); + test_basic (proxy); test_methods (proxy); test_properties (proxy); test_signals (proxy); @@ -536,6 +589,63 @@ test_proxy (void) /* ---------------------------------------------------------------------------------------------------- */ +static void +proxy_ready (GObject *source, + GAsyncResult *result, + gpointer user_data) +{ + GDBusProxy *proxy; + GError *error; + + error = NULL; + proxy = g_dbus_proxy_new_for_bus_finish (result, &error); + g_assert_no_error (error); + + test_basic (proxy); + test_methods (proxy); + test_properties (proxy); + test_signals (proxy); + test_expected_interface (proxy); + + g_object_unref (proxy); +} + +static void +test_async (void) +{ + g_dbus_proxy_new_for_bus (G_BUS_TYPE_SESSION, + G_DBUS_PROXY_FLAGS_NONE, + NULL, /* GDBusInterfaceInfo */ + "com.example.TestService", /* name */ + "/com/example/TestObject", /* object path */ + "com.example.Frob", /* interface */ + NULL, /* GCancellable */ + proxy_ready, + NULL); +} + +static void +test_no_properties (void) +{ + GDBusProxy *proxy; + GError *error; + + error = NULL; + proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION, + G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, + NULL, /* GDBusInterfaceInfo */ + "com.example.TestService", /* name */ + "/com/example/TestObject", /* object path */ + "com.example.Frob", /* interface */ + NULL, /* GCancellable */ + &error); + g_assert_no_error (error); + + test_properties (proxy); + + g_object_unref (proxy); +} + int main (int argc, char *argv[]) @@ -560,6 +670,8 @@ main (int argc, g_setenv ("DBUS_SESSION_BUS_ADDRESS", session_bus_get_temporary_address (), TRUE); g_test_add_func ("/gdbus/proxy", test_proxy); + g_test_add_func ("/gdbus/proxy/async", test_async); + g_test_add_func ("/gdbus/proxy/no-properties", test_no_properties); ret = g_test_run(); -- 2.7.4