1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

[UNIT-TESTS] add test for the recent dm_bitset_equal() function

This commit is contained in:
Joe Thornber 2010-07-20 15:26:43 +00:00
parent 66392e6660
commit 4adf163d13

View File

@ -6,14 +6,10 @@ enum {
NR_BITS = 137
};
int main(int argc, char **argv)
static void test_get_next(struct dm_pool *mem)
{
int i, j, last, first;
dm_bitset_t bs;
struct dm_pool *mem = dm_pool_create("bitset test", 1024);
assert(mem);
bs = dm_bitset_create(mem, NR_BITS);
dm_bitset_t bs = dm_bitset_create(mem, NR_BITS);
for (i = 0; i < NR_BITS; i++)
assert(!dm_bit(bs, i));
@ -33,7 +29,56 @@ int main(int argc, char **argv)
}
assert(dm_bit_get_next(bs, last) == -1);
dm_pool_destroy(mem);
}
static void bit_flip(dm_bitset_t bs, int bit)
{
int old = dm_bit(bs, bit);
if (old)
dm_bit_clear(bs, bit);
else
dm_bit_set(bs, bit);
}
static void test_equal(struct dm_pool *mem)
{
dm_bitset_t bs1 = dm_bitset_create(mem, NR_BITS);
dm_bitset_t bs2 = 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);
}
assert(dm_bitset_equal(bs1, bs2));
assert(dm_bitset_equal(bs2, bs1));
for (i = 0; i < NR_BITS; i++) {
bit_flip(bs1, i);
assert(!dm_bitset_equal(bs1, bs2));
assert(!dm_bitset_equal(bs2, bs1));
assert(dm_bitset_equal(bs1, bs1)); /* comparing with self */
bit_flip(bs1, i);
}
}
int main(int argc, char **argv)
{
typedef void (*test_fn)(struct dm_pool *);
static test_fn tests[] = {
test_get_next,
test_equal
};
int i;
for (i = 0; i < sizeof(tests) / sizeof(*tests); i++) {
struct dm_pool *mem = dm_pool_create("bitset test", 1024);
assert(mem);
tests[i](mem);
dm_pool_destroy(mem);
}
return 0;
}