From 094553712ca5087ccba1df594643c0538e7d1aaa Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 13 May 2009 23:14:22 -0500 Subject: First parts of some tests to test the properties. --- tests/test-glib-properties-client.c | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 tests/test-glib-properties-client.c (limited to 'tests/test-glib-properties-client.c') diff --git a/tests/test-glib-properties-client.c b/tests/test-glib-properties-client.c new file mode 100644 index 0000000..bcbd170 --- /dev/null +++ b/tests/test-glib-properties-client.c @@ -0,0 +1,9 @@ + +#include "test-glib-properties.h" + +int +main (int argc, char * argv[]) +{ + + return 0; +} -- cgit v1.2.3 From b5312e7a0591a734a463d3eb50ff565605f210bf Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 15 May 2009 14:12:51 -0500 Subject: Adding in a function to get the properties, and make sure to catch soem more warnings and other protections. Also, no more deprecated GTK stuf. --- libdbusmenu-glib/Makefile.am | 2 +- libdbusmenu-glib/menuitem.c | 24 +++++++ libdbusmenu-glib/menuitem.h | 7 +- tests/test-glib-properties-client.c | 134 +++++++++++++++++++++++++++++++++++- 4 files changed, 161 insertions(+), 6 deletions(-) (limited to 'tests/test-glib-properties-client.c') diff --git a/libdbusmenu-glib/Makefile.am b/libdbusmenu-glib/Makefile.am index 844e1b8..a485f2b 100644 --- a/libdbusmenu-glib/Makefile.am +++ b/libdbusmenu-glib/Makefile.am @@ -35,7 +35,7 @@ libdbusmenu_glib_la_LDFLAGS = \ -export-symbols-regex "^[^_].*" libdbusmenu_glib_la_CFLAGS = \ - $(DBUSMENUGLIB_CFLAGS) -Wall -Werror + $(DBUSMENUGLIB_CFLAGS) -Wall -Werror -DG_DISABLE_DEPRECATED libdbusmenu_glib_la_LIBADD = \ $(DBUSMENUGLIB_LIBS) diff --git a/libdbusmenu-glib/menuitem.c b/libdbusmenu-glib/menuitem.c index e017721..6145ba2 100644 --- a/libdbusmenu-glib/menuitem.c +++ b/libdbusmenu-glib/menuitem.c @@ -601,6 +601,26 @@ dbusmenu_menuitem_property_exist (DbusmenuMenuitem * mi, const gchar * property) return value != NULL; } +/** + dbusmenu_menuitem_properties_list: + @mi: #DbusmenuMenuitem to list the properties on + + This functiong gets a list of the names of all the properties + that are set on this menu item. This data on the list is owned + by the menuitem but the list is not and should be freed using + g_list_free() when the calling function is done with it. + + Return value: A list of strings or NULL if there are none. +*/ +GList * +dbusmenu_menuitem_properties_list (DbusmenuMenuitem * mi) +{ + g_return_val_if_fail(DBUSMENU_IS_MENUITEM(mi), NULL); + + DbusmenuMenuitemPrivate * priv = DBUSMENU_MENUITEM_GET_PRIVATE(mi); + return g_hash_table_get_keys(priv->properties); +} + /** dbusmenu_menuitem_buildxml: @mi: #DbusmenuMenuitem to represent in XML @@ -657,6 +677,9 @@ foreach_helper (gpointer data, gpointer user_data) void dbusmenu_menuitem_foreach (DbusmenuMenuitem * mi, void (*func) (DbusmenuMenuitem * mi, gpointer data), gpointer data) { + g_return_if_fail(DBUSMENU_IS_MENUITEM(mi)); + g_return_if_fail(func != NULL); + func(mi, data); GList * children = dbusmenu_menuitem_get_children(mi); foreach_struct_t foreach_data = {func: func, data: data}; @@ -675,6 +698,7 @@ dbusmenu_menuitem_foreach (DbusmenuMenuitem * mi, void (*func) (DbusmenuMenuitem void dbusmenu_menuitem_activate (DbusmenuMenuitem * mi) { + g_return_if_fail(DBUSMENU_IS_MENUITEM(mi)); g_signal_emit(G_OBJECT(mi), signals[ITEM_ACTIVATED], 0, TRUE); return; } diff --git a/libdbusmenu-glib/menuitem.h b/libdbusmenu-glib/menuitem.h index e2786cc..f820a7a 100644 --- a/libdbusmenu-glib/menuitem.h +++ b/libdbusmenu-glib/menuitem.h @@ -98,12 +98,12 @@ struct _DbusmenuMenuitemClass GType dbusmenu_menuitem_get_type (void); -DbusmenuMenuitem * dbusmenu_menuitem_new (void); -DbusmenuMenuitem * dbusmenu_menuitem_new_with_id (guint id); +DbusmenuMenuitem * dbusmenu_menuitem_new (void) G_GNUC_WARN_UNUSED_RESULT; +DbusmenuMenuitem * dbusmenu_menuitem_new_with_id (guint id) G_GNUC_WARN_UNUSED_RESULT; guint dbusmenu_menuitem_get_id (DbusmenuMenuitem * mi); GList * dbusmenu_menuitem_get_children (DbusmenuMenuitem * mi); -GList * dbusmenu_menuitem_take_children (DbusmenuMenuitem * mi); +GList * dbusmenu_menuitem_take_children (DbusmenuMenuitem * mi) G_GNUC_WARN_UNUSED_RESULT; guint dbusmenu_menuitem_get_position (DbusmenuMenuitem * mi, DbusmenuMenuitem * parent); gboolean dbusmenu_menuitem_child_append (DbusmenuMenuitem * mi, DbusmenuMenuitem * child); @@ -115,6 +115,7 @@ DbusmenuMenuitem * dbusmenu_menuitem_find_id (DbusmenuMenuitem * mi, guint id); gboolean dbusmenu_menuitem_property_set (DbusmenuMenuitem * mi, const gchar * property, const gchar * value); const gchar * dbusmenu_menuitem_property_get (DbusmenuMenuitem * mi, const gchar * property); gboolean dbusmenu_menuitem_property_exist (DbusmenuMenuitem * mi, const gchar * property); +GList * dbusmenu_menuitem_properties_list (DbusmenuMenuitem * mi) G_GNUC_WARN_UNUSED_RESULT; void dbusmenu_menuitem_buildxml (DbusmenuMenuitem * mi, GPtrArray * array); void dbusmenu_menuitem_foreach (DbusmenuMenuitem * mi, void (*func) (DbusmenuMenuitem * mi, gpointer data), gpointer data); diff --git a/tests/test-glib-properties-client.c b/tests/test-glib-properties-client.c index bcbd170..244b7c4 100644 --- a/tests/test-glib-properties-client.c +++ b/tests/test-glib-properties-client.c @@ -1,9 +1,139 @@ +/* +A test for libdbusmenu to ensure its quality. + +Copyright 2009 Canonical Ltd. + +Authors: + Ted Gould + +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 . +*/ + +#include + +#include +#include #include "test-glib-properties.h" +static guint layouton = 0; +static GMainLoop * mainloop = NULL; +static gboolean passed = TRUE; + +static gboolean +verify_props (DbusmenuMenuitem * mi, gchar ** properties) +{ + + + +} + +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("Failed as ID %d is not equal to %d", layout->id, dbusmenu_menuitem_get_id(mi)); + return FALSE; + } + + if (!veryify_props(mi, layout->properties)) { + return FALSE; + } + + GList * children = dbusmenu_menuitem_get_children(mi); + + if (children == NULL && layout->submenu == NULL) { + return TRUE; + } + if (children == NULL || layout->submenu == NULL) { + if (children == NULL) { + g_debug("Failed as there are no children but we have submenus"); + } else { + g_debug("Failed 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) { + return TRUE; + } + + if (children != NULL) { + g_debug("Failed as there are still children but no submenus. (ID: %d)", layout->id); + } else { + g_debug("Failed as there are still submenus but no children. (ID: %d)", layout->id); + } + return FALSE; +} + +static void +layout_updated (DbusmenuClient * client, gpointer data) +{ + g_debug("Layout Updated"); + + DbusmenuMenuitem * menuroot = dbusmenu_client_get_root(client); + proplayout_t * layout = &layouts[layouton]; + + if (!verify_root_to_layout(menuroot, layout)) { + g_debug("Failed layout: %d", layouton); + passed = FALSE; + } + + layouton++; + + return; +} + +static gboolean +timer_func (gpointer data) +{ + g_debug("Death timer. Oops. Got to: %d", layouton); + passed = FALSE; + g_main_loop_quit(mainloop); + return FALSE; +} + int -main (int argc, char * argv[]) +main (int argc, char ** argv) { + g_type_init(); + + g_usleep(500000); + + DbusmenuClient * client = dbusmenu_client_new(":1.0", "/org/test"); + g_signal_connect(G_OBJECT(client), DBUSMENU_CLIENT_SIGNAL_LAYOUT_UPDATED, G_CALLBACK(layout_updated), NULL); + + 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)); - return 0; + if (passed) { + g_debug("Quiting"); + return 0; + } else { + g_debug("Quiting as we're a failure"); + return 0; + } } -- cgit v1.2.3 From cc8b4e70486af063785d0dd6ea42c382a2d84aa4 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 15 May 2009 15:19:12 -0500 Subject: Oops, that didn't compile. --- tests/test-glib-properties-client.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'tests/test-glib-properties-client.c') diff --git a/tests/test-glib-properties-client.c b/tests/test-glib-properties-client.c index 244b7c4..7fe9b8f 100644 --- a/tests/test-glib-properties-client.c +++ b/tests/test-glib-properties-client.c @@ -33,9 +33,11 @@ static gboolean passed = TRUE; static gboolean verify_props (DbusmenuMenuitem * mi, gchar ** properties) { + if (properties == NULL) { + return TRUE; + } - - + return TRUE; } static gboolean @@ -48,7 +50,7 @@ verify_root_to_layout(DbusmenuMenuitem * mi, proplayout_t * layout) return FALSE; } - if (!veryify_props(mi, layout->properties)) { + if (!verify_props(mi, layout->properties)) { return FALSE; } -- cgit v1.2.3 From 9f3095425e166de4b82c0066057749edafe3980e Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 19 May 2009 04:15:57 +0200 Subject: Cleaning up pass and fail message to make them more readable --- tests/test-glib-properties-client.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'tests/test-glib-properties-client.c') diff --git a/tests/test-glib-properties-client.c b/tests/test-glib-properties-client.c index 7fe9b8f..11cd70d 100644 --- a/tests/test-glib-properties-client.c +++ b/tests/test-glib-properties-client.c @@ -46,24 +46,26 @@ 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("Failed as ID %d is not equal to %d", 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("Failed as there are no children but we have submenus"); + g_debug("\tFailed as there are no children but we have submenus"); } else { - g_debug("Failed as we have children but no submenu"); + g_debug("\tFailed as we have children but no submenu"); } return FALSE; } @@ -76,13 +78,14 @@ verify_root_to_layout(DbusmenuMenuitem * mi, proplayout_t * layout) } if (children == NULL && layout->submenu[i].id == 0) { + g_debug("\tPassed: %d", layout->id); return TRUE; } if (children != NULL) { - g_debug("Failed as there are still children but no submenus. (ID: %d)", layout->id); + g_debug("\tFailed as there are still children but no submenus. (ID: %d)", layout->id); } else { - g_debug("Failed as there are still submenus but no children. (ID: %d)", layout->id); + g_debug("\tFailed as there are still submenus but no children. (ID: %d)", layout->id); } return FALSE; } -- cgit v1.2.3 From 17a0a712d5187101216ed937955c6871a000d8b0 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 19 May 2009 04:24:27 +0200 Subject: Handling death better. Now we extend our life the more successful we are. Plus if we get through all the layouts we quit right then. --- tests/test-glib-properties-client.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) (limited to 'tests/test-glib-properties-client.c') diff --git a/tests/test-glib-properties-client.c b/tests/test-glib-properties-client.c index 11cd70d..d840217 100644 --- a/tests/test-glib-properties-client.c +++ b/tests/test-glib-properties-client.c @@ -29,6 +29,7 @@ with this program. If not, see . static guint layouton = 0; static GMainLoop * mainloop = NULL; static gboolean passed = TRUE; +static guint death_timer = 0; static gboolean verify_props (DbusmenuMenuitem * mi, gchar ** properties) @@ -90,6 +91,15 @@ verify_root_to_layout(DbusmenuMenuitem * mi, proplayout_t * layout) 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 void layout_updated (DbusmenuClient * client, gpointer data) { @@ -99,35 +109,35 @@ layout_updated (DbusmenuClient * client, gpointer data) proplayout_t * layout = &layouts[layouton]; if (!verify_root_to_layout(menuroot, layout)) { - g_debug("Failed layout: %d", layouton); + 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, client); } layouton++; + + if (layouts[layouton].id == 0) { + g_main_loop_quit(mainloop); + } return; } -static gboolean -timer_func (gpointer data) -{ - g_debug("Death timer. Oops. Got to: %d", layouton); - passed = FALSE; - g_main_loop_quit(mainloop); - return FALSE; -} - int main (int argc, char ** argv) { g_type_init(); + /* Make sure the server starts up and all that */ g_usleep(500000); DbusmenuClient * client = dbusmenu_client_new(":1.0", "/org/test"); g_signal_connect(G_OBJECT(client), DBUSMENU_CLIENT_SIGNAL_LAYOUT_UPDATED, G_CALLBACK(layout_updated), NULL); - g_timeout_add_seconds(10, timer_func, client); + death_timer = g_timeout_add_seconds(10, timer_func, client); mainloop = g_main_loop_new(NULL, FALSE); g_main_loop_run(mainloop); -- cgit v1.2.3 From 85ff79a58f531a5173565bbe1b97b5a9c7e4148e Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 19 May 2009 04:34:59 +0200 Subject: Starting to verify the properties --- tests/test-glib-properties-client.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'tests/test-glib-properties-client.c') diff --git a/tests/test-glib-properties-client.c b/tests/test-glib-properties-client.c index d840217..145e4fd 100644 --- a/tests/test-glib-properties-client.c +++ b/tests/test-glib-properties-client.c @@ -38,6 +38,19 @@ verify_props (DbusmenuMenuitem * mi, gchar ** properties) 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; } -- cgit v1.2.3 From 0386af8ac00626ace16cd3c882a1bc261a4cc256 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 19 May 2009 04:42:50 +0200 Subject: Making it so that the verifcation hapens slightly after the update, as it takes a couple of milliseconds for the properties to trasfer over DBus. --- tests/test-glib-properties-client.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'tests/test-glib-properties-client.c') diff --git a/tests/test-glib-properties-client.c b/tests/test-glib-properties-client.c index 145e4fd..4439788 100644 --- a/tests/test-glib-properties-client.c +++ b/tests/test-glib-properties-client.c @@ -113,12 +113,20 @@ timer_func (gpointer data) return FALSE; } +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; +} - DbusmenuMenuitem * menuroot = dbusmenu_client_get_root(client); +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)) { @@ -127,7 +135,7 @@ layout_updated (DbusmenuClient * client, gpointer data) } else { /* Extend our death */ g_source_remove(death_timer); - death_timer = g_timeout_add_seconds(10, timer_func, client); + death_timer = g_timeout_add_seconds(10, timer_func, data); } layouton++; @@ -136,7 +144,7 @@ layout_updated (DbusmenuClient * client, gpointer data) g_main_loop_quit(mainloop); } - return; + return FALSE; } int -- cgit v1.2.3