diff options
author | Ted Gould <ted@gould.cx> | 2009-12-22 14:36:47 -0600 |
---|---|---|
committer | Ted Gould <ted@gould.cx> | 2009-12-22 14:36:47 -0600 |
commit | 39cb6247d5a749ce102542adc8a30b73221fb686 (patch) | |
tree | 90a99cbd9adb181f2102d6ef7c47d2d7744e958a | |
parent | ba3999565f0bbc19df01111a1f6dd4108f323aae (diff) | |
parent | e8b9e2835c71ab60df2fd67b4d78b8d08224a975 (diff) | |
download | libdbusmenu-39cb6247d5a749ce102542adc8a30b73221fb686.tar.gz libdbusmenu-39cb6247d5a749ce102542adc8a30b73221fb686.tar.bz2 libdbusmenu-39cb6247d5a749ce102542adc8a30b73221fb686.zip |
Fix signal prototype and how the hashtable is handled. Added tests.
-rw-r--r-- | .bzrignore | 3 | ||||
-rw-r--r-- | libdbusmenu-glib/menuitem-marshal.list | 2 | ||||
-rw-r--r-- | libdbusmenu-glib/menuitem.c | 11 | ||||
-rw-r--r-- | libdbusmenu-glib/server.c | 9 | ||||
-rw-r--r-- | tests/Makefile.am | 26 | ||||
-rw-r--r-- | tests/test-glib-objects.c | 277 |
6 files changed, 316 insertions, 12 deletions
@@ -54,3 +54,6 @@ libdbusmenu-[0-9].[0-9].[0-9].tar.gz.asc tests/test-mago tests/*.bustle libdbusmenu-gtk/libdbusmenu_gtk_la-genericmenuitem.lo +tests/test-glib-objects +tests/test-glib-objects-test +tests/test-glib-objects.xml diff --git a/libdbusmenu-glib/menuitem-marshal.list b/libdbusmenu-glib/menuitem-marshal.list index a32e7e3..dc4ba53 100644 --- a/libdbusmenu-glib/menuitem-marshal.list +++ b/libdbusmenu-glib/menuitem-marshal.list @@ -1,4 +1,4 @@ -VOID: STRING, STRING +VOID: STRING, POINTER VOID: OBJECT, UINT, UINT VOID: OBJECT, UINT VOID: OBJECT diff --git a/libdbusmenu-glib/menuitem.c b/libdbusmenu-glib/menuitem.c index dc01157..a03117c 100644 --- a/libdbusmenu-glib/menuitem.c +++ b/libdbusmenu-glib/menuitem.c @@ -122,8 +122,8 @@ dbusmenu_menuitem_class_init (DbusmenuMenuitemClass *klass) G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET(DbusmenuMenuitemClass, property_changed), NULL, NULL, - _dbusmenu_menuitem_marshal_VOID__STRING_STRING, - G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_STRING); + _dbusmenu_menuitem_marshal_VOID__STRING_POINTER, + G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_POINTER); /** DbusmenuMenuitem::item-activated: @arg0: The #DbusmenuMenuitem object. @@ -250,7 +250,7 @@ static guint menuitem_next_id = 1; /* A small little function to both clear the insides of a value as well as the memory it itself uses. */ static void -g_value_free (gpointer data) +_g_value_free (gpointer data) { if (data == NULL) return; GValue * value = (GValue*)data; @@ -269,7 +269,7 @@ dbusmenu_menuitem_init (DbusmenuMenuitem *self) priv->id = 0; priv->children = NULL; - priv->properties = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_value_free); + priv->properties = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, _g_value_free); priv->root = FALSE; @@ -815,12 +815,13 @@ dbusmenu_menuitem_property_set_value (DbusmenuMenuitem * mi, const gchar * prope g_value_init(lval, G_VALUE_TYPE(value)); g_value_copy(value, lval); - g_hash_table_insert(priv->properties, lprop, lval); + g_hash_table_replace(priv->properties, lprop, lval); #ifdef MASSIVEDEBUGGING gchar * valstr = g_strdup_value_contents(lval); g_debug("Menuitem %d (%s) signalling property '%s' changed to '%s'", ID(mi), LABEL(mi), property, g_utf8_strlen(valstr, 50) < 25 ? valstr : "<too long>"); g_free(valstr); #endif + g_signal_emit(G_OBJECT(mi), signals[PROPERTY_CHANGED], 0, lprop, lval, TRUE); return TRUE; diff --git a/libdbusmenu-glib/server.c b/libdbusmenu-glib/server.c index f61b0fb..0825997 100644 --- a/libdbusmenu-glib/server.c +++ b/libdbusmenu-glib/server.c @@ -92,7 +92,7 @@ static void dbusmenu_server_dispose (GObject *object); static void dbusmenu_server_finalize (GObject *object); static void set_property (GObject * obj, guint id, const GValue * value, GParamSpec * pspec); static void get_property (GObject * obj, guint id, GValue * value, GParamSpec * pspec); -static void menuitem_property_changed (DbusmenuMenuitem * mi, gchar * property, gchar * value, DbusmenuServer * server); +static void menuitem_property_changed (DbusmenuMenuitem * mi, gchar * property, GValue * value, DbusmenuServer * server); static void menuitem_child_added (DbusmenuMenuitem * parent, DbusmenuMenuitem * child, guint pos, DbusmenuServer * server); static void menuitem_child_removed (DbusmenuMenuitem * parent, DbusmenuMenuitem * child, DbusmenuServer * server); static void menuitem_signals_create (DbusmenuMenuitem * mi, gpointer data); @@ -292,12 +292,9 @@ get_property (GObject * obj, guint id, GValue * value, GParamSpec * pspec) } static void -menuitem_property_changed (DbusmenuMenuitem * mi, gchar * property, gchar * strvalue, DbusmenuServer * server) +menuitem_property_changed (DbusmenuMenuitem * mi, gchar * property, GValue * value, DbusmenuServer * server) { - GValue value = {0}; - g_value_init(&value, G_TYPE_STRING); - g_value_set_static_string(&value, strvalue); - g_signal_emit(G_OBJECT(server), signals[ID_PROP_UPDATE], 0, dbusmenu_menuitem_get_id(mi), property, &value, TRUE); + g_signal_emit(G_OBJECT(server), signals[ID_PROP_UPDATE], 0, dbusmenu_menuitem_get_id(mi), property, value, TRUE); return; } diff --git a/tests/Makefile.am b/tests/Makefile.am index 1d58700..fa18b9d 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -2,6 +2,7 @@ DBUS_RUNNER=dbus-test-runner TESTS = \ + test-glib-objects-test \ test-glib-layout \ test-glib-properties \ test-glib-simple-items \ @@ -10,6 +11,7 @@ TESTS = \ check_PROGRAMS = \ glib-server-nomenu \ + test-glib-objects \ test-glib-layout-client \ test-glib-layout-server \ test-glib-properties-client \ @@ -71,6 +73,28 @@ test_glib_layout_client_LDADD = \ ###################### +# Test Glib Object +###################### + +OBJECT_XML_REPORT = test-glib-objects.xml + +test-glib-objects-test: test-glib-objects Makefile.am + @echo "#!/bin/bash" > $@ + @echo $(DBUS_RUNNER) -b $@.bustle --task gtester --parameter -k --parameter -o --parameter $(OBJECT_XML_REPORT) --parameter ./test-glib-objects >> $@ + @chmod +x $@ + +test_glib_objects_SOURCES = \ + test-glib-objects.c + +test_glib_objects_CFLAGS = \ + -I $(srcdir)/.. \ + $(DBUSMENUGLIB_CFLAGS) -Wall -Werror + +test_glib_objects_LDADD = \ + ../libdbusmenu-glib/libdbusmenu-glib.la \ + $(DBUSMENUGLIB_LIBS) + +###################### # Test Glib Properties ###################### @@ -239,6 +263,8 @@ distclean-local: DISTCLEANFILES = \ $(TESTS) \ + $(OBJECT_XML_FILE) \ + test-glib-objects-test.bustle \ test-glib-layout.bustle \ test-glib-properties.bustle \ test-glib-simple-items.bustle \ diff --git a/tests/test-glib-objects.c b/tests/test-glib-objects.c new file mode 100644 index 0000000..7b22b7a --- /dev/null +++ b/tests/test-glib-objects.c @@ -0,0 +1,277 @@ +/* +Testing for the various objects just by themselves. + +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 <glib-object.h> + +#include <libdbusmenu-glib/menuitem.h> + +/* Building the basic menu item, make sure we didn't break + any core GObject stuff */ +static void +test_object_menuitem (void) +{ + /* Build a menu item */ + DbusmenuMenuitem * item = dbusmenu_menuitem_new(); + + /* Test to make sure it's a happy object */ + g_assert(item != NULL); + g_assert(G_IS_OBJECT(item)); + g_assert(DBUSMENU_IS_MENUITEM(item)); + + /* Set up a check to make sure it gets destroyed on unref */ + g_object_add_weak_pointer(G_OBJECT(item), (gpointer *)&item); + g_object_unref(item); + + /* Did it go away? */ + g_assert(item == NULL); + + return; +} + +/* Set a string prop, make sure it's stored as one */ +static void +test_object_menuitem_props_string (void) +{ + /* Build a menu item */ + DbusmenuMenuitem * item = dbusmenu_menuitem_new(); + const GValue * out = NULL; + + /* Test to make sure it's a happy object */ + g_assert(item != NULL); + + /* Setting a string */ + dbusmenu_menuitem_property_set(item, "string", "value"); + out = dbusmenu_menuitem_property_get_value(item, "string"); + g_assert(out != NULL); + g_assert(G_VALUE_TYPE(out) == G_TYPE_STRING); + g_assert(!g_strcmp0(g_value_get_string(out), "value")); + g_assert(!g_strcmp0(dbusmenu_menuitem_property_get(item, "string"), "value")); + + g_object_unref(item); + + return; +} + +/* Set an integer prop, make sure it's stored as one */ +static void +test_object_menuitem_props_int (void) +{ + /* Build a menu item */ + DbusmenuMenuitem * item = dbusmenu_menuitem_new(); + const GValue * out = NULL; + + /* Test to make sure it's a happy object */ + g_assert(item != NULL); + + /* Setting a string */ + dbusmenu_menuitem_property_set_int(item, "int", 12345); + out = dbusmenu_menuitem_property_get_value(item, "int"); + g_assert(out != NULL); + g_assert(G_VALUE_TYPE(out) == G_TYPE_INT); + g_assert(g_value_get_int(out) == 12345); + g_assert(dbusmenu_menuitem_property_get_int(item, "int") == 12345); + + g_object_unref(item); + + return; +} + +/* Set a boolean prop, make sure it's stored as one */ +static void +test_object_menuitem_props_bool (void) +{ + /* Build a menu item */ + DbusmenuMenuitem * item = dbusmenu_menuitem_new(); + const GValue * out = NULL; + + /* Test to make sure it's a happy object */ + g_assert(item != NULL); + + /* Setting a string */ + dbusmenu_menuitem_property_set_bool(item, "boolean", TRUE); + out = dbusmenu_menuitem_property_get_value(item, "boolean"); + g_assert(out != NULL); + g_assert(G_VALUE_TYPE(out) == G_TYPE_BOOLEAN); + g_assert(g_value_get_boolean(out)); + g_assert(dbusmenu_menuitem_property_get_int(item, "boolean")); + + g_object_unref(item); + + return; +} + +/* Set the same property several times with + different types. */ +static void +test_object_menuitem_props_swap (void) +{ + /* Build a menu item */ + DbusmenuMenuitem * item = dbusmenu_menuitem_new(); + + /* Test to make sure it's a happy object */ + g_assert(item != NULL); + + /* Setting a boolean */ + dbusmenu_menuitem_property_set_bool(item, "swapper", TRUE); + g_assert(dbusmenu_menuitem_property_get_bool(item, "swapper")); + + /* Setting a int */ + dbusmenu_menuitem_property_set_int(item, "swapper", 5432); + g_assert(dbusmenu_menuitem_property_get_int(item, "swapper") == 5432); + + /* Setting a string */ + dbusmenu_menuitem_property_set(item, "swapper", "mystring"); + g_assert(!g_strcmp0(dbusmenu_menuitem_property_get(item, "swapper"), "mystring")); + + /* Setting a boolean */ + dbusmenu_menuitem_property_set_bool(item, "swapper", FALSE); + g_assert(!dbusmenu_menuitem_property_get_bool(item, "swapper")); + + g_object_unref(item); + + return; +} + +/* A helper to put a value into a pointer for eval. */ +static void +test_object_menuitem_props_signals_helper (DbusmenuMenuitem * mi, gchar * property, GValue * value, GValue ** out) +{ + /* g_debug("Signal handler got: %s", property); */ + if (!g_strcmp0(property, "swapper")) { + *out = value; + } + return; +} + +/* Set the same property several times with + different types. */ +static void +test_object_menuitem_props_signals (void) +{ + /* Build a menu item */ + DbusmenuMenuitem * item = dbusmenu_menuitem_new(); + GValue * out = NULL; + + /* Test to make sure it's a happy object */ + g_assert(item != NULL); + + /* Setting up our callback */ + g_signal_connect(G_OBJECT(item), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, G_CALLBACK(test_object_menuitem_props_signals_helper), &out); + + /* Setting a boolean */ + dbusmenu_menuitem_property_set_bool(item, "swapper", TRUE); + g_assert(out != NULL); + g_assert(g_value_get_boolean(out)); + out = NULL; + + /* Setting a int */ + dbusmenu_menuitem_property_set_int(item, "swapper", 5432); + g_assert(out != NULL); + g_assert(g_value_get_int(out) == 5432); + out = NULL; + + /* Setting a string */ + dbusmenu_menuitem_property_set(item, "swapper", "mystring"); + g_assert(out != NULL); + g_assert(!g_strcmp0(g_value_get_string(out), "mystring")); + out = NULL; + + /* Setting a boolean */ + dbusmenu_menuitem_property_set_bool(item, "swapper", FALSE); + g_assert(out != NULL); + g_assert(!g_value_get_boolean(out)); + out = NULL; + + g_object_unref(item); + + return; +} + +/* Set a boolean prop, as a string too! */ +static void +test_object_menuitem_props_boolstr (void) +{ + /* Build a menu item */ + DbusmenuMenuitem * item = dbusmenu_menuitem_new(); + + /* Test to make sure it's a happy object */ + g_assert(item != NULL); + + /* Setting a bool */ + dbusmenu_menuitem_property_set_bool(item, "boolean", TRUE); + g_assert(dbusmenu_menuitem_property_get_bool(item, "boolean")); + + /* Setting "true" */ + dbusmenu_menuitem_property_set(item, "boolean", "true"); + g_assert(dbusmenu_menuitem_property_get_bool(item, "boolean")); + + /* Setting "True" */ + dbusmenu_menuitem_property_set(item, "boolean", "True"); + g_assert(dbusmenu_menuitem_property_get_bool(item, "boolean")); + + /* Setting "TRUE" */ + dbusmenu_menuitem_property_set(item, "boolean", "TRUE"); + g_assert(dbusmenu_menuitem_property_get_bool(item, "boolean")); + + /* Setting "false" */ + dbusmenu_menuitem_property_set(item, "boolean", "false"); + g_assert(!dbusmenu_menuitem_property_get_bool(item, "boolean")); + + /* Setting "False" */ + dbusmenu_menuitem_property_set(item, "boolean", "False"); + g_assert(!dbusmenu_menuitem_property_get_bool(item, "boolean")); + + /* Setting "FALSE" */ + dbusmenu_menuitem_property_set(item, "boolean", "FALSE"); + g_assert(!dbusmenu_menuitem_property_get_bool(item, "boolean")); + + g_object_unref(item); + + return; +} + +/* Build the test suite */ +static void +test_glib_objects_suite (void) +{ + g_test_add_func ("/dbusmenu/glib/objects/menuitem/base", test_object_menuitem); + g_test_add_func ("/dbusmenu/glib/objects/menuitem/props_string", test_object_menuitem_props_string); + g_test_add_func ("/dbusmenu/glib/objects/menuitem/props_int", test_object_menuitem_props_int); + g_test_add_func ("/dbusmenu/glib/objects/menuitem/props_bool", test_object_menuitem_props_bool); + g_test_add_func ("/dbusmenu/glib/objects/menuitem/props_swap", test_object_menuitem_props_swap); + g_test_add_func ("/dbusmenu/glib/objects/menuitem/props_signals", test_object_menuitem_props_signals); + g_test_add_func ("/dbusmenu/glib/objects/menuitem/props_boolstr", test_object_menuitem_props_boolstr); + return; +} + +gint +main (gint argc, gchar * argv[]) +{ + g_type_init(); + g_test_init(&argc, &argv, NULL); + + /* Test suites */ + test_glib_objects_suite(); + + + return g_test_run (); +} |