From fd2791b86c34873d0891d74da492a18bed75b461 Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Tue, 8 Jul 2014 20:40:33 +0200 Subject: [PATCH] avltree_test: Test duplicate detection and clear() as well. --- t/unit/utils/avltree_test.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/t/unit/utils/avltree_test.c b/t/unit/utils/avltree_test.c index d978eff..3ca8054 100644 --- a/t/unit/utils/avltree_test.c +++ b/t/unit/utils/avltree_test.c @@ -127,6 +127,21 @@ START_TEST(test_insert) "sdb_avltree_size() = %d; expected: %zu", check, i + 1); } + + /* 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(, <%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() = %d; expected: %zu", + check, SDB_STATIC_ARRAY_LEN(test_data)); + } } END_TEST @@ -171,6 +186,12 @@ START_TEST(test_iter) "sdb_avltree_iter_get_next() = ; expected: NULL"); sdb_avltree_iter_destroy(iter); + + sdb_avltree_clear(tree); + check = sdb_avltree_size(tree); + fail_unless(check == 0, + "sdb_avltree_clear() left %zu nodes in the tree; " + "expected: 0", check); } END_TEST -- 2.30.2