aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorTed Gould <ted@gould.cx>2010-02-05 17:30:10 -0800
committerTed Gould <ted@gould.cx>2010-02-05 17:30:10 -0800
commit1a8b83c9f2bb8afa7d737f08e6f183ab3e384113 (patch)
tree4f08b249d0b270c7063da5a3d37f4e187e8f8b61 /tests
parentf8ab455538c130ce03132e2557c9363e9a808156 (diff)
downloadlibayatana-appindicator-1a8b83c9f2bb8afa7d737f08e6f183ab3e384113.tar.gz
libayatana-appindicator-1a8b83c9f2bb8afa7d737f08e6f183ab3e384113.tar.bz2
libayatana-appindicator-1a8b83c9f2bb8afa7d737f08e6f183ab3e384113.zip
Adding a test for changing the status. Just a copy of the standard dbus test.
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am43
-rw-r--r--tests/test-libappindicator-status-client.c260
-rw-r--r--tests/test-libappindicator-status-server.c59
3 files changed, 362 insertions, 0 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 327c8cc..10a5647 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -3,6 +3,8 @@ check_PROGRAMS = \
test-libappindicator \
test-libappindicator-dbus-client \
test-libappindicator-dbus-server \
+ test-libappindicator-status-client \
+ test-libappindicator-status-server \
test-libappindicator-fallback-watcher \
test-libappindicator-fallback-item \
test-simple-app
@@ -63,6 +65,40 @@ test_libappindicator_dbus_server_LDADD = \
$(top_builddir)/src/libappindicator.la
#########################################
+## test-libappindicator-status-client
+#########################################
+
+test_libappindicator_status_client_SOURCES = \
+ test-defines.h \
+ test-libappindicator-status-client.c
+
+test_libappindicator_status_client_CFLAGS = \
+ $(INDICATOR_CFLAGS) \
+ -Wall -Werror \
+ -I$(top_srcdir)/src
+
+test_libappindicator_status_client_LDADD = \
+ $(INDICATOR_LIBS) \
+ $(top_builddir)/src/libappindicator.la
+
+#########################################
+## test-libappindicator-status-server
+#########################################
+
+test_libappindicator_status_server_SOURCES = \
+ test-defines.h \
+ test-libappindicator-status-server.c
+
+test_libappindicator_status_server_CFLAGS = \
+ $(INDICATOR_CFLAGS) \
+ -Wall -Werror \
+ -I$(top_srcdir)/src
+
+test_libappindicator_status_server_LDADD = \
+ $(INDICATOR_LIBS) \
+ $(top_builddir)/src/libappindicator.la
+
+#########################################
## test-libappindicator-fallback
#########################################
@@ -128,6 +164,13 @@ test-libappindicator-dbus: test-libappindicator-dbus-client test-libappindicator
TESTS += test-libappindicator-dbus
+test-libappindicator-status: test-libappindicator-status-client test-libappindicator-status-server Makefile.am
+ @echo "#!/bin/sh" > test-libappindicator-status
+ @echo $(DBUS_RUNNER) --task ./test-libappindicator-status-client --task-name Client --task ./test-libappindicator-status-server --task-name Server --ignore-return >> test-libappindicator-status
+ @chmod +x test-libappindicator-status
+
+TESTS += test-libappindicator-dbus
+
#########################################
## test-simple-app
#########################################
diff --git a/tests/test-libappindicator-status-client.c b/tests/test-libappindicator-status-client.c
new file mode 100644
index 0000000..5a7107f
--- /dev/null
+++ b/tests/test-libappindicator-status-client.c
@@ -0,0 +1,260 @@
+/*
+Tests for the libappindicator library that are over DBus. This is
+the client side of those tests.
+
+Copyright 2009 Canonical Ltd.
+
+Authors:
+ Ted Gould <ted@canonical.com>
+
+This program is free software: you can redistribute it and/or modify it
+under the terms of the GNU General Public License version 3, as published
+by the Free Software Foundation.
+
+This program is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranties of
+MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
+PURPOSE. See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along
+with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+
+#include <glib.h>
+#include <dbus/dbus-glib.h>
+#include <libappindicator/app-indicator.h>
+#include "test-defines.h"
+
+static GMainLoop * mainloop = NULL;
+static gboolean passed = TRUE;
+static int propcount = 0;
+
+static void
+check_propcount (void)
+{
+ if (propcount >= 5) {
+ g_main_loop_quit(mainloop);
+ }
+ return;
+}
+
+
+static void
+prop_id_cb (DBusGProxy * proxy, DBusGProxyCall * call, void * data)
+{
+ propcount++;
+
+ GError * error = NULL;
+ GValue value = {0};
+
+ if (!dbus_g_proxy_end_call(proxy, call, &error, G_TYPE_VALUE, &value, G_TYPE_INVALID)) {
+ g_warning("Getting ID failed: %s", error->message);
+ g_error_free(error);
+ passed = FALSE;
+ check_propcount();
+ return;
+ }
+
+ if (g_strcmp0(TEST_ID, g_value_get_string(&value))) {
+ g_debug("Property ID Returned: FAILED");
+ passed = FALSE;
+ } else {
+ g_debug("Property ID Returned: PASSED");
+ }
+
+ check_propcount();
+ return;
+}
+
+static void
+prop_category_cb (DBusGProxy * proxy, DBusGProxyCall * call, void * data)
+{
+ propcount++;
+
+ GError * error = NULL;
+ GValue value = {0};
+
+ if (!dbus_g_proxy_end_call(proxy, call, &error, G_TYPE_VALUE, &value, G_TYPE_INVALID)) {
+ g_warning("Getting category failed: %s", error->message);
+ g_error_free(error);
+ passed = FALSE;
+ check_propcount();
+ return;
+ }
+
+ if (g_strcmp0(TEST_CATEGORY_S, g_value_get_string(&value))) {
+ g_debug("Property category Returned: FAILED");
+ passed = FALSE;
+ } else {
+ g_debug("Property category Returned: PASSED");
+ }
+
+ check_propcount();
+ return;
+}
+
+static void
+prop_status_cb (DBusGProxy * proxy, DBusGProxyCall * call, void * data)
+{
+ propcount++;
+
+ GError * error = NULL;
+ GValue value = {0};
+
+ if (!dbus_g_proxy_end_call(proxy, call, &error, G_TYPE_VALUE, &value, G_TYPE_INVALID)) {
+ g_warning("Getting status failed: %s", error->message);
+ g_error_free(error);
+ passed = FALSE;
+ check_propcount();
+ return;
+ }
+
+ if (g_strcmp0(TEST_STATE_S, g_value_get_string(&value))) {
+ g_debug("Property status Returned: FAILED");
+ passed = FALSE;
+ } else {
+ g_debug("Property status Returned: PASSED");
+ }
+
+ check_propcount();
+ return;
+}
+
+static void
+prop_icon_name_cb (DBusGProxy * proxy, DBusGProxyCall * call, void * data)
+{
+ propcount++;
+
+ GError * error = NULL;
+ GValue value = {0};
+
+ if (!dbus_g_proxy_end_call(proxy, call, &error, G_TYPE_VALUE, &value, G_TYPE_INVALID)) {
+ g_warning("Getting icon name failed: %s", error->message);
+ g_error_free(error);
+ passed = FALSE;
+ check_propcount();
+ return;
+ }
+
+ if (g_strcmp0(TEST_ICON_NAME, g_value_get_string(&value))) {
+ g_debug("Property icon name Returned: FAILED");
+ passed = FALSE;
+ } else {
+ g_debug("Property icon name Returned: PASSED");
+ }
+
+ check_propcount();
+ return;
+}
+
+static void
+prop_attention_icon_name_cb (DBusGProxy * proxy, DBusGProxyCall * call, void * data)
+{
+ propcount++;
+
+ GError * error = NULL;
+ GValue value = {0};
+
+ if (!dbus_g_proxy_end_call(proxy, call, &error, G_TYPE_VALUE, &value, G_TYPE_INVALID)) {
+ g_warning("Getting attention icon name failed: %s", error->message);
+ g_error_free(error);
+ passed = FALSE;
+ check_propcount();
+ return;
+ }
+
+ if (g_strcmp0(TEST_ATTENTION_ICON_NAME, g_value_get_string(&value))) {
+ g_debug("Property attention icon name Returned: FAILED");
+ passed = FALSE;
+ } else {
+ g_debug("Property attention icon name Returned: PASSED");
+ }
+
+ check_propcount();
+ return;
+}
+
+gboolean
+kill_func (gpointer userdata)
+{
+ g_main_loop_quit(mainloop);
+ g_warning("Forced to Kill");
+ passed = FALSE;
+ return FALSE;
+}
+
+gint
+main (gint argc, gchar * argv[])
+{
+ g_type_init();
+
+ g_usleep(500000);
+
+ GError * error = NULL;
+ DBusGConnection * session_bus = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
+ if (error != NULL) {
+ g_error("Unable to get session bus: %s", error->message);
+ return 1;
+ }
+
+ DBusGProxy * props = dbus_g_proxy_new_for_name_owner(session_bus,
+ ":1.0",
+ "/org/ayatana/NotificationItem",
+ DBUS_INTERFACE_PROPERTIES,
+ &error);
+ if (error != NULL) {
+ g_error("Unable to get property proxy: %s", error->message);
+ return 1;
+ }
+
+ dbus_g_proxy_begin_call (props,
+ "Get",
+ prop_id_cb,
+ NULL, NULL,
+ G_TYPE_STRING, "org.ayatana.indicator.application.NotificationItem",
+ G_TYPE_STRING, "Id",
+ G_TYPE_INVALID);
+ dbus_g_proxy_begin_call (props,
+ "Get",
+ prop_category_cb,
+ NULL, NULL,
+ G_TYPE_STRING, "org.ayatana.indicator.application.NotificationItem",
+ G_TYPE_STRING, "Category",
+ G_TYPE_INVALID);
+ dbus_g_proxy_begin_call (props,
+ "Get",
+ prop_status_cb,
+ NULL, NULL,
+ G_TYPE_STRING, "org.ayatana.indicator.application.NotificationItem",
+ G_TYPE_STRING, "Status",
+ G_TYPE_INVALID);
+ dbus_g_proxy_begin_call (props,
+ "Get",
+ prop_icon_name_cb,
+ NULL, NULL,
+ G_TYPE_STRING, "org.ayatana.indicator.application.NotificationItem",
+ G_TYPE_STRING, "IconName",
+ G_TYPE_INVALID);
+ dbus_g_proxy_begin_call (props,
+ "Get",
+ prop_attention_icon_name_cb,
+ NULL, NULL,
+ G_TYPE_STRING, "org.ayatana.indicator.application.NotificationItem",
+ G_TYPE_STRING, "AttentionIconName",
+ G_TYPE_INVALID);
+
+ g_timeout_add_seconds(2, kill_func, NULL);
+
+ mainloop = g_main_loop_new(NULL, FALSE);
+ g_main_loop_run(mainloop);
+
+ if (passed) {
+ g_debug("Quiting");
+ return 0;
+ } else {
+ g_debug("Quiting as we're a failure");
+ return 1;
+ }
+ return 0;
+}
diff --git a/tests/test-libappindicator-status-server.c b/tests/test-libappindicator-status-server.c
new file mode 100644
index 0000000..cc072aa
--- /dev/null
+++ b/tests/test-libappindicator-status-server.c
@@ -0,0 +1,59 @@
+/*
+Tests for the libappindicator library that are over DBus. This is
+the server side of those tests.
+
+Copyright 2009 Canonical Ltd.
+
+Authors:
+ Ted Gould <ted@canonical.com>
+
+This program is free software: you can redistribute it and/or modify it
+under the terms of the GNU General Public License version 3, as published
+by the Free Software Foundation.
+
+This program is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranties of
+MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
+PURPOSE. See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along
+with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-lowlevel.h>
+#include <glib.h>
+#include <libappindicator/app-indicator.h>
+#include "test-defines.h"
+
+static GMainLoop * mainloop = NULL;
+
+gboolean
+kill_func (gpointer userdata)
+{
+ g_main_loop_quit(mainloop);
+ return FALSE;
+}
+
+gint
+main (gint argc, gchar * argv[])
+{
+ g_type_init();
+
+ 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);
+
+ g_timeout_add_seconds(2, kill_func, NULL);
+
+ mainloop = g_main_loop_new(NULL, FALSE);
+ g_main_loop_run(mainloop);
+
+ g_object_unref(G_OBJECT(ci));
+ g_debug("Quiting");
+
+ return 0;
+}