From 1fbe46ddfe40c3c9a50070506b0873a989dd8659 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 27 Feb 2011 12:14:16 -0800 Subject: [PATCH] test for emptiness of a list (it's super-simple) --- src/util/quicklist.c | 4 ++++ src/util/quicklist.h | 1 + src/util/quicklist_test.c | 2 ++ 3 files changed, 7 insertions(+) diff --git a/src/util/quicklist.c b/src/util/quicklist.c index 92eb38c08..8356106ca 100644 --- a/src/util/quicklist.c +++ b/src/util/quicklist.c @@ -47,6 +47,10 @@ int ql_length(const quicklist * ql) { return ql?ql->num_elements+ql_length(ql->next):0; } +int ql_empty(const quicklist * ql) { + return !ql; +} + void ql_push(quicklist ** qlp, void * data) { quicklist * ql = 0; while(*qlp && ((*qlp)->next || (*qlp)->num_elements==QL_MAXSIZE)) { diff --git a/src/util/quicklist.h b/src/util/quicklist.h index 91eb55468..d70fa648c 100644 --- a/src/util/quicklist.h +++ b/src/util/quicklist.h @@ -25,6 +25,7 @@ extern "C" { typedef struct quicklist quicklist; void * ql_get(const struct quicklist * ql, int index); int ql_length(const struct quicklist * ql); +int ql_empty(const struct quicklist * ql); void ql_push(struct quicklist ** qlp, void * data); int ql_delete(struct quicklist ** qlp, int index); int ql_insert(struct quicklist ** qlp, int index, void * data); diff --git a/src/util/quicklist_test.c b/src/util/quicklist_test.c index 5592599f8..ead3d2c78 100644 --- a/src/util/quicklist_test.c +++ b/src/util/quicklist_test.c @@ -19,7 +19,9 @@ static void test_insert(CuTest * tc) { static void test_insert_delete_gives_null(CuTest * tc) { struct quicklist * ql = NULL; + CuAssertIntEquals(tc, 1, ql_empty(ql)); ql_push(&ql, (void*)42); + CuAssertIntEquals(tc, 0, ql_empty(ql)); ql_delete(&ql, 0); CuAssertPtrEquals(tc, 0, ql); }