aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am54
-rw-r--r--tests/test-glib-proxy-client.c171
-rw-r--r--tests/test-glib-proxy-proxy.c80
-rw-r--r--tests/test-glib-proxy-server.c126
-rw-r--r--tests/test-glib-proxy.h142
5 files changed, 573 insertions, 0 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 746ac23..cfa1399 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -5,6 +5,7 @@ TESTS = \
test-glib-objects-test \
test-glib-layout \
test-glib-properties \
+ test-glib-proxy \
test-glib-simple-items \
test-gtk-label \
test-gtk-reorder
@@ -16,6 +17,9 @@ check_PROGRAMS = \
test-glib-layout-server \
test-glib-properties-client \
test-glib-properties-server \
+ test-glib-proxy-client \
+ test-glib-proxy-server \
+ test-glib-proxy-proxy \
test-gtk-label-client \
test-gtk-label-server \
test-glib-simple-items \
@@ -127,6 +131,56 @@ test_glib_properties_client_LDADD = \
../libdbusmenu-glib/libdbusmenu-glib.la \
$(DBUSMENUGLIB_LIBS)
+######################
+# Test Glib Proxy
+######################
+
+test-glib-proxy: test-glib-proxy-client test-glib-proxy-server test-glib-proxy-proxy Makefile.am
+ @echo "#!/bin/bash" > $@
+ @echo $(DBUS_RUNNER) --task ./test-glib-proxy-client --task-name Client --task ./test-glib-proxy-server --task-name Server --ignore-return \\ >> $@
+ @echo --task ./test-glib-proxy-proxy --parameter test.proxy.first_proxy --parameter test.proxy.second_proxy --task-name Proxy01 --ignore-return \\ >> $@
+ @echo --task ./test-glib-proxy-proxy --parameter test.proxy.second_proxy --parameter test.proxy.third_proxy --task-name Proxy02 --ignore-return \\ >> $@
+ @echo --task ./test-glib-proxy-proxy --parameter test.proxy.third_proxy --parameter test.proxy.fourth_proxy --task-name Proxy03 --ignore-return \\ >> $@
+ @echo --task ./test-glib-proxy-proxy --parameter test.proxy.fourth_proxy --parameter test.proxy.last_proxy --task-name Proxy04 --ignore-return \\ >> $@
+ @echo --task ./test-glib-proxy-proxy --parameter test.proxy.last_proxy --parameter test.proxy.server --task-name Proxy05 --ignore-return >> $@
+ @chmod +x $@
+
+test_glib_proxy_server_SOURCES = \
+ test-glib-proxy.h \
+ test-glib-proxy-server.c
+
+test_glib_proxy_server_CFLAGS = \
+ -I $(srcdir)/.. \
+ $(DBUSMENUGLIB_CFLAGS) -Wall -Werror
+
+test_glib_proxy_server_LDADD = \
+ ../libdbusmenu-glib/libdbusmenu-glib.la \
+ $(DBUSMENUGLIB_LIBS)
+
+test_glib_proxy_client_SOURCES = \
+ test-glib-proxy.h \
+ test-glib-proxy-client.c
+
+test_glib_proxy_client_CFLAGS = \
+ -I $(srcdir)/.. \
+ $(DBUSMENUGLIB_CFLAGS) -Wall -Werror
+
+test_glib_proxy_client_LDADD = \
+ ../libdbusmenu-glib/libdbusmenu-glib.la \
+ $(DBUSMENUGLIB_LIBS)
+
+test_glib_proxy_proxy_SOURCES = \
+ test-glib-proxy.h \
+ test-glib-proxy-proxy.c
+
+test_glib_proxy_proxy_CFLAGS = \
+ -I $(srcdir)/.. \
+ $(DBUSMENUGLIB_CFLAGS) -Wall -Werror
+
+test_glib_proxy_proxy_LDADD = \
+ ../libdbusmenu-glib/libdbusmenu-glib.la \
+ $(DBUSMENUGLIB_LIBS)
+
#########################
# Test Glib Simple Items
#########################
diff --git a/tests/test-glib-proxy-client.c b/tests/test-glib-proxy-client.c
new file mode 100644
index 0000000..50ad5d3
--- /dev/null
+++ b/tests/test-glib-proxy-client.c
@@ -0,0 +1,171 @@
+/*
+A test for libdbusmenu to ensure its quality.
+
+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 <libdbusmenu-glib/client.h>
+#include <libdbusmenu-glib/menuitem.h>
+
+#include "test-glib-proxy.h"
+
+static guint layouton = -1;
+static GMainLoop * mainloop = NULL;
+static gboolean passed = TRUE;
+static guint death_timer = 0;
+
+static gboolean
+verify_props (DbusmenuMenuitem * mi, gchar ** properties)
+{
+ if (properties == NULL) {
+ return TRUE;
+ }
+
+ /* Verify they're all there and correct */
+ guint i;
+ for (i = 0; properties[i] != NULL; i += 2) {
+ const gchar * value = dbusmenu_menuitem_property_get(mi, properties[i]);
+ if (g_strcmp0(value, properties[i + 1])) {
+ g_debug("\tFailed as property '%s' should be '%s' and is '%s'", properties[i], properties[i+1], value);
+ return FALSE;
+ }
+ }
+
+ /* Verify that we don't have any extras */
+ // GList * props = dbusmenu_menuitem_properties_list(mi);
+
+ return TRUE;
+}
+
+static gboolean
+verify_root_to_layout(DbusmenuMenuitem * mi, proplayout_t * layout)
+{
+ g_debug("Verifying ID: %d", layout->id);
+
+ if (!verify_props(mi, layout->properties)) {
+ g_debug("\tFailed as unable to verify properties.");
+ return FALSE;
+ }
+
+ GList * children = dbusmenu_menuitem_get_children(mi);
+
+ if (children == NULL && layout->submenu == NULL) {
+ g_debug("\tPassed: %d", layout->id);
+ return TRUE;
+ }
+ if (children == NULL || layout->submenu == NULL) {
+ if (children == NULL) {
+ g_debug("\tFailed as there are no children but we have submenus");
+ } else {
+ g_debug("\tFailed as we have children but no submenu");
+ }
+ return FALSE;
+ }
+
+ guint i = 0;
+ for (i = 0; children != NULL && layout->submenu[i].id != -1; children = g_list_next(children), i++) {
+ if (!verify_root_to_layout(DBUSMENU_MENUITEM(children->data), &layout->submenu[i])) {
+ return FALSE;
+ }
+ }
+
+ if (children == NULL && layout->submenu[i].id == -1) {
+ g_debug("\tPassed: %d", layout->id);
+ return TRUE;
+ }
+
+ if (children != NULL) {
+ g_debug("\tFailed as there are still children but no submenus. (ID: %d)", layout->id);
+ } else {
+ g_debug("\tFailed as there are still submenus but no children. (ID: %d)", layout->id);
+ }
+ return FALSE;
+}
+
+static gboolean
+timer_func (gpointer data)
+{
+ g_debug("Death timer. Oops. Got to: %d", layouton);
+ passed = FALSE;
+ g_main_loop_quit(mainloop);
+ return FALSE;
+}
+
+static gboolean layout_verify_timer (gpointer data);
+
+static void
+layout_updated (DbusmenuClient * client, gpointer data)
+{
+ g_debug("Layout Updated");
+ if (dbusmenu_client_get_root(client) == NULL) {
+ g_debug("\tIgnored, no root");
+ return;
+ }
+ layouton++;
+ g_timeout_add (1500, layout_verify_timer, client);
+ return;
+}
+
+static gboolean
+layout_verify_timer (gpointer data)
+{
+ g_debug("Verifing Layout: %d", layouton);
+ DbusmenuMenuitem * menuroot = dbusmenu_client_get_root(DBUSMENU_CLIENT(data));
+ proplayout_t * layout = &layouts[layouton];
+
+ if (!verify_root_to_layout(menuroot, layout)) {
+ g_debug("FAILED LAYOUT: %d", layouton);
+ passed = FALSE;
+ } else {
+ /* Extend our death */
+ g_source_remove(death_timer);
+ death_timer = g_timeout_add_seconds(10, timer_func, data);
+ }
+
+ if (layouts[layouton+1].id == -1) {
+ g_main_loop_quit(mainloop);
+ }
+
+ return FALSE;
+}
+
+int
+main (int argc, char ** argv)
+{
+ g_type_init();
+
+ DbusmenuClient * client = dbusmenu_client_new("test.proxy.first_proxy", "/org/test");
+ g_signal_connect(G_OBJECT(client), DBUSMENU_CLIENT_SIGNAL_LAYOUT_UPDATED, G_CALLBACK(layout_updated), NULL);
+
+ death_timer = g_timeout_add_seconds(10, timer_func, client);
+
+ mainloop = g_main_loop_new(NULL, FALSE);
+ g_main_loop_run(mainloop);
+
+ g_object_unref(G_OBJECT(client));
+
+ if (passed) {
+ g_debug("Quiting");
+ return 0;
+ } else {
+ g_debug("Quiting as we're a failure");
+ return 1;
+ }
+}
diff --git a/tests/test-glib-proxy-proxy.c b/tests/test-glib-proxy-proxy.c
new file mode 100644
index 0000000..1059cfd
--- /dev/null
+++ b/tests/test-glib-proxy-proxy.c
@@ -0,0 +1,80 @@
+#include <glib.h>
+
+#include <dbus/dbus.h>
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-lowlevel.h>
+#include <dbus/dbus-glib-bindings.h>
+
+#include <libdbusmenu-glib/menuitem.h>
+#include <libdbusmenu-glib/menuitem-proxy.h>
+#include <libdbusmenu-glib/server.h>
+#include <libdbusmenu-glib/client.h>
+
+#include "test-glib-proxy.h"
+
+static DbusmenuServer * server = NULL;
+static DbusmenuClient * client = NULL;
+static GMainLoop * mainloop = NULL;
+
+void
+root_changed (DbusmenuClient * client, DbusmenuMenuitem * newroot, gpointer user_data)
+{
+ g_debug("New root: %X", (guint)newroot);
+
+ if (newroot == NULL) {
+ g_debug("Root removed, exiting");
+ g_main_loop_quit(mainloop);
+ return;
+ }
+
+ DbusmenuMenuitemProxy * pmi = dbusmenu_menuitem_proxy_new(newroot);
+ dbusmenu_server_set_root(server, DBUSMENU_MENUITEM(pmi));
+ return;
+}
+
+int
+main (int argc, char ** argv)
+{
+ g_type_init();
+
+ if (argc != 3) {
+ g_error ("Need two params");
+ return 1;
+ }
+
+ gchar * whoami = argv[1];
+ gchar * myproxy = argv[2];
+
+ g_debug("I am '%s' and I'm proxying '%s'", whoami, myproxy);
+
+ GError * error = NULL;
+ DBusGConnection * connection = dbus_g_bus_get(DBUS_BUS_SESSION, NULL);
+
+ g_debug("DBus ID: %s", dbus_connection_get_server_id(dbus_g_connection_get_connection(connection)));
+
+ DBusGProxy * bus_proxy = dbus_g_proxy_new_for_name(connection, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS);
+ guint nameret = 0;
+
+ if (!org_freedesktop_DBus_request_name(bus_proxy, whoami, 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;
+ }
+
+ server = dbusmenu_server_new("/org/test");
+ client = dbusmenu_client_new(myproxy, "/org/test");
+
+ g_signal_connect(client, DBUSMENU_CLIENT_SIGNAL_ROOT_CHANGED, G_CALLBACK(root_changed), server);
+
+ mainloop = g_main_loop_new(NULL, FALSE);
+ g_main_loop_run(mainloop);
+
+ g_object_unref(G_OBJECT(server));
+ g_debug("Quiting");
+
+ return 0;
+}
diff --git a/tests/test-glib-proxy-server.c b/tests/test-glib-proxy-server.c
new file mode 100644
index 0000000..cba8ec7
--- /dev/null
+++ b/tests/test-glib-proxy-server.c
@@ -0,0 +1,126 @@
+/*
+A test for libdbusmenu to ensure its quality.
+
+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.h>
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-lowlevel.h>
+#include <dbus/dbus-glib-bindings.h>
+
+#include <libdbusmenu-glib/menuitem.h>
+#include <libdbusmenu-glib/server.h>
+
+#include "test-glib-proxy.h"
+
+static void
+set_props (DbusmenuMenuitem * mi, gchar ** props)
+{
+ if (props == NULL) return;
+
+ guint i;
+ for (i = 0; props[i] != NULL; i += 2) {
+ dbusmenu_menuitem_property_set(mi, props[i], props[i+1]);
+ }
+
+ return;
+}
+
+static DbusmenuMenuitem *
+layout2menuitem (proplayout_t * layout)
+{
+ if (layout == NULL || layout->id == -1) return NULL;
+
+ DbusmenuMenuitem * local = dbusmenu_menuitem_new();
+ set_props(local, layout->properties);
+
+ if (layout->submenu != NULL) {
+ guint count;
+ for (count = 0; layout->submenu[count].id != -1; count++) {
+ DbusmenuMenuitem * child = layout2menuitem(&layout->submenu[count]);
+ if (child != NULL) {
+ dbusmenu_menuitem_child_append(local, child);
+ }
+ }
+ }
+
+ /* g_debug("Layout to menu return: 0x%X", (unsigned int)local); */
+ return local;
+}
+
+static guint layouton = 0;
+static DbusmenuServer * server = NULL;
+static GMainLoop * mainloop = NULL;
+
+static gboolean
+timer_func (gpointer data)
+{
+ if (layouts[layouton].id == -1) {
+ g_main_loop_quit(mainloop);
+ return FALSE;
+ }
+ g_debug("Updating to Layout %d", layouton);
+
+ DbusmenuMenuitem * mi = layout2menuitem(&layouts[layouton]);
+ dbusmenu_server_set_root(server, mi);
+ g_object_unref(G_OBJECT(mi));
+ layouton++;
+
+ return TRUE;
+}
+
+int
+main (int argc, char ** argv)
+{
+ g_type_init();
+
+ GError * error = NULL;
+ DBusGConnection * connection = dbus_g_bus_get(DBUS_BUS_SESSION, NULL);
+
+ g_debug("DBus ID: %s", dbus_connection_get_server_id(dbus_g_connection_get_connection(connection)));
+
+ DBusGProxy * bus_proxy = dbus_g_proxy_new_for_name(connection, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS);
+ guint nameret = 0;
+
+ if (!org_freedesktop_DBus_request_name(bus_proxy, "test.proxy.server", 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;
+ }
+
+ server = dbusmenu_server_new("/org/test");
+
+ timer_func(NULL);
+ g_timeout_add(2500, timer_func, NULL);
+
+ mainloop = g_main_loop_new(NULL, FALSE);
+ g_main_loop_run(mainloop);
+
+ g_object_unref(G_OBJECT(server));
+ g_debug("Quiting");
+
+ return 0;
+}
+
diff --git a/tests/test-glib-proxy.h b/tests/test-glib-proxy.h
new file mode 100644
index 0000000..bc12df6
--- /dev/null
+++ b/tests/test-glib-proxy.h
@@ -0,0 +1,142 @@
+/*
+A test for libdbusmenu to ensure its quality.
+
+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>
+
+typedef struct _proplayout_t proplayout_t;
+struct _proplayout_t {
+ gint id;
+ gchar ** properties;
+ proplayout_t * submenu;
+};
+
+gchar * props1[] = {"property1", "value1", "property2", "value2", NULL};
+gchar * props2[] = {"property00", "value00", "property01", "value01", "property02", "value02", "property03", "value03", "property04", "value04",
+ "property05", "value05", "property06", "value06", "property07", "value07", "property08", "value08", "property09", "value09",
+ "property10", "value10", "property11", "value11", "property12", "value12", "property13", "value13", "property14", "value14",
+ "property15", "value15", "property16", "value16", "property17", "value17", "property18", "value18", "property19", "value19",
+ "property20", "value20", "property21", "value21", "property22", "value22", "property23", "value23", "property24", "value24",
+ "property25", "value25", "property26", "value26", "property27", "value27", "property28", "value28", "property29", "value29",
+ "property30", "value30", "property31", "value31", "property32", "value32", "property33", "value33", "property34", "value34",
+ "property35", "value35", "property36", "value36", "property37", "value37", "property38", "value38", "property39", "value39",
+ "property40", "value40", "property41", "value41", "property42", "value42", "property43", "value43", "property44", "value44",
+ "property45", "value45", "property46", "value46", "property47", "value47", "property48", "value48", "property49", "value49",
+ "property50", "value50", "property51", "value51", "property52", "value52", "property53", "value53", "property54", "value54",
+ "property55", "value55", "property56", "value56", "property57", "value57", "property58", "value58", "property59", "value59",
+ "property60", "value60", "property61", "value61", "property62", "value62", "property63", "value63", "property64", "value64",
+ "property65", "value65", "property66", "value66", "property67", "value67", "property68", "value68", "property69", "value69",
+ "property70", "value70", "property71", "value71", "property72", "value72", "property73", "value73", "property74", "value74",
+ "property75", "value75", "property76", "value76", "property77", "value77", "property78", "value78", "property79", "value79",
+ "property80", "value80", "property81", "value81", "property82", "value82", "property83", "value83", "property84", "value84",
+ "property85", "value85", "property86", "value86", "property87", "value87", "property88", "value88", "property89", "value89",
+ "property90", "value90", "property91", "value91", "property92", "value92", "property93", "value93", "property94", "value94",
+ "property95", "value95", "property96", "value96", "property97", "value97", "property98", "value98", "property99", "value99",
+ NULL};
+gchar * props3[] = {"property name that is really long and will ensure that we can really have long property names, which could be important at some point.",
+ "And a property name that is really long should have a value that is really long, because well, that's an important part of the yin and yang of software testing.",
+ NULL};
+gchar * props4[] = {"icon-name", "network-status", "label", "Look at network", "right-column", "10:32", NULL};
+
+
+proplayout_t submenu_4_1[] = {
+ {id: 10, properties: props2, submenu: NULL},
+ {id: 11, properties: props2, submenu: NULL},
+ {id: 12, properties: props2, submenu: NULL},
+ {id: 13, properties: props2, submenu: NULL},
+ {id: 14, properties: props2, submenu: NULL},
+ {id: 15, properties: props2, submenu: NULL},
+ {id: 16, properties: props2, submenu: NULL},
+ {id: 17, properties: props2, submenu: NULL},
+ {id: 18, properties: props2, submenu: NULL},
+ {id: 19, properties: props2, submenu: NULL},
+ {id: -1, properties: NULL, submenu: NULL}
+};
+
+proplayout_t submenu_4_2[] = {
+ {id: 20, properties: props2, submenu: NULL},
+ {id: 21, properties: props2, submenu: NULL},
+ {id: 22, properties: props2, submenu: NULL},
+ {id: 23, properties: props2, submenu: NULL},
+ {id: 24, properties: props2, submenu: NULL},
+ {id: 25, properties: props2, submenu: NULL},
+ {id: 26, properties: props2, submenu: NULL},
+ {id: 27, properties: props2, submenu: NULL},
+ {id: 28, properties: props2, submenu: NULL},
+ {id: 29, properties: props2, submenu: NULL},
+ {id: -1, properties: NULL, submenu: NULL}
+};
+
+proplayout_t submenu_4_3[] = {
+ {id: 30, properties: props2, submenu: NULL},
+ {id: 31, properties: props2, submenu: NULL},
+ {id: 32, properties: props2, submenu: NULL},
+ {id: 33, properties: props2, submenu: NULL},
+ {id: 34, properties: props2, submenu: NULL},
+ {id: 35, properties: props2, submenu: NULL},
+ {id: 36, properties: props2, submenu: NULL},
+ {id: 37, properties: props2, submenu: NULL},
+ {id: 38, properties: props2, submenu: NULL},
+ {id: 39, properties: props2, submenu: NULL},
+ {id: -1, properties: NULL, submenu: NULL}
+};
+
+proplayout_t submenu_4_0[] = {
+ {id: 1, properties: props2, submenu: submenu_4_1},
+ {id: 2, properties: props2, submenu: submenu_4_2},
+ {id: 3, properties: props2, submenu: submenu_4_3},
+ {id: -1, properties: NULL, submenu: NULL}
+};
+
+proplayout_t submenu_5_5[] = {
+ {id: 205, properties: props3, submenu: NULL},
+ {id: -1, properties: NULL, submenu: NULL}
+};
+
+proplayout_t submenu_5_4[] = {
+ {id: 204, properties: props3, submenu: submenu_5_5},
+ {id: -1, properties: NULL, submenu: NULL}
+};
+
+proplayout_t submenu_5_3[] = {
+ {id: 203, properties: props3, submenu: submenu_5_4},
+ {id: -1, properties: NULL, submenu: NULL}
+};
+
+proplayout_t submenu_5_2[] = {
+ {id: 202, properties: props3, submenu: submenu_5_3},
+ {id: -1, properties: NULL, submenu: NULL}
+};
+
+proplayout_t submenu_5_1[] = {
+ {id: 201, properties: props3, submenu: submenu_5_2},
+ {id: -1, properties: NULL, submenu: NULL}
+};
+
+proplayout_t layouts[] = {
+ {id: 1, properties: props1, submenu: NULL},
+ {id: 10, properties: props2, submenu: submenu_4_1},
+ {id: 20, properties: props3, submenu: submenu_4_2},
+ {id: 100, properties: props2, submenu: submenu_4_0},
+ {id: 200, properties: props3, submenu: submenu_5_1},
+ {id: -1, properties: NULL, submenu: NULL}
+};
+