From 007a855bab062af81da3cc5caf68734a974d1e20 Mon Sep 17 00:00:00 2001 From: Slava Monich Date: Thu, 18 Jan 2018 20:36:52 +0200 Subject: [PATCH] unit: Improve idmap.c unit test coverage This brings function, line and branch coverage for idmap.c to 100% --- unit/test-idmap.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/unit/test-idmap.c b/unit/test-idmap.c index b0729335..2d2e2266 100644 --- a/unit/test-idmap.c +++ b/unit/test-idmap.c @@ -35,9 +35,12 @@ static void test_alloc(void) idmap = idmap_new(2); g_assert(idmap); + g_assert(idmap_get_min(idmap) == 1); bit = idmap_alloc(idmap); g_assert(bit == 1); + g_assert(idmap_find(idmap, bit)); + g_assert(!idmap_find(idmap, idmap_get_max(idmap) + 1)); bit = idmap_alloc(idmap); g_assert(bit == 2); @@ -62,6 +65,12 @@ static void test_alloc(void) bit = idmap_alloc(idmap); g_assert(bit == 1); + idmap_put(idmap, 1); + idmap_take(idmap, 1); + idmap_take(idmap, 3); + bit = idmap_alloc(idmap); + g_assert(bit == 2); + idmap_free(idmap); } @@ -80,9 +89,24 @@ static void test_alloc_next(void) bit = idmap_alloc_next(idmap, 255); g_assert(bit == 1); + while (idmap_alloc(idmap) < (sizeof(unsigned long) * 8) + 1); + bit = idmap_alloc_next(idmap, 1); + g_assert(bit == (sizeof(unsigned long) * 8) + 2); + + idmap_free(idmap); + + idmap = idmap_new(2); + + g_assert(idmap); + g_assert(idmap_alloc_next(idmap, 0) == 3); + g_assert(idmap_alloc_next(idmap, 3) == 3); + bit = idmap_alloc_next(idmap, 1); g_assert(bit == 2); + bit = idmap_alloc_next(idmap, 2); + g_assert(bit == 1); + idmap_free(idmap); }