aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am89
-rw-r--r--tests/test-defines.h10
-rw-r--r--tests/test-libcustomindicator-dbus-client.c272
-rw-r--r--tests/test-libcustomindicator-dbus-server.c44
-rw-r--r--tests/test-libcustomindicator.c163
5 files changed, 578 insertions, 0 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
new file mode 100644
index 0000000..dfdb397
--- /dev/null
+++ b/tests/Makefile.am
@@ -0,0 +1,89 @@
+
+check_PROGRAMS = \
+ test-libcustomindicator \
+ test-libcustomindicator-dbus-client \
+ test-libcustomindicator-dbus-server
+
+TESTS =
+DISTCLEANFILES = $(TESTS)
+
+#########################################
+## test-libcustomindicator
+#########################################
+
+test_libcustomindicator_SOURCES = \
+ test-libcustomindicator.c
+
+test_libcustomindicator_CFLAGS = \
+ $(INDICATOR_CFLAGS) \
+ -Wall -Werror \
+ -I$(top_srcdir)/src
+
+test_libcustomindicator_LDADD = \
+ $(INDICATOR_LIBS) \
+ $(top_builddir)/src/libcustomindicator.la
+
+#########################################
+## test-libcustomindicator-dbus-client
+#########################################
+
+test_libcustomindicator_dbus_client_SOURCES = \
+ test-defines.h \
+ test-libcustomindicator-dbus-client.c
+
+test_libcustomindicator_dbus_client_CFLAGS = \
+ $(INDICATOR_CFLAGS) \
+ -Wall -Werror \
+ -I$(top_srcdir)/src
+
+test_libcustomindicator_dbus_client_LDADD = \
+ $(INDICATOR_LIBS) \
+ $(top_builddir)/src/libcustomindicator.la
+
+#########################################
+## test-libcustomindicator-dbus-server
+#########################################
+
+test_libcustomindicator_dbus_server_SOURCES = \
+ test-defines.h \
+ test-libcustomindicator-dbus-server.c
+
+test_libcustomindicator_dbus_server_CFLAGS = \
+ $(INDICATOR_CFLAGS) \
+ -Wall -Werror \
+ -I$(top_srcdir)/src
+
+test_libcustomindicator_dbus_server_LDADD = \
+ $(INDICATOR_LIBS) \
+ $(top_builddir)/src/libcustomindicator.la
+
+#########################################
+## Actual tests
+#########################################
+
+XML_REPORT = libcustomindicator-check-results.xml
+HTML_REPORT = libcustomindicator-check-results.html
+
+libcustomindicator-tests: libcustomindicator-tests-gtester Makefile.am
+ @echo "#!/bin/sh" > $@
+ @echo $(DBUS_RUNNER) --task ./libcustomindicator-tests-gtester >> $@
+ @chmod +x $@
+
+libcustomindicator-tests-gtester: test-libcustomindicator Makefile.am
+ @echo "#!/bin/sh" > $@
+ @echo gtester -k --verbose -o=$(XML_REPORT) ./test-libcustomindicator >> $@
+ @chmod +x $@
+
+TESTS += libcustomindicator-tests
+DISTCLEANFILES += $(XML_REPORT) $(HTML_REPORT) libcustomindicator-tests-gtester
+
+
+DBUS_RUNNER=dbus-test-runner --dbus-config /usr/share/dbus-test-runner/session.conf
+
+test-libcustomindicator-dbus: test-libcustomindicator-dbus-client test-libcustomindicator-dbus-server Makefile.am
+ @echo "#!/bin/sh" > test-libcustomindicator-dbus
+ @echo $(DBUS_RUNNER) --task ./test-libcustomindicator-dbus-client --task-name Client --task ./test-libcustomindicator-dbus-server --task-name Server --ignore-return >> test-libcustomindicator-dbus
+ @chmod +x test-libcustomindicator-dbus
+
+TESTS += test-libcustomindicator-dbus
+
diff --git a/tests/test-defines.h b/tests/test-defines.h
new file mode 100644
index 0000000..9d1fc26
--- /dev/null
+++ b/tests/test-defines.h
@@ -0,0 +1,10 @@
+
+#define TEST_ID "my-id"
+#define TEST_ICON_NAME "my-icon-name"
+#define TEST_ATTENTION_ICON_NAME "my-attention-icon-name"
+#define TEST_STATE CUSTOM_INDICATOR_STATUS_ACTIVE
+#define TEST_STATE_S "active"
+#define TEST_CATEGORY CUSTOM_INDICATOR_CATEGORY_APPLICATION_STATUS
+#define TEST_CATEGORY_S "application-status"
+#define TEST_OBJECT "/an/object/path/to/use"
+
diff --git a/tests/test-libcustomindicator-dbus-client.c b/tests/test-libcustomindicator-dbus-client.c
new file mode 100644
index 0000000..e0203c0
--- /dev/null
+++ b/tests/test-libcustomindicator-dbus-client.c
@@ -0,0 +1,272 @@
+
+#include <glib.h>
+#include <dbus/dbus-glib.h>
+#include <libcustomindicator/custom-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 >= 6) {
+ 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;
+}
+
+static void
+prop_menu_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 menu object failed: %s", error->message);
+ g_error_free(error);
+ passed = FALSE;
+ check_propcount();
+ return;
+ }
+
+ if (g_strcmp0(TEST_OBJECT, g_value_get_string(&value))) {
+ g_debug("Property menu object Returned: FAILED");
+ passed = FALSE;
+ } else {
+ g_debug("Property menu object 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",
+ "/need/a/path",
+ 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.custom.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.custom.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.custom.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.custom.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.custom.NotificationItem",
+ G_TYPE_STRING, "AttentionIconName",
+ G_TYPE_INVALID);
+ dbus_g_proxy_begin_call (props,
+ "Get",
+ prop_menu_cb,
+ NULL, NULL,
+ G_TYPE_STRING, "org.ayatana.indicator.custom.NotificationItem",
+ G_TYPE_STRING, "Menu",
+ 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-libcustomindicator-dbus-server.c b/tests/test-libcustomindicator-dbus-server.c
new file mode 100644
index 0000000..2d61776
--- /dev/null
+++ b/tests/test-libcustomindicator-dbus-server.c
@@ -0,0 +1,44 @@
+
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-lowlevel.h>
+#include <glib.h>
+#include <libcustomindicator/custom-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))));
+
+ DbusmenuServer * dms = dbusmenu_server_new(TEST_OBJECT);
+
+ CustomIndicator * ci = CUSTOM_INDICATOR(g_object_new(CUSTOM_INDICATOR_TYPE,
+ "id", TEST_ID,
+ "category-enum", TEST_CATEGORY,
+ "status-enum", TEST_STATE,
+ "icon-name", TEST_ICON_NAME,
+ "attention-icon-name", TEST_ATTENTION_ICON_NAME,
+ "menu-object", dms,
+ NULL));
+
+ 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;
+}
diff --git a/tests/test-libcustomindicator.c b/tests/test-libcustomindicator.c
new file mode 100644
index 0000000..c4342e8
--- /dev/null
+++ b/tests/test-libcustomindicator.c
@@ -0,0 +1,163 @@
+
+#include <glib.h>
+#include <glib-object.h>
+
+#include <libcustomindicator/custom-indicator.h>
+
+void
+test_libcustomindicator_prop_signals_status_helper (CustomIndicator * ci, gchar * status, gboolean * signalactivated)
+{
+ *signalactivated = TRUE;
+ return;
+}
+
+void
+test_libcustomindicator_prop_signals_helper (CustomIndicator * ci, gboolean * signalactivated)
+{
+ *signalactivated = TRUE;
+ return;
+}
+
+void
+test_libcustomindicator_prop_signals (void)
+{
+ CustomIndicator * ci = CUSTOM_INDICATOR(g_object_new(CUSTOM_INDICATOR_TYPE, NULL));
+ g_assert(ci != NULL);
+
+ gboolean signaled = FALSE;
+ gulong handlerid;
+
+ handlerid = 0;
+ handlerid = g_signal_connect(G_OBJECT(ci), "new-icon", G_CALLBACK(test_libcustomindicator_prop_signals_helper), &signaled);
+ g_assert(handlerid != 0);
+
+ handlerid = 0;
+ handlerid = g_signal_connect(G_OBJECT(ci), "new-attention-icon", G_CALLBACK(test_libcustomindicator_prop_signals_helper), &signaled);
+ g_assert(handlerid != 0);
+
+ handlerid = 0;
+ handlerid = g_signal_connect(G_OBJECT(ci), "new-status", G_CALLBACK(test_libcustomindicator_prop_signals_status_helper), &signaled);
+ g_assert(handlerid != 0);
+
+
+ signaled = FALSE;
+ custom_indicator_set_icon(ci, "bob");
+ g_assert(signaled);
+
+ signaled = FALSE;
+ custom_indicator_set_icon(ci, "bob");
+ g_assert(!signaled);
+
+ signaled = FALSE;
+ custom_indicator_set_icon(ci, "al");
+ g_assert(signaled);
+
+
+ signaled = FALSE;
+ custom_indicator_set_attention_icon(ci, "bob");
+ g_assert(signaled);
+
+ signaled = FALSE;
+ custom_indicator_set_attention_icon(ci, "bob");
+ g_assert(!signaled);
+
+ signaled = FALSE;
+ custom_indicator_set_attention_icon(ci, "al");
+ g_assert(signaled);
+
+
+ signaled = FALSE;
+ custom_indicator_set_status(ci, CUSTOM_INDICATOR_STATUS_PASSIVE);
+ g_assert(!signaled);
+
+ signaled = FALSE;
+ custom_indicator_set_status(ci, CUSTOM_INDICATOR_STATUS_ACTIVE);
+ g_assert(signaled);
+
+ signaled = FALSE;
+ custom_indicator_set_status(ci, CUSTOM_INDICATOR_STATUS_ACTIVE);
+ g_assert(!signaled);
+
+ signaled = FALSE;
+ custom_indicator_set_status(ci, CUSTOM_INDICATOR_STATUS_ATTENTION);
+ g_assert(signaled);
+
+ return;
+}
+
+void
+test_libcustomindicator_init_set_props (void)
+{
+ CustomIndicator * ci = CUSTOM_INDICATOR(g_object_new(CUSTOM_INDICATOR_TYPE, NULL));
+ g_assert(ci != NULL);
+
+ custom_indicator_set_id(ci, "my-id");
+ custom_indicator_set_category(ci, CUSTOM_INDICATOR_CATEGORY_APPLICATION_STATUS);
+ custom_indicator_set_status(ci, CUSTOM_INDICATOR_STATUS_ACTIVE);
+ custom_indicator_set_icon(ci, "my-name");
+ custom_indicator_set_attention_icon(ci, "my-attention-name");
+
+ g_assert(!g_strcmp0("my-id", custom_indicator_get_id(ci)));
+ g_assert(!g_strcmp0("my-name", custom_indicator_get_icon(ci)));
+ g_assert(!g_strcmp0("my-attention-name", custom_indicator_get_attention_icon(ci)));
+ g_assert(custom_indicator_get_status(ci) == CUSTOM_INDICATOR_STATUS_ACTIVE);
+ g_assert(custom_indicator_get_category(ci) == CUSTOM_INDICATOR_CATEGORY_APPLICATION_STATUS);
+
+ g_object_unref(G_OBJECT(ci));
+ return;
+}
+
+void
+test_libcustomindicator_init_with_props (void)
+{
+ CustomIndicator * ci = CUSTOM_INDICATOR(g_object_new(CUSTOM_INDICATOR_TYPE,
+ "id", "my-id",
+ "category-enum", CUSTOM_INDICATOR_CATEGORY_APPLICATION_STATUS,
+ "status-enum", CUSTOM_INDICATOR_STATUS_ACTIVE,
+ "icon-name", "my-name",
+ "attention-icon-name", "my-attention-name",
+ NULL));
+ g_assert(ci != NULL);
+
+ g_assert(!g_strcmp0("my-id", custom_indicator_get_id(ci)));
+ g_assert(!g_strcmp0("my-name", custom_indicator_get_icon(ci)));
+ g_assert(!g_strcmp0("my-attention-name", custom_indicator_get_attention_icon(ci)));
+ g_assert(custom_indicator_get_status(ci) == CUSTOM_INDICATOR_STATUS_ACTIVE);
+ g_assert(custom_indicator_get_category(ci) == CUSTOM_INDICATOR_CATEGORY_APPLICATION_STATUS);
+
+ g_object_unref(G_OBJECT(ci));
+ return;
+}
+
+void
+test_libcustomindicator_init (void)
+{
+ CustomIndicator * ci = CUSTOM_INDICATOR(g_object_new(CUSTOM_INDICATOR_TYPE, NULL));
+ g_assert(ci != NULL);
+ g_object_unref(G_OBJECT(ci));
+ return;
+}
+
+void
+test_libcustomindicator_props_suite (void)
+{
+ g_test_add_func ("/indicator-custom/libcustomindicator/init", test_libcustomindicator_init);
+ g_test_add_func ("/indicator-custom/libcustomindicator/init_props", test_libcustomindicator_init_with_props);
+ g_test_add_func ("/indicator-custom/libcustomindicator/init_set_props", test_libcustomindicator_init_set_props);
+ g_test_add_func ("/indicator-custom/libcustomindicator/prop_signals", test_libcustomindicator_prop_signals);
+
+ return;
+}
+
+gint
+main (gint argc, gchar * argv[])
+{
+ g_type_init();
+ g_test_init(&argc, &argv, NULL);
+
+ /* Test suites */
+ test_libcustomindicator_props_suite();
+
+
+ return g_test_run ();
+}