diff options
author | Ted Gould <ted@gould.cx> | 2010-02-19 16:19:14 -0600 |
---|---|---|
committer | Ted Gould <ted@gould.cx> | 2010-02-19 16:19:14 -0600 |
commit | 96f2eb92c8ce54792cd48d3f8a558074b8132b92 (patch) | |
tree | 9dd0c789a01d51560fda661aab38197403b8c8ba /tests | |
parent | 435edba2721a55712c440bbc71fd47911680453d (diff) | |
parent | 7e683f7476324dd4490a6b6ec0dbd27fcd47c4da (diff) | |
download | ayatana-indicator-application-96f2eb92c8ce54792cd48d3f8a558074b8132b92.tar.gz ayatana-indicator-application-96f2eb92c8ce54792cd48d3f8a558074b8132b92.tar.bz2 ayatana-indicator-application-96f2eb92c8ce54792cd48d3f8a558074b8132b92.zip |
Improving the dbus tests so that they have a mock watcher in them.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test-libappindicator-dbus-client.c | 32 | ||||
-rw-r--r-- | tests/test-libappindicator-dbus-server.c | 1 | ||||
-rw-r--r-- | tests/test-libappindicator-status-client.c | 30 |
3 files changed, 63 insertions, 0 deletions
diff --git a/tests/test-libappindicator-dbus-client.c b/tests/test-libappindicator-dbus-client.c index 6125d36..f5482aa 100644 --- a/tests/test-libappindicator-dbus-client.c +++ b/tests/test-libappindicator-dbus-client.c @@ -23,9 +23,13 @@ with this program. If not, see <http://www.gnu.org/licenses/>. #include <glib.h> #include <dbus/dbus-glib.h> +#include <dbus/dbus-glib-bindings.h> +#include <dbus/dbus-glib-lowlevel.h> #include <libappindicator/app-indicator.h> #include "test-defines.h" +#include "../src/dbus-shared.h" + static GMainLoop * mainloop = NULL; static gboolean passed = TRUE; static int propcount = 0; @@ -184,6 +188,19 @@ kill_func (gpointer userdata) return FALSE; } +static DBusHandlerResult +dbus_filter (DBusConnection * connection, DBusMessage * message, void * user_data) +{ + if (dbus_message_is_method_call(message, NOTIFICATION_WATCHER_DBUS_ADDR, "RegisterStatusNotifierItem")) { + DBusMessage * reply = dbus_message_new_method_return(message); + dbus_connection_send(connection, reply, NULL); + dbus_message_unref(reply); + return DBUS_HANDLER_RESULT_HANDLED; + } + + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; +} + gint main (gint argc, gchar * argv[]) { @@ -198,6 +215,21 @@ main (gint argc, gchar * argv[]) return 1; } + DBusGProxy * bus_proxy = dbus_g_proxy_new_for_name(session_bus, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS); + guint nameret = 0; + + if (!org_freedesktop_DBus_request_name(bus_proxy, NOTIFICATION_WATCHER_DBUS_ADDR, 0, &nameret, &error)) { + g_error("Unable to call to request name"); + return 1; + } + + if (nameret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) { + g_error("Unable to get name"); + return 1; + } + + dbus_connection_add_filter(dbus_g_connection_get_connection(session_bus), dbus_filter, NULL, NULL); + DBusGProxy * props = dbus_g_proxy_new_for_name_owner(session_bus, ":1.0", "/org/ayatana/NotificationItem/my_id", diff --git a/tests/test-libappindicator-dbus-server.c b/tests/test-libappindicator-dbus-server.c index 76f0e50..2d68950 100644 --- a/tests/test-libappindicator-dbus-server.c +++ b/tests/test-libappindicator-dbus-server.c @@ -44,6 +44,7 @@ main (gint argc, gchar * argv[]) g_debug("DBus ID: %s", dbus_connection_get_server_id(dbus_g_connection_get_connection(dbus_g_bus_get(DBUS_BUS_SESSION, NULL)))); AppIndicator * ci = app_indicator_new (TEST_ID, TEST_ICON_NAME, TEST_CATEGORY); + app_indicator_set_status (ci, TEST_STATE); app_indicator_set_attention_icon (ci, TEST_ATTENTION_ICON_NAME); diff --git a/tests/test-libappindicator-status-client.c b/tests/test-libappindicator-status-client.c index 55d85a2..acf4fca 100644 --- a/tests/test-libappindicator-status-client.c +++ b/tests/test-libappindicator-status-client.c @@ -23,6 +23,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>. #include <glib.h> #include <dbus/dbus-glib.h> +#include <dbus/dbus-glib-bindings.h> #include <dbus/dbus-glib-lowlevel.h> #include "../src/dbus-shared.h" @@ -37,6 +38,20 @@ static guint toggle_count = 0; #define ATTN_STR "NeedsAttention" static DBusHandlerResult +dbus_reg_filter (DBusConnection * connection, DBusMessage * message, void * user_data) +{ + if (dbus_message_is_method_call(message, NOTIFICATION_WATCHER_DBUS_ADDR, "RegisterStatusNotifierItem")) { + DBusMessage * reply = dbus_message_new_method_return(message); + dbus_connection_send(connection, reply, NULL); + dbus_message_unref(reply); + return DBUS_HANDLER_RESULT_HANDLED; + } + + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; +} + + +static DBusHandlerResult dbus_filter (DBusConnection * connection, DBusMessage * message, void * user_data) { if (!dbus_message_is_signal(message, NOTIFICATION_ITEM_DBUS_IFACE, "NewStatus")) { @@ -103,6 +118,21 @@ main (gint argc, gchar * argv[]) return 1; } + DBusGProxy * bus_proxy = dbus_g_proxy_new_for_name(session_bus, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS); + guint nameret = 0; + + if (!org_freedesktop_DBus_request_name(bus_proxy, NOTIFICATION_WATCHER_DBUS_ADDR, 0, &nameret, &error)) { + g_error("Unable to call to request name"); + return 1; + } + + if (nameret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) { + g_error("Unable to get name"); + return 1; + } + + dbus_connection_add_filter(dbus_g_connection_get_connection(session_bus), dbus_reg_filter, NULL, NULL); + dbus_connection_add_filter(dbus_g_connection_get_connection(session_bus), dbus_filter, NULL, NULL); dbus_bus_add_match(dbus_g_connection_get_connection(session_bus), "type='signal',interface='" NOTIFICATION_ITEM_DBUS_IFACE "',member='NewStatus'", NULL); |