diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile.am | 27 | ||||
-rw-r--r-- | tests/test-interests-client.c | 63 | ||||
-rw-r--r-- | tests/test-interests-server.c | 45 | ||||
-rwxr-xr-x | tests/test_interests | 5 |
4 files changed, 139 insertions, 1 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index 36818b8..256a699 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,8 +1,11 @@ TESTS = \ - test_simple + test_simple \ + test_interests libexec_PROGRAMS = \ + test-interests-client \ + test-interests-server \ test-simple-client \ test-simple-server @@ -31,3 +34,25 @@ test_simple_server_LDADD = \ ../libindicate/libindicate.la \ $(LIBINDICATE_LIBS) +test_interests: test-interests-client test-interests-server + +test_interests_client_SOURCES = \ + test-interests-client.c + +test_interests_client_CFLAGS = \ + $(LIBINDICATE_CFLAGS) -I$(srcdir)/.. + +test_interests_client_LDADD = \ + ../libindicate/libindicate.la \ + $(LIBINDICATE_LIBS) + +test_interests_server_SOURCES = \ + test-interests-server.c + +test_interests_server_CFLAGS = \ + $(LIBINDICATE_CFLAGS) -I$(srcdir)/.. + +test_interests_server_LDADD = \ + ../libindicate/libindicate.la \ + $(LIBINDICATE_LIBS) + diff --git a/tests/test-interests-client.c b/tests/test-interests-client.c new file mode 100644 index 0000000..0fe8587 --- /dev/null +++ b/tests/test-interests-client.c @@ -0,0 +1,63 @@ + +#include <glib.h> +#include "libindicate/indicator.h" +#include "libindicate/server.h" +#include "libindicate/interests.h" + +static gboolean passed = TRUE; +static GMainLoop * mainloop = NULL; +static gboolean interests[INDICATE_INTEREST_LAST] = {0}; + +static gboolean +check_interests (void) +{ + guint i; + for (i = INDICATE_INTEREST_NONE; i < INDICATE_INTEREST_LAST; i++) { + if (!interests[i]) { + return FALSE; + } + } + + return TRUE; +} + +static void +interest_added (IndicateServer * server, IndicateInterests interest) +{ + g_debug("Oh, someone is interested in my for: %d", interest); + interests[interest] = TRUE; + + if (check_interests()) { + g_main_loop_quit(mainloop); + } + + return; +} + +static gboolean +done_timeout_cb (gpointer data) +{ + g_debug("All interests not set"); + passed = FALSE; + g_main_loop_quit(mainloop); + return FALSE; +} + +int +main (int argc, char * argv) +{ + g_type_init(); + + IndicateIndicator * indicator = indicate_indicator_new(); + indicate_indicator_show(indicator); + + IndicateServer * server = indicate_server_ref_default(); + g_signal_connect(G_OBJECT(server), INDICATE_SERVER_SIGNAL_INTEREST_ADDED, G_CALLBACK(interest_added), NULL); + + g_timeout_add_seconds(10, done_timeout_cb, indicator); + + mainloop = g_main_loop_new(NULL, FALSE); + g_main_loop_run(mainloop); + + return !passed; +} diff --git a/tests/test-interests-server.c b/tests/test-interests-server.c new file mode 100644 index 0000000..82cab3c --- /dev/null +++ b/tests/test-interests-server.c @@ -0,0 +1,45 @@ + +#include <glib.h> +#include "libindicate/listener.h" + +static gboolean passed = TRUE; +static GMainLoop * mainloop = NULL; + +static void +server_added (IndicateListener * listener, IndicateListenerServer * server, gchar * type, gpointer data) +{ + g_debug("Indicator Server Added: %s %s", INDICATE_LISTENER_SERVER_DBUS_NAME(server), type); + + guint i; + for (i = INDICATE_INTEREST_NONE; i < INDICATE_INTEREST_LAST; i++) { + g_debug("Indicating Interests: %d", i); + indicate_listener_server_show_interest(listener, server, i); + } + + return; +} + +static gboolean +failed_cb (gpointer data) +{ + g_debug("Done indicatating interest"); + g_main_loop_quit(mainloop); + return FALSE; +} + +int +main (int argc, char * argv) +{ + g_type_init(); + + IndicateListener * listener = indicate_listener_ref_default(); + + g_signal_connect(listener, INDICATE_LISTENER_SIGNAL_SERVER_ADDED, G_CALLBACK(server_added), NULL); + + g_timeout_add_seconds(2, failed_cb, NULL); + + mainloop = g_main_loop_new(NULL, FALSE); + g_main_loop_run(mainloop); + + return !passed; +} diff --git a/tests/test_interests b/tests/test_interests new file mode 100755 index 0000000..b37189f --- /dev/null +++ b/tests/test_interests @@ -0,0 +1,5 @@ +#!/bin/sh + +DBUS_RUNNER="/home/ted/Development/dbus-play/dbus-test-runner --dbus-config /home/ted/Development/dbus-play/session.conf" + +${DBUS_RUNNER} --task ./test-interests-client --task-name Client --task ./test-interests-server --task-name Server |