aboutsummaryrefslogtreecommitdiff
path: root/src/or/test.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/or/test.c')
-rw-r--r--src/or/test.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/or/test.c b/src/or/test.c
index 2776fcbfc..147023a8d 100644
--- a/src/or/test.c
+++ b/src/or/test.c
@@ -1544,6 +1544,43 @@ test_smartlist(void)
smartlist_free(sl);
}
+static void
+test_bitarray(void)
+{
+ bitarray_t *ba;
+ int i, j, ok=1;
+
+ ba = bitarray_init_zero(1);
+ test_assert(! bitarray_is_set(ba, 0));
+ bitarray_set(ba, 0);
+ test_assert(bitarray_is_set(ba, 0));
+ bitarray_clear(ba, 0);
+ test_assert(! bitarray_is_set(ba, 0));
+ bitarray_free(ba);
+
+ ba = bitarray_init_zero(1023);
+ for (i = 1; i < 64; ) {
+ for (j = 0; j < 1023; ++j) {
+ if (j % i)
+ bitarray_set(ba, j);
+ else
+ bitarray_clear(ba, j);
+ }
+ for (j = 0; j < 1023; ++j) {
+ if (!bool_eq(bitarray_is_set(ba, j), j%i))
+ ok = 0;
+ }
+ test_assert(ok);
+ if (i < 7)
+ ++i;
+ else if (i == 28)
+ i = 32;
+ else
+ i += 7;
+ }
+ bitarray_free(ba);
+}
+
/* stop threads running at once. */
static tor_mutex_t *_thread_test_mutex = NULL;
/* make sure that threads have to run at the same time. */
@@ -2990,6 +3027,8 @@ main(int c, char**v)
test_util();
puts("\n--smartlist");
test_smartlist();
+ puts("\n--bitarray");
+ test_bitarray();
puts("\n--mempool");
test_mempool();
puts("\n--strmap");