[glib] Improve tree test coverage
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] Improve tree test coverage
- Date: Sat, 31 Jul 2010 06:49:56 +0000 (UTC)
commit 6d41af0f724fad717b2cba4dc0001cd53564a9eb
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Jul 31 02:15:03 2010 -0400
Improve tree test coverage
glib/tests/tree.c | 42 ++++++++++++++++++++++++++++++++++++++++++
1 files changed, 42 insertions(+), 0 deletions(-)
---
diff --git a/glib/tests/tree.c b/glib/tests/tree.c
index 07ffab4..b2db158 100644
--- a/glib/tests/tree.c
+++ b/glib/tests/tree.c
@@ -294,6 +294,47 @@ test_tree_destroy (void)
g_tree_unref (tree);
}
+static gboolean
+traverse_func (gpointer key, gpointer value, gpointer data)
+{
+ gchar *c = value;
+ gchar **p = data;
+
+ **p = *c;
+ (*p)++;
+
+ return FALSE;
+}
+
+static void
+test_tree_traverse (void)
+{
+ GTree *tree;
+ gint i;
+ gchar *p, *result;
+
+ tree = g_tree_new (my_compare);
+
+ for (i = 0; chars[i]; i++)
+ g_tree_insert (tree, &chars[i], &chars[i]);
+
+ result = g_new0 (gchar, strlen (chars) + 1);
+
+ p = result;
+ g_tree_traverse (tree, traverse_func, G_IN_ORDER, &p);
+ g_assert_cmpstr (result, ==, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");
+
+ p = result;
+ g_tree_traverse (tree, traverse_func, G_PRE_ORDER, &p);
+ g_assert_cmpstr (result, ==, "VF73102546B98ADCENJHGILKMRPOQTSUldZXWYbachfegjiktpnmorqsxvuwyz");
+
+ p = result;
+ g_tree_traverse (tree, traverse_func, G_POST_ORDER, &p);
+ g_assert_cmpstr (result, ==, "02146538A9CEDB7GIHKMLJOQPSUTRNFWYXacbZegfikjhdmonqsrpuwvzyxtlV");
+
+ g_tree_unref (tree);
+}
+
int
main (int argc, char *argv[])
{
@@ -302,6 +343,7 @@ main (int argc, char *argv[])
g_test_add_func ("/tree/search", test_tree_search);
g_test_add_func ("/tree/remove", test_tree_remove);
g_test_add_func ("/tree/destroy", test_tree_destroy);
+ g_test_add_func ("/tree/traverse", test_tree_traverse);
return g_test_run ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]