Add uc_bv_find_first_zero

This commit is contained in:
Nils O. Selåsdal
2025-07-20 21:44:11 +02:00
parent 5b5ca445e9
commit 7408c48dff
3 changed files with 51 additions and 1 deletions
+27
View File
@@ -79,6 +79,31 @@ START_TEST (test_bitvec_setall_clearall)
uc_bv_free(v);
}
END_TEST
START_TEST (test_bitvec_find_first_zero)
{
uc_bv_integer buf[8];
struct UCBitVec v = UC_BV_STATIC_INIT(buf);
uc_bv_set_all(&v);
int bit = uc_bv_find_first_zero(&v);
ck_assert_int_eq(bit, -1);
uc_bv_clr_bit(&v, 0);
bit = uc_bv_find_first_zero(&v);
ck_assert_int_eq(bit, 0);
uc_bv_set_bit(&v, 0);
uc_bv_clr_bit(&v, 63);
bit = uc_bv_find_first_zero(&v);
ck_assert_int_eq(bit, 63);
uc_bv_set_bit(&v, 63);
uc_bv_clr_bit(&v, sizeof buf * CHAR_BIT - 1);
bit = uc_bv_find_first_zero(&v);
ck_assert_int_eq(bit, sizeof buf * CHAR_BIT - 1);
}
END_TEST
@@ -91,6 +116,8 @@ Suite *bitvec_suite(void)
tcase_add_test(tc, test_bitvec_set_bits_from_array);
tcase_add_test(tc, test_bitvec_clearbit);
tcase_add_test(tc, test_bitvec_setall_clearall);
tcase_add_test(tc, test_bitvec_find_first_zero);
suite_add_tcase(s, tc);
return s;