diff options
author | Harald Welte <laforge@gnumonks.org> | 2019-02-03 12:04:46 +0100 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2019-02-05 09:24:17 +0000 |
commit | ae7966d145965452a325a33ca6334b6d6fe061a6 (patch) | |
tree | 153502bda3057136cf69fe9cb247e65500a6b321 /tests/bitvec/bitvec_test.c | |
parent | 71806ddb29f5acc2ea78a08756ff2b82fd6d618e (diff) |
bitvec: Add bitvec_bytes_used() function
This new bitvec API function returns the number of bytes used in a given
bit-vector.
Change-Id: Id4bd7f7543f5b0f4f6f876e283bd065039c37646
Diffstat (limited to 'tests/bitvec/bitvec_test.c')
-rw-r--r-- | tests/bitvec/bitvec_test.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/bitvec/bitvec_test.c b/tests/bitvec/bitvec_test.c index d0bc30c4..c8795dbd 100644 --- a/tests/bitvec/bitvec_test.c +++ b/tests/bitvec/bitvec_test.c @@ -181,6 +181,29 @@ static void test_array() test_array_item(17, &b, n, array, n * 3); } +static void test_used_bytes() +{ + struct bitvec b; + uint8_t d[32]; + unsigned int i; + + b.data = d; + b.data_len = sizeof(d); + bitvec_zero(&b); + + OSMO_ASSERT(bitvec_used_bytes(&b) == 0); + + for (i = 0; i < 8; i++) { + bitvec_set_bit(&b, 1); + OSMO_ASSERT(bitvec_used_bytes(&b) == 1); + } + + for (i = 8; i < 16; i++) { + bitvec_set_bit(&b, 1); + OSMO_ASSERT(bitvec_used_bytes(&b) == 2); + } +} + int main(int argc, char **argv) { struct bitvec bv; @@ -286,6 +309,9 @@ int main(int argc, char **argv) bitvec_zero(&bv); test_bitvec_rl_curbit(&bv, 1, 64, 0); + printf("\nbitvec bytes used.\n"); + test_used_bytes(); + printf("\nbitvec ok.\n"); return 0; } |