aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.bzrignore3
-rw-r--r--debian/changelog6
-rw-r--r--libdbusmenu-glib/menuitem.c7
-rw-r--r--tests/Makefile.am26
-rw-r--r--tests/test-glib-objects.c233
5 files changed, 272 insertions, 3 deletions
diff --git a/.bzrignore b/.bzrignore
index 861636f..d506979 100644
--- a/.bzrignore
+++ b/.bzrignore
@@ -55,3 +55,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/debian/changelog b/debian/changelog
index 4621c6f..ab376d2 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+libdbusmenu (0.2.0~dev-0ubuntu1~ppa6~sigfix4) UNRELEASED; urgency=low
+
+ * Using a hash table replace
+
+ -- Ted Gould <ted@ubuntu.com> Mon, 21 Dec 2009 16:16:45 -0600
+
libdbusmenu (0.2.0~dev-0ubuntu1~ppa6~sigfix3) karmic; urgency=low
* debian/rules: Massive debugging
diff --git a/libdbusmenu-glib/menuitem.c b/libdbusmenu-glib/menuitem.c
index ec37da5..a03117c 100644
--- a/libdbusmenu-glib/menuitem.c
+++ b/libdbusmenu-glib/menuitem.c
@@ -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/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..afa669a
--- /dev/null
+++ b/tests/test-glib-objects.c
@@ -0,0 +1,233 @@
+/*
+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;
+}
+
+/* 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);
+ 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 ();
+}