From 96412de6a92e8da00d8a2fbfe0fd2ce2122b096e Mon Sep 17 00:00:00 2001 From: Joe Thornber Date: Tue, 20 Jul 2010 15:28:22 +0000 Subject: [PATCH] [UNIT-TEST] test for recent dm_bit_and() function --- unit-tests/datastruct/bitset_t.c | 36 +++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/unit-tests/datastruct/bitset_t.c b/unit-tests/datastruct/bitset_t.c index ab17ab4c1..25d19d7c2 100644 --- a/unit-tests/datastruct/bitset_t.c +++ b/unit-tests/datastruct/bitset_t.c @@ -64,12 +64,46 @@ static void test_equal(struct dm_pool *mem) } } +static void test_and(struct dm_pool *mem) +{ + dm_bitset_t bs1 = dm_bitset_create(mem, NR_BITS); + dm_bitset_t bs2 = dm_bitset_create(mem, NR_BITS); + dm_bitset_t bs3 = dm_bitset_create(mem, NR_BITS); + + int i, j; + for (i = 0, j = 1; i < NR_BITS; i += j, j++) { + dm_bit_set(bs1, i); + dm_bit_set(bs2, i); + } + + dm_bit_and(bs3, bs1, bs2); + + assert(dm_bitset_equal(bs1, bs2)); + assert(dm_bitset_equal(bs1, bs3)); + assert(dm_bitset_equal(bs2, bs3)); + + dm_bit_clear_all(bs1); + dm_bit_clear_all(bs2); + + for (i = 0; i < NR_BITS; i++) { + if (i % 2) + dm_bit_set(bs1, i); + else + dm_bit_set(bs2, i); + } + + dm_bit_and(bs3, bs1, bs2); + for (i = 0; i < NR_BITS; i++) + assert(!dm_bit(bs3, i)); +} + int main(int argc, char **argv) { typedef void (*test_fn)(struct dm_pool *); static test_fn tests[] = { test_get_next, - test_equal + test_equal, + test_and }; int i;