← Back to team overview

ayatana-commits team mailing list archive

[Branch ~dbusmenu-team/dbusmenu/trunk] Rev 42: Fix signal prototype and how the hashtable is handled. Added tests.

 

Merge authors:
  Ted Gould (ted)
Related merge proposals:
  https://code.launchpad.net/~ted/dbusmenu/v2work/+merge/16456
  proposed by: Ted Gould (ted)
  https://code.launchpad.net/~ted/dbusmenu/v2work/+merge/16323
  proposed by: Ted Gould (ted)
  review: Approve - Cody Russell (bratsche)
  review: Approve - Neil J. Patel (njpatel)
------------------------------------------------------------
revno: 42 [merge]
committer: Ted Gould <ted@xxxxxxxx>
branch nick: trunk
timestamp: Tue 2009-12-22 14:36:47 -0600
message:
  Fix signal prototype and how the hashtable is handled.  Added tests.
added:
  tests/test-glib-objects.c
modified:
  .bzrignore
  libdbusmenu-glib/menuitem-marshal.list
  libdbusmenu-glib/menuitem.c
  libdbusmenu-glib/server.c
  tests/Makefile.am


--
lp:dbusmenu
https://code.launchpad.net/~dbusmenu-team/dbusmenu/trunk

Your team ayatana-commits is subscribed to branch lp:dbusmenu.
To unsubscribe from this branch go to https://code.launchpad.net/~dbusmenu-team/dbusmenu/trunk/+edit-subscription.
=== modified file '.bzrignore'
--- .bzrignore	2009-12-17 22:41:01 +0000
+++ .bzrignore	2009-12-21 21:08:03 +0000
@@ -54,3 +54,6 @@
 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

=== modified file 'libdbusmenu-glib/menuitem-marshal.list'
--- libdbusmenu-glib/menuitem-marshal.list	2009-06-23 19:38:58 +0000
+++ libdbusmenu-glib/menuitem-marshal.list	2009-12-19 03:58:26 +0000
@@ -1,4 +1,4 @@
-VOID: STRING, STRING
+VOID: STRING, POINTER
 VOID: OBJECT, UINT, UINT
 VOID: OBJECT, UINT
 VOID: OBJECT

=== modified file 'libdbusmenu-glib/menuitem.c'
--- libdbusmenu-glib/menuitem.c	2009-12-15 20:03:08 +0000
+++ libdbusmenu-glib/menuitem.c	2009-12-21 22:15:45 +0000
@@ -122,8 +122,8 @@
 	                                           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 @@
 /* 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 @@
 	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 @@
 	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;

=== modified file 'libdbusmenu-glib/server.c'
--- libdbusmenu-glib/server.c	2009-12-10 03:50:25 +0000
+++ libdbusmenu-glib/server.c	2009-12-22 03:18:35 +0000
@@ -92,7 +92,7 @@
 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 @@
 }
 
 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;
 }
 

=== modified file 'tests/Makefile.am'
--- tests/Makefile.am	2009-12-17 22:41:01 +0000
+++ tests/Makefile.am	2009-12-21 20:56:49 +0000
@@ -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 @@
 
 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 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 @@
 
 DISTCLEANFILES = \
 	$(TESTS) \
+	$(OBJECT_XML_FILE) \
+	test-glib-objects-test.bustle \
 	test-glib-layout.bustle \
 	test-glib-properties.bustle \
 	test-glib-simple-items.bustle \

=== added file 'tests/test-glib-objects.c'
--- tests/test-glib-objects.c	1970-01-01 00:00:00 +0000
+++ tests/test-glib-objects.c	2009-12-21 22:54:48 +0000
@@ -0,0 +1,277 @@
+/*
+Testing for the various objects just by themselves.
+
+Copyright 2009 Canonical Ltd.
+
+Authors:
+    Ted Gould <ted@xxxxxxxxxxxxx>
+
+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 ();
+}