aboutsummaryrefslogtreecommitdiffstats
path: root/tests/bitvec
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2019-02-04 12:09:05 +0100
committerHarald Welte <laforge@gnumonks.org>2019-02-05 11:16:44 +0100
commitb0708d3e769851093ef633844d894b683a3c0341 (patch)
tree50ec260fa831746711c36502d8da6b6503408b46 /tests/bitvec
parentae7966d145965452a325a33ca6334b6d6fe061a6 (diff)
bitvec: Add bitvec_tailroom_bits() function
This is similar to msgb_tailroom(): It returns the amount of space left at the end of the bit vector (compared to the current cursor). The function returns the number of bits left in the bitvec. Change-Id: I8980a6b6d1973b67a2d9ad411c878d956fb428d1
Diffstat (limited to 'tests/bitvec')
-rw-r--r--tests/bitvec/bitvec_test.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/bitvec/bitvec_test.c b/tests/bitvec/bitvec_test.c
index c8795dbd..fbf5c5dd 100644
--- a/tests/bitvec/bitvec_test.c
+++ b/tests/bitvec/bitvec_test.c
@@ -204,6 +204,24 @@ static void test_used_bytes()
}
}
+static void test_tailroom()
+{
+ struct bitvec b;
+ uint8_t d[32];
+ unsigned int i;
+
+ b.data = d;
+ b.data_len = sizeof(d);
+ bitvec_zero(&b);
+
+ OSMO_ASSERT(bitvec_tailroom_bits(&b) == sizeof(d)*8);
+
+ for (i = 0; i < 8*sizeof(d); i++) {
+ bitvec_set_bit(&b, 1);
+ OSMO_ASSERT(bitvec_tailroom_bits(&b) == sizeof(d)*8-(i+1));
+ }
+}
+
int main(int argc, char **argv)
{
struct bitvec bv;
@@ -311,6 +329,7 @@ int main(int argc, char **argv)
printf("\nbitvec bytes used.\n");
test_used_bytes();
+ test_tailroom();
printf("\nbitvec ok.\n");
return 0;