aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorTed Gould <ted@canonical.com>2009-06-18 13:06:01 -0500
committerTed Gould <ted@canonical.com>2009-06-18 13:06:01 -0500
commita957c68bedfe0b5cb065590c91a86b829cafd4b3 (patch)
tree299be9d34df9899209b9ed5cff7fb8be9d0f9e89 /tests
parentec5c382624da19a1a83d1e75d21f74778df01f38 (diff)
parent218976c1a5087e745fdc2fb697deb154efd1ca3b (diff)
downloadlibdbusmenu-a957c68bedfe0b5cb065590c91a86b829cafd4b3.tar.gz
libdbusmenu-a957c68bedfe0b5cb065590c91a86b829cafd4b3.tar.bz2
libdbusmenu-a957c68bedfe0b5cb065590c91a86b829cafd4b3.zip
Pulling in the GTK code
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am45
-rw-r--r--tests/test-glib-layout-server.c2
-rw-r--r--tests/test-glib-properties-server.c7
-rw-r--r--tests/test-gtk-label-client.c181
-rw-r--r--tests/test-gtk-label-server.c139
-rw-r--r--tests/test-gtk-label.json158
6 files changed, 526 insertions, 6 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 1f21141..2ec6ca7 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -2,14 +2,16 @@ check: tests
DBUS_RUNNER=dbus-test-runner --dbus-config /usr/share/dbus-test-runner/session.conf
-tests: test-glib-layout test-glib-properties
+tests: test-glib-layout test-glib-properties test-gtk-label
libexec_PROGRAMS = \
glib-server-nomenu \
test-glib-layout-client \
test-glib-layout-server \
test-glib-properties-client \
- test-glib-properties-server
+ test-glib-properties-server \
+ test-gtk-label-client \
+ test-gtk-label-server
glib_server_nomenu_SOURCES = \
glib-server-nomenu.c
@@ -82,9 +84,46 @@ test_glib_properties_client_LDADD = \
+test-gtk-label: test-gtk-label-client test-gtk-label-server test-gtk-label.json
+ $(DBUS_RUNNER) --task ./test-gtk-label-client --task-name Client --task ./test-gtk-label-server --parameter $(srcdir)/test-gtk-label.json --task-name Server --ignore-return
+
+test_gtk_label_server_SOURCES = \
+ test-gtk-label-server.c
+
+test_gtk_label_server_CFLAGS = \
+ -I $(srcdir)/.. \
+ $(DBUSMENUGTK_CFLAGS) \
+ $(DBUSMENUTESTS_CFLAGS) \
+ $(DBUSMENUGLIB_CFLAGS) -Wall -Werror
+
+test_gtk_label_server_LDADD = \
+ ../libdbusmenu-glib/libdbusmenu-glib.la \
+ ../libdbusmenu-gtk/libdbusmenu-gtk.la \
+ $(DBUSMENUGTK_LIBS) \
+ $(DBUSMENUTESTS_LIBS)
+
+test_gtk_label_client_SOURCES = \
+ test-gtk-label-client.c
+
+test_gtk_label_client_CFLAGS = \
+ -I $(srcdir)/.. \
+ $(DBUSMENUGTK_CFLAGS) \
+ $(DBUSMENUTESTS_CFLAGS) \
+ $(DBUSMENUGLIB_CFLAGS) -Wall -Werror
+
+test_gtk_label_client_LDADD = \
+ ../libdbusmenu-glib/libdbusmenu-glib.la \
+ ../libdbusmenu-gtk/libdbusmenu-gtk.la \
+ $(DBUSMENUGTK_LIBS) \
+ $(DBUSMENUTESTS_LIBS)
+
+
+
examplesdir = $(docdir)/examples/
examples_DATA = \
$(glib_server_nomenu_SOURCES)
-EXTRA_DIST = $(examples_DATA)
+EXTRA_DIST = \
+ $(examples_DATA) \
+ test-gtk-label.json
diff --git a/tests/test-glib-layout-server.c b/tests/test-glib-layout-server.c
index e69c6b2..cc9b8e7 100644
--- a/tests/test-glib-layout-server.c
+++ b/tests/test-glib-layout-server.c
@@ -48,7 +48,7 @@ layout2menuitem (layout_t * layout)
}
}
- g_debug("Layout to menu return: 0x%X", (unsigned int)local);
+ /* g_debug("Layout to menu return: 0x%X", (unsigned int)local); */
return local;
}
diff --git a/tests/test-glib-properties-server.c b/tests/test-glib-properties-server.c
index 477f951..a51ac0c 100644
--- a/tests/test-glib-properties-server.c
+++ b/tests/test-glib-properties-server.c
@@ -40,7 +40,7 @@ layout2menuitem (proplayout_t * layout)
}
}
- g_debug("Layout to menu return: 0x%X", (unsigned int)local);
+ /* g_debug("Layout to menu return: 0x%X", (unsigned int)local); */
return local;
}
@@ -57,7 +57,9 @@ timer_func (gpointer data)
}
g_debug("Updating to Layout %d", layouton);
- dbusmenu_server_set_root(server, layout2menuitem(&layouts[layouton]));
+ DbusmenuMenuitem * mi = layout2menuitem(&layouts[layouton]);
+ dbusmenu_server_set_root(server, mi);
+ g_object_unref(G_OBJECT(mi));
layouton++;
return TRUE;
@@ -78,6 +80,7 @@ main (int argc, char ** argv)
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-gtk-label-client.c b/tests/test-gtk-label-client.c
new file mode 100644
index 0000000..b691f84
--- /dev/null
+++ b/tests/test-gtk-label-client.c
@@ -0,0 +1,181 @@
+/*
+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 <gtk/gtk.h>
+#include <libdbusmenu-gtk/menu.h>
+
+static guint layouton = 0;
+static GMainLoop * mainloop = NULL;
+static gboolean passed = TRUE;
+static guint death_timer = 0;
+
+#if 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 (layout->id != dbusmenu_menuitem_get_id(mi)) {
+ g_debug("\tFailed as ID %d is not equal to %d", layout->id, dbusmenu_menuitem_get_id(mi));
+ return FALSE;
+ }
+
+ 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 != 0; 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 == 0) {
+ 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;
+}
+#endif
+
+static gboolean
+timer_func (gpointer data)
+{
+ g_debug("Death timer. Oops. Got to: %d", layouton);
+ passed = FALSE;
+ g_main_loop_quit(mainloop);
+ return FALSE;
+}
+
+#if 0
+static gboolean layout_verify_timer (gpointer data);
+
+static void
+layout_updated (DbusmenuClient * client, gpointer data)
+{
+ g_debug("Layout Updated");
+ g_timeout_add (250, layout_verify_timer, client);
+ return;
+}
+
+static gboolean
+layout_verify_timer (gpointer data)
+{
+ 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);
+ }
+
+ layouton++;
+
+ if (layouts[layouton].id == 0) {
+ g_main_loop_quit(mainloop);
+ }
+
+ return FALSE;
+}
+#endif
+
+int
+main (int argc, char ** argv)
+{
+ gtk_init(&argc, &argv);
+
+ /* Make sure the server starts up and all that */
+ g_usleep(500000);
+
+ GtkWidget * window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ GtkWidget * menubar = gtk_menu_bar_new();
+ GtkWidget * menuitem = gtk_menu_item_new_with_label("Test");
+ gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), GTK_WIDGET(dbusmenu_gtkmenu_new ("glib.label.test", "/org/test")));
+ gtk_widget_show(menuitem);
+ gtk_menu_bar_append(menubar, menuitem);
+ gtk_widget_show(menubar);
+ gtk_container_add(GTK_CONTAINER(window), menubar);
+ gtk_window_set_title(GTK_WINDOW(window), "libdbusmenu-gtk test");
+ gtk_widget_show(window);
+
+ death_timer = g_timeout_add_seconds(60, timer_func, window);
+
+ 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 0;
+ }
+}
diff --git a/tests/test-gtk-label-server.c b/tests/test-gtk-label-server.c
new file mode 100644
index 0000000..a7534f2
--- /dev/null
+++ b/tests/test-gtk-label-server.c
@@ -0,0 +1,139 @@
+#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 <json-glib/json-glib.h>
+
+static void
+set_props (DbusmenuMenuitem * mi, JsonObject * node)
+{
+ if (node == NULL) return;
+
+ GList * members = NULL;
+ for (members = json_object_get_members(node); members != NULL; members = g_list_next(members)) {
+ const gchar * member = members->data;
+
+ if (!g_strcmp0(member, "id")) { continue; }
+ if (!g_strcmp0(member, "submenu")) { continue; }
+
+ JsonNode * lnode = json_object_get_member(node, member);
+ if (JSON_NODE_TYPE(lnode) != JSON_NODE_VALUE) { continue; }
+
+ dbusmenu_menuitem_property_set(mi, member, json_node_get_string(lnode));
+ }
+
+ return;
+}
+
+static DbusmenuMenuitem *
+layout2menuitem (JsonNode * inlayout)
+{
+ if (inlayout == NULL) return NULL;
+ if (JSON_NODE_TYPE(inlayout) != JSON_NODE_OBJECT) return NULL;
+
+ JsonObject * layout = json_node_get_object(inlayout);
+
+ DbusmenuMenuitem * local = NULL;
+ if (json_object_has_member(layout, "id")) {
+ JsonNode * node = json_object_get_member(layout, "id");
+ g_return_val_if_fail(JSON_NODE_TYPE(node) == JSON_NODE_VALUE, NULL);
+ local = dbusmenu_menuitem_new_with_id(json_node_get_int(node));
+ } else {
+ local = dbusmenu_menuitem_new();
+ }
+
+ set_props(local, layout);
+
+ if (json_object_has_member(layout, "submenu")) {
+ JsonNode * node = json_object_get_member(layout, "submenu");
+ g_return_val_if_fail(JSON_NODE_TYPE(node) == JSON_NODE_ARRAY, local);
+ JsonArray * array = json_node_get_array(node);
+ guint count;
+ for (count = 0; count < json_array_get_length(array); count++) {
+ DbusmenuMenuitem * child = layout2menuitem(json_array_get_element(array, count));
+ if (child != NULL) {
+ dbusmenu_menuitem_child_append(local, child);
+ }
+ }
+ }
+
+ /* g_debug("Layout to menu return: 0x%X", (unsigned int)local); */
+ return local;
+}
+
+static JsonArray * root_array = NULL;
+static guint layouton = 0;
+static DbusmenuServer * server = NULL;
+static GMainLoop * mainloop = NULL;
+
+static gboolean
+timer_func (gpointer data)
+{
+ if (layouton == json_array_get_length(root_array)) {
+ g_debug("Completed %d layouts", layouton);
+ g_main_loop_quit(mainloop);
+ return FALSE;
+ }
+ g_debug("Updating to Layout %d", layouton);
+
+ dbusmenu_server_set_root(server, layout2menuitem(json_array_get_element(root_array, layouton)));
+ layouton++;
+
+ return TRUE;
+}
+
+int
+main (int argc, char ** argv)
+{
+ g_type_init();
+
+ JsonParser * parser = json_parser_new();
+ GError * error = NULL;
+ if (!json_parser_load_from_file(parser, argv[1], &error)) {
+ g_debug("Failed parsing file %s because: %s", argv[1], error->message);
+ return 1;
+ }
+ JsonNode * root_node = json_parser_get_root(parser);
+ if (JSON_NODE_TYPE(root_node) != JSON_NODE_ARRAY) {
+ g_debug("Root node is not an array, fail. It's an: %s", json_node_type_name(root_node));
+ return 1;
+ }
+
+ root_array = json_node_get_array(root_node);
+ g_debug("%d layouts in test description '%s'", json_array_get_length(root_array), argv[1]);
+
+ 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(dbus_g_bus_get(DBUS_BUS_SESSION, NULL))));
+
+ 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, "glib.label.test", 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_seconds(15, timer_func, NULL);
+
+ mainloop = g_main_loop_new(NULL, FALSE);
+ g_main_loop_run(mainloop);
+
+ g_debug("Quiting");
+
+ return 0;
+}
+
diff --git a/tests/test-gtk-label.json b/tests/test-gtk-label.json
new file mode 100644
index 0000000..64c1386
--- /dev/null
+++ b/tests/test-gtk-label.json
@@ -0,0 +1,158 @@
+[
+ {"id": 1,
+ "label": "value1",
+ "submenu": [
+ {"id": 30,
+ "label": "value30"},
+ {"id": 31,
+ "label": "value31"},
+ {"id": 32,
+ "label": "value32"},
+ {"id": 33,
+ "label": "value33"},
+ {"id": 34,
+ "label": "value34"},
+ {"id": 35,
+ "label": "value35"},
+ {"id": 36,
+ "label": "value36"},
+ {"id": 37,
+ "label": "value37"},
+ {"id": 38,
+ "label": "value38"},
+ {"id": 39,
+ "label": "value39"}
+ ]
+ },
+ {"id": 2,
+ "label": "value2",
+ "submenu": [
+ {"id": 20,
+ "label": "value20"},
+ {"id": 21,
+ "label": "value21"},
+ {"id": 22,
+ "label": "value22"},
+ {"id": 23,
+ "label": "value23"},
+ {"id": 24,
+ "label": "value24"},
+ {"id": 25,
+ "label": "value25"},
+ {"id": 26,
+ "label": "value26"},
+ {"id": 27,
+ "label": "value27"},
+ {"id": 28,
+ "label": "value28"},
+ {"id": 29,
+ "label": "value29"}
+ ]
+ },
+ {"id": 3,
+ "label": "a super long label that is really of unreasonable length but we should make sure it makes it across the bus",
+ "not.a.value": "A useless value",
+ "submenu": [
+ {"id": 10,
+ "label": "value10"},
+ {"id": 11,
+ "label": "value11"},
+ {"id": 12,
+ "label": "value12"},
+ {"id": 13,
+ "label": "value13"},
+ {"id": 14,
+ "label": "value14"},
+ {"id": 15,
+ "label": "value15"},
+ {"id": 16,
+ "label": "value16"},
+ {"id": 17,
+ "label": "value17"},
+ {"id": 18,
+ "label": "value18"},
+ {"id": 19,
+ "label": "value19"}
+ ]
+ },
+ {"id": 4,
+ "label": "value2",
+ "submenu": [
+ {"id": 5,
+ "label": "value5",
+ "submenu": [
+ {"id": 10,
+ "label": "value10"},
+ {"id": 11,
+ "label": "value11"},
+ {"id": 12,
+ "label": "value12"},
+ {"id": 13,
+ "label": "value13"},
+ {"id": 14,
+ "label": "value14"},
+ {"id": 15,
+ "label": "value15"},
+ {"id": 16,
+ "label": "value16"},
+ {"id": 17,
+ "label": "value17"},
+ {"id": 18,
+ "label": "value18"},
+ {"id": 19,
+ "label": "value19"}
+ ]
+ },
+ {"id": 6,
+ "label": "value6",
+ "submenu": [
+ {"id": 20,
+ "label": "value20"},
+ {"id": 21,
+ "label": "value21"},
+ {"id": 22,
+ "label": "value22"},
+ {"id": 23,
+ "label": "value23"},
+ {"id": 24,
+ "label": "value24"},
+ {"id": 25,
+ "label": "value25"},
+ {"id": 26,
+ "label": "value26"},
+ {"id": 27,
+ "label": "value27"},
+ {"id": 28,
+ "label": "value28"},
+ {"id": 29,
+ "label": "value29"}
+ ]
+ },
+ {"id": 7,
+ "label": "value7",
+ "submenu": [
+ {"id": 30,
+ "label": "value30"},
+ {"id": 31,
+ "label": "value31"},
+ {"id": 32,
+ "label": "value32"},
+ {"id": 33,
+ "label": "value33"},
+ {"id": 34,
+ "label": "value34"},
+ {"id": 35,
+ "label": "value35"},
+ {"id": 36,
+ "label": "value36"},
+ {"id": 37,
+ "label": "value37"},
+ {"id": 38,
+ "label": "value38"},
+ {"id": 39,
+ "label": "value39"}
+ ]
+ },
+ ]
+ }
+]