Code

object: Added SDB_OBJECT_STATIC.
[sysdb.git] / t / unit / utils / avltree_test.c
index d978eff9da688fc4306728f060db34a9a9e04609..0488693d112d139afb935b333ab79941318cb739 100644 (file)
@@ -47,19 +47,23 @@ teardown(void)
        tree = NULL;
 } /* teardown */
 
-/* 'a' - 'k' */
+/* 'a' thru 'o' */
 static sdb_object_t test_data[] = {
-       SSTRING_OBJ("d"),
-       SSTRING_OBJ("f"),
-       SSTRING_OBJ("e"),
-       SSTRING_OBJ("b"),
-       SSTRING_OBJ("a"),
-       SSTRING_OBJ("c"),
-       SSTRING_OBJ("g"),
-       SSTRING_OBJ("h"),
-       SSTRING_OBJ("i"),
-       SSTRING_OBJ("j"),
-       SSTRING_OBJ("k"),
+       SDB_OBJECT_STATIC("h"),
+       SDB_OBJECT_STATIC("j"),
+       SDB_OBJECT_STATIC("i"),
+       SDB_OBJECT_STATIC("f"),
+       SDB_OBJECT_STATIC("e"),
+       SDB_OBJECT_STATIC("g"),
+       SDB_OBJECT_STATIC("k"),
+       SDB_OBJECT_STATIC("l"),
+       SDB_OBJECT_STATIC("m"),
+       SDB_OBJECT_STATIC("n"),
+       SDB_OBJECT_STATIC("o"),
+       SDB_OBJECT_STATIC("d"),
+       SDB_OBJECT_STATIC("c"),
+       SDB_OBJECT_STATIC("b"),
+       SDB_OBJECT_STATIC("a"),
 };
 
 static void
@@ -72,7 +76,7 @@ populate(void)
 
 START_TEST(test_null)
 {
-       sdb_object_t o1 = SSTRING_OBJ("obj");
+       sdb_object_t o1 = SDB_OBJECT_STATIC("obj");
        sdb_object_t *o2;
        sdb_avltree_iter_t *iter;
        int check;
@@ -126,6 +130,25 @@ START_TEST(test_insert)
                fail_unless(check == (int)i + 1,
                                "sdb_avltree_size(<tree>) = %d; expected: %zu",
                                check, i + 1);
+
+               fail_unless(sdb_avltree_valid(tree),
+                               "sdb_avltree_insert(<tree>, <%s>) left behind invalid tree",
+                               test_data[i].name);
+       }
+
+       /* and again ... now reporting errors because of duplicates */
+       for (i = 0; i < SDB_STATIC_ARRAY_LEN(test_data); ++i) {
+               int check;
+
+               check = sdb_avltree_insert(tree, &test_data[i]);
+               fail_unless(check < 0,
+                               "sdb_avltree_insert(<tree>, <%s>) = %d (redo); expected: <0",
+                               test_data[i].name, check);
+
+               check = (int)sdb_avltree_size(tree);
+               fail_unless(check == SDB_STATIC_ARRAY_LEN(test_data),
+                               "sdb_avltree_size(<tree>) = %d; expected: %zu",
+                               check, SDB_STATIC_ARRAY_LEN(test_data));
        }
 }
 END_TEST
@@ -171,6 +194,12 @@ START_TEST(test_iter)
                        "sdb_avltree_iter_get_next(<iter>) = <obj>; expected: NULL");
 
        sdb_avltree_iter_destroy(iter);
+
+       sdb_avltree_clear(tree);
+       check = sdb_avltree_size(tree);
+       fail_unless(check == 0,
+                       "sdb_avltree_clear(<tree>) left %zu nodes in the tree; "
+                       "expected: 0", check);
 }
 END_TEST