aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorTed Gould <ted@gould.cx>2010-02-05 10:54:42 -0800
committerTed Gould <ted@gould.cx>2010-02-05 10:54:42 -0800
commit873763b18e85fe2d53f847e00d5207e4926bb619 (patch)
tree833014e2b5bea30c53b5e3660e3a47180be1faa8 /tests
parenta207ebb4db1921fe122a9c78b97f17e7ec175a29 (diff)
parent0f6f4c9cdd83d80dfd77fbedcc9a9468cb16eaae (diff)
downloadlibdbusmenu-873763b18e85fe2d53f847e00d5207e4926bb619.tar.gz
libdbusmenu-873763b18e85fe2d53f847e00d5207e4926bb619.tar.bz2
libdbusmenu-873763b18e85fe2d53f847e00d5207e4926bb619.zip
Fix IDs to handle the root ID of zero better and to handle merging of properties if items are reused.
Diffstat (limited to 'tests')
-rw-r--r--tests/test-glib-layout-client.c12
-rw-r--r--tests/test-glib-layout-server.c4
-rw-r--r--tests/test-glib-layout.h22
-rw-r--r--tests/test-glib-objects.c25
-rw-r--r--tests/test-glib-properties-client.c12
-rw-r--r--tests/test-glib-properties-server.c6
-rw-r--r--tests/test-glib-properties.h12
7 files changed, 61 insertions, 32 deletions
diff --git a/tests/test-glib-layout-client.c b/tests/test-glib-layout-client.c
index bb2d13a..5ea0cf8 100644
--- a/tests/test-glib-layout-client.c
+++ b/tests/test-glib-layout-client.c
@@ -36,8 +36,10 @@ verify_root_to_layout(DbusmenuMenuitem * mi, layout_t * layout)
g_debug("Verifying ID: %d", layout->id);
if (layout->id != dbusmenu_menuitem_get_id(mi)) {
- g_debug("Failed as ID %d is not equal to %d", layout->id, dbusmenu_menuitem_get_id(mi));
- return FALSE;
+ if (!(dbusmenu_menuitem_get_root(mi) && dbusmenu_menuitem_get_id(mi) == 0)) {
+ g_debug("Failed as ID %d is not equal to %d", layout->id, dbusmenu_menuitem_get_id(mi));
+ return FALSE;
+ }
}
GList * children = dbusmenu_menuitem_get_children(mi);
@@ -55,13 +57,13 @@ verify_root_to_layout(DbusmenuMenuitem * mi, layout_t * layout)
}
guint i = 0;
- for (i = 0; children != NULL && layout->submenu[i].id != 0; children = g_list_next(children), i++) {
+ for (i = 0; children != NULL && layout->submenu[i].id != -1; children = g_list_next(children), i++) {
if (!verify_root_to_layout(DBUSMENU_MENUITEM(children->data), &layout->submenu[i])) {
return FALSE;
}
}
- if (children == NULL && layout->submenu[i].id == 0) {
+ if (children == NULL && layout->submenu[i].id == -1) {
return TRUE;
}
@@ -88,7 +90,7 @@ layout_updated (DbusmenuClient * client, gpointer data)
layouton++;
- if (layouts[layouton].id == 0) {
+ if (layouts[layouton].id == -1) {
g_main_loop_quit(mainloop);
}
diff --git a/tests/test-glib-layout-server.c b/tests/test-glib-layout-server.c
index 40dd048..111e164 100644
--- a/tests/test-glib-layout-server.c
+++ b/tests/test-glib-layout-server.c
@@ -41,7 +41,7 @@ layout2menuitem (layout_t * layout)
if (layout->submenu != NULL) {
guint count;
- for (count = 0; layout->submenu[count].id != 0; count++) {
+ for (count = 0; layout->submenu[count].id != -1; count++) {
DbusmenuMenuitem * child = layout2menuitem(&layout->submenu[count]);
if (child != NULL) {
dbusmenu_menuitem_child_append(local, child);
@@ -60,7 +60,7 @@ static GMainLoop * mainloop = NULL;
static gboolean
timer_func (gpointer data)
{
- if (layouts[layouton].id == 0) {
+ if (layouts[layouton].id == -1) {
g_main_loop_quit(mainloop);
return FALSE;
}
diff --git a/tests/test-glib-layout.h b/tests/test-glib-layout.h
index a13125d..b64c4ea 100644
--- a/tests/test-glib-layout.h
+++ b/tests/test-glib-layout.h
@@ -21,51 +21,51 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
typedef struct _layout_t layout_t;
struct _layout_t {
- guint id;
+ gint id;
layout_t * submenu;
};
layout_t submenu_2[] = {
{id: 2, submenu: NULL},
{id: 3, submenu: NULL},
- {id: 0, submenu: NULL}
+ {id: -1, submenu: NULL}
};
layout_t submenu_3_1[] = {
{id: 3, submenu: NULL},
{id: 4, submenu: NULL},
{id: 5, submenu: NULL},
- {id: 0, submenu: NULL}
+ {id: -1, submenu: NULL}
};
layout_t submenu_3_2[] = {
{id: 7, submenu: NULL},
{id: 8, submenu: NULL},
{id: 9, submenu: NULL},
- {id: 0, submenu: NULL}
+ {id: -1, submenu: NULL}
};
layout_t submenu_3[] = {
{id: 2, submenu: submenu_3_1},
{id: 6, submenu: submenu_3_2},
- {id: 0, submenu: NULL}
+ {id: -1, submenu: NULL}
};
layout_t submenu_4_1[] = {
{id: 6, submenu: NULL},
- {id: 0, submenu: NULL}
+ {id: -1, submenu: NULL}
};
layout_t submenu_4_2[] = {
{id: 5, submenu: submenu_4_1},
- {id: 0, submenu: NULL}
+ {id: -1, submenu: NULL}
};
layout_t submenu_4_3[] = {
{id: 4, submenu: submenu_4_2},
- {id: 0, submenu: NULL}
+ {id: -1, submenu: NULL}
};
layout_t submenu_4_4[] = {
{id: 3, submenu: submenu_4_3},
- {id: 0, submenu: NULL}
+ {id: -1, submenu: NULL}
};
layout_t submenu_4_5[] = {
{id: 2, submenu: submenu_4_4},
- {id: 0, submenu: NULL}
+ {id: -1, submenu: NULL}
};
layout_t layouts[] = {
@@ -73,6 +73,6 @@ layout_t layouts[] = {
{id: 1, submenu: submenu_2},
{id: 1, submenu: submenu_3},
{id: 1, submenu: submenu_4_5},
- {id: 0, submenu: NULL}
+ {id: -1, submenu: NULL}
};
diff --git a/tests/test-glib-objects.c b/tests/test-glib-objects.c
index f3fbcc8..1d4f673 100644
--- a/tests/test-glib-objects.c
+++ b/tests/test-glib-objects.c
@@ -47,6 +47,30 @@ test_object_menuitem (void)
return;
}
+/* Check to make sure a new ID is bigger than 0 */
+static void
+test_object_menuitem_id (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));
+
+ g_assert(dbusmenu_menuitem_get_id(item) > 0);
+
+ /* 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)
@@ -255,6 +279,7 @@ 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/id", test_object_menuitem_id);
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);
diff --git a/tests/test-glib-properties-client.c b/tests/test-glib-properties-client.c
index 39815aa..434465a 100644
--- a/tests/test-glib-properties-client.c
+++ b/tests/test-glib-properties-client.c
@@ -60,8 +60,10 @@ verify_root_to_layout(DbusmenuMenuitem * mi, proplayout_t * layout)
g_debug("Verifying ID: %d", layout->id);
if (layout->id != dbusmenu_menuitem_get_id(mi)) {
- g_debug("\tFailed as ID %d is not equal to %d", layout->id, dbusmenu_menuitem_get_id(mi));
- return FALSE;
+ if (!dbusmenu_menuitem_get_root(mi)) {
+ g_debug("\tFailed as ID %d is not equal to %d", layout->id, dbusmenu_menuitem_get_id(mi));
+ return FALSE;
+ }
}
if (!verify_props(mi, layout->properties)) {
@@ -85,13 +87,13 @@ verify_root_to_layout(DbusmenuMenuitem * mi, proplayout_t * layout)
}
guint i = 0;
- for (i = 0; children != NULL && layout->submenu[i].id != 0; children = g_list_next(children), i++) {
+ for (i = 0; children != NULL && layout->submenu[i].id != -1; children = g_list_next(children), i++) {
if (!verify_root_to_layout(DBUSMENU_MENUITEM(children->data), &layout->submenu[i])) {
return FALSE;
}
}
- if (children == NULL && layout->submenu[i].id == 0) {
+ if (children == NULL && layout->submenu[i].id == -1) {
g_debug("\tPassed: %d", layout->id);
return TRUE;
}
@@ -140,7 +142,7 @@ layout_verify_timer (gpointer data)
layouton++;
- if (layouts[layouton].id == 0) {
+ if (layouts[layouton].id == -1) {
g_main_loop_quit(mainloop);
}
diff --git a/tests/test-glib-properties-server.c b/tests/test-glib-properties-server.c
index 8dad37f..091e550 100644
--- a/tests/test-glib-properties-server.c
+++ b/tests/test-glib-properties-server.c
@@ -46,14 +46,14 @@ set_props (DbusmenuMenuitem * mi, gchar ** props)
static DbusmenuMenuitem *
layout2menuitem (proplayout_t * layout)
{
- if (layout == NULL || layout->id == 0) return NULL;
+ if (layout == NULL || layout->id == -1) return NULL;
DbusmenuMenuitem * local = dbusmenu_menuitem_new_with_id(layout->id);
set_props(local, layout->properties);
if (layout->submenu != NULL) {
guint count;
- for (count = 0; layout->submenu[count].id != 0; count++) {
+ for (count = 0; layout->submenu[count].id != -1; count++) {
DbusmenuMenuitem * child = layout2menuitem(&layout->submenu[count]);
if (child != NULL) {
dbusmenu_menuitem_child_append(local, child);
@@ -72,7 +72,7 @@ static GMainLoop * mainloop = NULL;
static gboolean
timer_func (gpointer data)
{
- if (layouts[layouton].id == 0) {
+ if (layouts[layouton].id == -1) {
g_main_loop_quit(mainloop);
return FALSE;
}
diff --git a/tests/test-glib-properties.h b/tests/test-glib-properties.h
index 5e83f5c..c0c929a 100644
--- a/tests/test-glib-properties.h
+++ b/tests/test-glib-properties.h
@@ -24,7 +24,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
typedef struct _proplayout_t proplayout_t;
struct _proplayout_t {
- guint id;
+ gint id;
gchar ** properties;
proplayout_t * submenu;
};
@@ -68,7 +68,7 @@ proplayout_t submenu_4_1[] = {
{id: 17, properties: props2, submenu: NULL},
{id: 18, properties: props2, submenu: NULL},
{id: 19, properties: props2, submenu: NULL},
- {id: 0, properties: NULL, submenu: NULL}
+ {id: -1, properties: NULL, submenu: NULL}
};
proplayout_t submenu_4_2[] = {
@@ -82,7 +82,7 @@ proplayout_t submenu_4_2[] = {
{id: 27, properties: props2, submenu: NULL},
{id: 28, properties: props2, submenu: NULL},
{id: 29, properties: props2, submenu: NULL},
- {id: 0, properties: NULL, submenu: NULL}
+ {id: -1, properties: NULL, submenu: NULL}
};
proplayout_t submenu_4_3[] = {
@@ -96,14 +96,14 @@ proplayout_t submenu_4_3[] = {
{id: 37, properties: props2, submenu: NULL},
{id: 38, properties: props2, submenu: NULL},
{id: 39, properties: props2, submenu: NULL},
- {id: 0, properties: NULL, submenu: NULL}
+ {id: -1, properties: NULL, submenu: NULL}
};
proplayout_t submenu_4_0[] = {
{id: 1, properties: props2, submenu: submenu_4_1},
{id: 2, properties: props2, submenu: submenu_4_2},
{id: 3, properties: props2, submenu: submenu_4_3},
- {id: 0, properties: NULL, submenu: NULL}
+ {id: -1, properties: NULL, submenu: NULL}
};
proplayout_t layouts[] = {
@@ -111,6 +111,6 @@ proplayout_t layouts[] = {
{id: 10, properties: props2, submenu: NULL},
{id: 20, properties: props3, submenu: NULL},
{id: 100, properties: props2, submenu: submenu_4_0},
- {id: 0, properties: NULL, submenu: NULL}
+ {id: -1, properties: NULL, submenu: NULL}
};