From b29f86be192fda821b7245b6159fa1aefc623a40 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 14 Jun 2010 13:10:18 -0500 Subject: Adding in a new gtester test suite. --- tests/test-gtk-objects.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 tests/test-gtk-objects.c (limited to 'tests/test-gtk-objects.c') diff --git a/tests/test-gtk-objects.c b/tests/test-gtk-objects.c new file mode 100644 index 0000000..561f91e --- /dev/null +++ b/tests/test-gtk-objects.c @@ -0,0 +1,67 @@ +/* +Testing for the various objects just by themselves. + +Copyright 2010 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 + +/* 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; +} + +/* Build the test suite */ +static void +test_gtk_objects_suite (void) +{ + g_test_add_func ("/dbusmenu/gtk/objects/menuitem/base", test_object_menuitem); + return; +} + +gint +main (gint argc, gchar * argv[]) +{ + gtk_init(&argc, &argv); + + g_test_init(&argc, &argv, NULL); + + /* Test suites */ + test_gtk_objects_suite(); + + return g_test_run (); +} -- cgit v1.2.3 From ecf64a2f000ee9666a263afe23075d36bf2efe9a Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 14 Jun 2010 13:54:12 -0500 Subject: Adding in a test for the pixbuf property --- tests/test-gtk-objects.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'tests/test-gtk-objects.c') diff --git a/tests/test-gtk-objects.c b/tests/test-gtk-objects.c index 561f91e..c9f9c4c 100644 --- a/tests/test-gtk-objects.c +++ b/tests/test-gtk-objects.c @@ -22,6 +22,8 @@ with this program. If not, see . #include #include +#define TEST_IMAGE SRCDIR "/" "test-gtk-objects.jpg" + /* Building the basic menu item, make sure we didn't break any core GObject stuff */ static void @@ -45,11 +47,49 @@ test_object_menuitem (void) return; } +/* Setting and getting a pixbuf */ +static void +test_object_prop_pixbuf (void) +{ + const gchar * prop_name = "image-test"; + + /* 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)); + + /* Load our image */ + GdkPixbuf * pixbuf = gdk_pixbuf_new_from_file(TEST_IMAGE, NULL); + g_assert(pixbuf != NULL); + + /* Set the property */ + gboolean success = dbusmenu_menuitem_property_set_image(item, prop_name, pixbuf); + g_assert(success); + g_object_unref(pixbuf); + + /* Check to see if it's set */ + const GValue * val = dbusmenu_menuitem_property_get_value(item, prop_name); + g_assert(val != NULL); + + /* Get the pixbuf back! */ + GdkPixbuf * newpixbuf = dbusmenu_menuitem_property_get_image(item, prop_name); + g_assert(newpixbuf != NULL); + g_object_unref(newpixbuf); + + g_object_unref(item); + + return; +} + /* Build the test suite */ static void test_gtk_objects_suite (void) { g_test_add_func ("/dbusmenu/gtk/objects/menuitem/base", test_object_menuitem); + g_test_add_func ("/dbusmenu/gtk/objects/menuitem/prop_pixbuf", test_object_prop_pixbuf); return; } -- cgit v1.2.3 From 13fd7c6e7182b3142c6951098dcd2172c9ddf4ca Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 14 Jun 2010 14:09:09 -0500 Subject: Add a test to set the shortcut on a menuitem --- tests/test-gtk-objects.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'tests/test-gtk-objects.c') diff --git a/tests/test-gtk-objects.c b/tests/test-gtk-objects.c index c9f9c4c..92f2469 100644 --- a/tests/test-gtk-objects.c +++ b/tests/test-gtk-objects.c @@ -21,6 +21,7 @@ with this program. If not, see . #include #include +#include #define TEST_IMAGE SRCDIR "/" "test-gtk-objects.jpg" @@ -84,12 +85,41 @@ test_object_prop_pixbuf (void) return; } +/* Setting and getting a shortcut */ +static void +test_object_prop_shortcut (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)); + + guint key = GDK_c; + GdkModifierType modifier = GDK_CONTROL_MASK; + + /* Set a shortcut */ + gboolean success = dbusmenu_menuitem_property_set_shortcut(item, key, modifier); + g_assert(success); + + /* Check for value */ + const GValue * val = dbusmenu_menuitem_property_get_value(item, DBUSMENU_MENUITEM_PROP_SHORTCUT); + g_assert(val != NULL); + + g_object_unref(item); + + return; +} + /* Build the test suite */ static void test_gtk_objects_suite (void) { g_test_add_func ("/dbusmenu/gtk/objects/menuitem/base", test_object_menuitem); g_test_add_func ("/dbusmenu/gtk/objects/menuitem/prop_pixbuf", test_object_prop_pixbuf); + g_test_add_func ("/dbusmenu/gtk/objects/menuitem/prop_shortcut", test_object_prop_shortcut); return; } -- cgit v1.2.3 From ac0a5299c1fe73acb30f34939dfcd6af57c12231 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 14 Jun 2010 14:52:26 -0500 Subject: Testing we can get the modifier back out. --- tests/test-gtk-objects.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tests/test-gtk-objects.c') diff --git a/tests/test-gtk-objects.c b/tests/test-gtk-objects.c index 92f2469..726f404 100644 --- a/tests/test-gtk-objects.c +++ b/tests/test-gtk-objects.c @@ -108,6 +108,14 @@ test_object_prop_shortcut (void) const GValue * val = dbusmenu_menuitem_property_get_value(item, DBUSMENU_MENUITEM_PROP_SHORTCUT); g_assert(val != NULL); + /* Check to see if we love it */ + guint newkey = 0; + GdkModifierType newmodifier = 0; + dbusmenu_menuitem_property_get_shortcut(item, &newkey, &newmodifier); + + g_assert(key == newkey); + g_assert(newmodifier == modifier); + g_object_unref(item); return; -- cgit v1.2.3