From 9276f061d4565b57a160ece79ec547550195188b Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 18 Dec 2009 22:24:25 -0600 Subject: Making sure we get our function. --- libdbusmenu-glib/menuitem.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libdbusmenu-glib/menuitem.c b/libdbusmenu-glib/menuitem.c index ec37da5..2cefce4 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; -- cgit v1.2.3 From d7f273f9fced68bea1d711503b9a0fd2defa72c6 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 21 Dec 2009 14:29:56 -0600 Subject: Starting a framework for object testing. --- tests/test-glib-objects.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 tests/test-glib-objects.c diff --git a/tests/test-glib-objects.c b/tests/test-glib-objects.c new file mode 100644 index 0000000..cc95b81 --- /dev/null +++ b/tests/test-glib-objects.c @@ -0,0 +1,60 @@ +/* +Testing for the various objects just by themselves. + +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 + +void +test_object_menuitem (void) +{ + + +} + +void +test_object_menuitem_props (void) +{ + + +} + +void +test_glib_objects_suite (void) +{ + g_test_add_func ("/dbusmenu/glib/objects/menuitem", test_object_menuitem); + g_test_add_func ("/dbusmenu/glib/objects/menuitem-props", test_object_menuitem_props); + 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 (); +} -- cgit v1.2.3 From 7f05a7e84a3bf4bf936bc9e81465e7feac1f7487 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 21 Dec 2009 14:41:50 -0600 Subject: Adding the object tests into the build. --- .bzrignore | 2 ++ tests/Makefile.am | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/.bzrignore b/.bzrignore index d7b28a6..66f815e 100644 --- a/.bzrignore +++ b/.bzrignore @@ -54,3 +54,5 @@ 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 diff --git a/tests/Makefile.am b/tests/Makefile.am index 1d58700..0c2ab57 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 \ @@ -70,6 +72,26 @@ test_glib_layout_client_LDADD = \ $(DBUSMENUGLIB_LIBS) +###################### +# Test Glib Object +###################### + +test-glib-objects-test: test-glib-objects Makefile.am + @echo "#!/bin/bash" > $@ + @echo $(DBUS_RUNNER) -b $@.bustle --task gtester --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 +261,7 @@ distclean-local: DISTCLEANFILES = \ $(TESTS) \ + test-glib-objects-test.bustle \ test-glib-layout.bustle \ test-glib-properties.bustle \ test-glib-simple-items.bustle \ -- cgit v1.2.3 From b03128c902c0b9906a34e3cc9f4fc5985d7a06d3 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 21 Dec 2009 14:52:44 -0600 Subject: Adding a menuitem allocation test. --- tests/test-glib-objects.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/test-glib-objects.c b/tests/test-glib-objects.c index cc95b81..cc59751 100644 --- a/tests/test-glib-objects.c +++ b/tests/test-glib-objects.c @@ -27,8 +27,22 @@ with this program. If not, see . 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; } void -- cgit v1.2.3 From 46532dd8beb62a6aa4a639ee646eb0bf1682b75c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 21 Dec 2009 14:56:49 -0600 Subject: Adding in an XML report file. --- tests/Makefile.am | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/Makefile.am b/tests/Makefile.am index 0c2ab57..fa18b9d 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -76,9 +76,11 @@ 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 ./test-glib-objects >> $@ + @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 = \ @@ -261,6 +263,7 @@ distclean-local: DISTCLEANFILES = \ $(TESTS) \ + $(OBJECT_XML_FILE) \ test-glib-objects-test.bustle \ test-glib-layout.bustle \ test-glib-properties.bustle \ -- cgit v1.2.3 From 0d32243f7b12d6d1bc94658a61c4f06c4643051b Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 21 Dec 2009 15:07:39 -0600 Subject: Setting all the different properties. --- tests/test-glib-objects.c | 70 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 67 insertions(+), 3 deletions(-) diff --git a/tests/test-glib-objects.c b/tests/test-glib-objects.c index cc59751..d45baa0 100644 --- a/tests/test-glib-objects.c +++ b/tests/test-glib-objects.c @@ -46,17 +46,81 @@ test_object_menuitem (void) } void -test_object_menuitem_props (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; +} + +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; +} + +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; } void test_glib_objects_suite (void) { - g_test_add_func ("/dbusmenu/glib/objects/menuitem", test_object_menuitem); - g_test_add_func ("/dbusmenu/glib/objects/menuitem-props", test_object_menuitem_props); + 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); return; } -- cgit v1.2.3 From d7480ea88bc34ac80c468e28ce8b6a0704cb3c8c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 21 Dec 2009 15:08:03 -0600 Subject: Ignoring the generated test description. --- .bzrignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.bzrignore b/.bzrignore index 66f815e..06863df 100644 --- a/.bzrignore +++ b/.bzrignore @@ -56,3 +56,4 @@ tests/*.bustle libdbusmenu-gtk/libdbusmenu_gtk_la-genericmenuitem.lo tests/test-glib-objects tests/test-glib-objects-test +tests/test-glib-objects.xml -- cgit v1.2.3 From c96e551eccc631c726e0987ebe8ed859c2305e42 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 21 Dec 2009 15:26:19 -0600 Subject: Testing setting the same prop multiple times of different types. --- tests/test-glib-objects.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/test-glib-objects.c b/tests/test-glib-objects.c index d45baa0..7f79746 100644 --- a/tests/test-glib-objects.c +++ b/tests/test-glib-objects.c @@ -114,6 +114,36 @@ test_object_menuitem_props_bool (void) return; } +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; +} + void test_glib_objects_suite (void) { @@ -121,6 +151,7 @@ test_glib_objects_suite (void) 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); return; } -- cgit v1.2.3 From d33832e3fd108c002216551123d419ec494bd668 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 21 Dec 2009 15:28:08 -0600 Subject: Comments are good for the soul. --- tests/test-glib-objects.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/test-glib-objects.c b/tests/test-glib-objects.c index 7f79746..d63c26d 100644 --- a/tests/test-glib-objects.c +++ b/tests/test-glib-objects.c @@ -24,6 +24,8 @@ with this program. If not, see . #include +/* Building the basic menu item, make sure we didn't break + any core GObject stuff */ void test_object_menuitem (void) { @@ -45,6 +47,7 @@ test_object_menuitem (void) return; } +/* Set a string prop, make sure it's stored as one */ void test_object_menuitem_props_string (void) { @@ -68,6 +71,7 @@ test_object_menuitem_props_string (void) return; } +/* Set an integer prop, make sure it's stored as one */ void test_object_menuitem_props_int (void) { @@ -91,6 +95,7 @@ test_object_menuitem_props_int (void) return; } +/* Set a boolean prop, make sure it's stored as one */ void test_object_menuitem_props_bool (void) { @@ -114,6 +119,8 @@ test_object_menuitem_props_bool (void) return; } +/* Set the same property several times with + different types. */ void test_object_menuitem_props_swap (void) { @@ -144,6 +151,7 @@ test_object_menuitem_props_swap (void) return; } +/* Build the test suite */ void test_glib_objects_suite (void) { -- cgit v1.2.3 From f5a12b2235fe0437d58ec2743382eef39f2b40fc Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 21 Dec 2009 15:59:41 -0600 Subject: Adding test to signal property changes. --- tests/test-glib-objects.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/tests/test-glib-objects.c b/tests/test-glib-objects.c index d63c26d..1807243 100644 --- a/tests/test-glib-objects.c +++ b/tests/test-glib-objects.c @@ -151,6 +151,60 @@ test_object_menuitem_props_swap (void) return; } +/* A helper to put a value into a pointer for eval. */ +void +test_object_menuitem_props_signals_helper (DbusmenuMenuitem * mi, gchar * property, GValue * value, GValue ** out) +{ + if (!g_strcmp0(property, "swapper")) { + *out = value; + } + return; +} + +/* Set the same property several times with + different types. */ +void +test_object_menuitem_props_signals (void) +{ + /* Build a menu item */ + DbusmenuMenuitem * item = dbusmenu_menuitem_new(); + GValue * out; + + /* 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 */ void test_glib_objects_suite (void) @@ -160,6 +214,7 @@ test_glib_objects_suite (void) 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; } -- cgit v1.2.3 From 2d6a51051442499e65f4dade13ba91d13a28fca9 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 21 Dec 2009 16:01:49 -0600 Subject: Making functions static so that we can get warnings if we don't use them. --- tests/test-glib-objects.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/test-glib-objects.c b/tests/test-glib-objects.c index 1807243..9e46128 100644 --- a/tests/test-glib-objects.c +++ b/tests/test-glib-objects.c @@ -26,7 +26,7 @@ with this program. If not, see . /* Building the basic menu item, make sure we didn't break any core GObject stuff */ -void +static void test_object_menuitem (void) { /* Build a menu item */ @@ -48,7 +48,7 @@ test_object_menuitem (void) } /* Set a string prop, make sure it's stored as one */ -void +static void test_object_menuitem_props_string (void) { /* Build a menu item */ @@ -72,7 +72,7 @@ test_object_menuitem_props_string (void) } /* Set an integer prop, make sure it's stored as one */ -void +static void test_object_menuitem_props_int (void) { /* Build a menu item */ @@ -96,7 +96,7 @@ test_object_menuitem_props_int (void) } /* Set a boolean prop, make sure it's stored as one */ -void +static void test_object_menuitem_props_bool (void) { /* Build a menu item */ @@ -121,7 +121,7 @@ test_object_menuitem_props_bool (void) /* Set the same property several times with different types. */ -void +static void test_object_menuitem_props_swap (void) { /* Build a menu item */ @@ -152,7 +152,7 @@ test_object_menuitem_props_swap (void) } /* A helper to put a value into a pointer for eval. */ -void +static void test_object_menuitem_props_signals_helper (DbusmenuMenuitem * mi, gchar * property, GValue * value, GValue ** out) { if (!g_strcmp0(property, "swapper")) { @@ -163,12 +163,12 @@ test_object_menuitem_props_signals_helper (DbusmenuMenuitem * mi, gchar * proper /* Set the same property several times with different types. */ -void +static void test_object_menuitem_props_signals (void) { /* Build a menu item */ DbusmenuMenuitem * item = dbusmenu_menuitem_new(); - GValue * out; + GValue * out = NULL; /* Test to make sure it's a happy object */ g_assert(item != NULL); @@ -206,7 +206,7 @@ test_object_menuitem_props_signals (void) } /* Build the test suite */ -void +static void test_glib_objects_suite (void) { g_test_add_func ("/dbusmenu/glib/objects/menuitem/base", test_object_menuitem); -- cgit v1.2.3 From 14e7084968a1ce9fe8a1c1419351f435acd0eda5 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 21 Dec 2009 16:15:12 -0600 Subject: Fix an assertion that is the wrong direction --- tests/test-glib-objects.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test-glib-objects.c b/tests/test-glib-objects.c index 9e46128..afa669a 100644 --- a/tests/test-glib-objects.c +++ b/tests/test-glib-objects.c @@ -155,6 +155,7 @@ test_object_menuitem_props_swap (void) 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; } @@ -197,7 +198,7 @@ test_object_menuitem_props_signals (void) /* Setting a boolean */ dbusmenu_menuitem_property_set_bool(item, "swapper", FALSE); g_assert(out != NULL); - g_assert(g_value_get_boolean(out)); + g_assert(!g_value_get_boolean(out)); out = NULL; g_object_unref(item); -- cgit v1.2.3 From 7d0dbc3dd6be6ffaeca675b460767e20e505841e Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 21 Dec 2009 16:15:45 -0600 Subject: Switching to a replace so that new values are added. --- libdbusmenu-glib/menuitem.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libdbusmenu-glib/menuitem.c b/libdbusmenu-glib/menuitem.c index 2cefce4..a03117c 100644 --- a/libdbusmenu-glib/menuitem.c +++ b/libdbusmenu-glib/menuitem.c @@ -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 : ""); g_free(valstr); #endif + g_signal_emit(G_OBJECT(mi), signals[PROPERTY_CHANGED], 0, lprop, lval, TRUE); return TRUE; -- cgit v1.2.3