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 (limited to '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 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(+) (limited to 'tests/test-glib-objects.c') 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 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(-) (limited to 'tests/test-glib-objects.c') 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 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(+) (limited to 'tests/test-glib-objects.c') 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(+) (limited to 'tests/test-glib-objects.c') 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(+) (limited to 'tests/test-glib-objects.c') 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(-) (limited to 'tests/test-glib-objects.c') 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(-) (limited to 'tests/test-glib-objects.c') 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 2c02b8e394a55f099b03066774543396078932aa Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 21 Dec 2009 16:54:48 -0600 Subject: Adding a test for the string to boolean convertions --- tests/test-glib-objects.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'tests/test-glib-objects.c') diff --git a/tests/test-glib-objects.c b/tests/test-glib-objects.c index afa669a..7b22b7a 100644 --- a/tests/test-glib-objects.c +++ b/tests/test-glib-objects.c @@ -206,6 +206,49 @@ test_object_menuitem_props_signals (void) 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) @@ -216,6 +259,7 @@ test_glib_objects_suite (void) 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; } -- cgit v1.2.3 From 0c85926daf6361821a4a6023e8756d1634fbfd85 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 22 Dec 2009 20:51:37 -0600 Subject: Removing the bustle captures as we're not using them and they seem to be breaking on Hudson. --- tests/test-glib-objects.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'tests/test-glib-objects.c') diff --git a/tests/test-glib-objects.c b/tests/test-glib-objects.c index 7b22b7a..f3fbcc8 100644 --- a/tests/test-glib-objects.c +++ b/tests/test-glib-objects.c @@ -155,9 +155,10 @@ 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; + } else { + g_warning("Signal handler got: %s", property); } return; } -- cgit v1.2.3