87 lines
2.2 KiB
C
87 lines
2.2 KiB
C
#include <check.h>
|
|
#include "ucore/bitvec.h"
|
|
|
|
|
|
START_TEST (test_bitvec_1)
|
|
uc_bv_integer s[3] = {0};
|
|
struct UCBitVec v = UC_BV_STATIC_INIT(s);
|
|
size_t i;
|
|
|
|
for (i = 0; i < sizeof s * 8; i++)
|
|
fail_if(uc_bv_get_bit(&v, i), "bit %zu is not 0", i);
|
|
END_TEST
|
|
|
|
START_TEST (test_bitvec_2)
|
|
uc_bv_integer s[3] = {0};
|
|
struct UCBitVec v = UC_BV_STATIC_INIT(s);
|
|
size_t i;
|
|
|
|
for (i = 0; i < sizeof s * 8; i++)
|
|
uc_bv_set_bit(&v, i);
|
|
|
|
for (i = 0; i < sizeof s * 8; i++)
|
|
fail_if(uc_bv_get_bit(&v, i) != 1 , "bit %zu is not 1", i);
|
|
END_TEST
|
|
|
|
START_TEST (test_bitvec_clearbit)
|
|
uc_bv_integer s[3] = {-1, -1, -1};
|
|
struct UCBitVec v = UC_BV_STATIC_INIT(s);
|
|
size_t i;
|
|
|
|
for (i = 0; i < sizeof(uc_bv_integer) * 8; i++)
|
|
fail_if(uc_bv_get_bit(&v, i) != 1 , "bit %zu is not 1", i);
|
|
|
|
for (i = 0; i < sizeof(uc_bv_integer) * 8; i++)
|
|
uc_bv_clr_bit(&v, i);
|
|
|
|
for (i = 0; i < sizeof(uc_bv_integer) * 8; i++)
|
|
fail_if(uc_bv_get_bit(&v, i) != 0 , "bit %zu is not 0", i);
|
|
|
|
END_TEST
|
|
|
|
START_TEST (test_bitvec_set_bits_from_array)
|
|
struct UCBitVec *v = uc_bv_new(5);
|
|
char a[] = {1, 0,1 ,0, 1};
|
|
|
|
uc_bv_set_bits_from_array(v,a , 5);
|
|
fail_if(uc_bv_get_bit(v, 0) != 1 , "bit 0 is wrong");
|
|
fail_if(uc_bv_get_bit(v, 1) != 0 , "bit 1 is wrong");
|
|
fail_if(uc_bv_get_bit(v, 2) != 1 , "bit 2 is wrong");
|
|
fail_if(uc_bv_get_bit(v, 3) != 0 , "bit 3 is wrong");
|
|
fail_if(uc_bv_get_bit(v, 4) != 1 , "bit 4 is wrong");
|
|
END_TEST
|
|
|
|
|
|
START_TEST (test_bitvec_setall_clearall)
|
|
struct UCBitVec *v = uc_bv_new(511);
|
|
size_t i;
|
|
|
|
uc_bv_set_all(v);
|
|
|
|
for (i = 0; i < 511; i++)
|
|
fail_if(uc_bv_get_bit(v, i) != 1 , "bit %zu is not 1", i);
|
|
|
|
uc_bv_clr_all(v);
|
|
|
|
for (i = 0; i < sizeof(uc_bv_integer) * 8; i++)
|
|
fail_if(uc_bv_get_bit(v, i) != 0 , "bit %zu is not 0", i);
|
|
|
|
uc_bv_free(v);
|
|
|
|
END_TEST
|
|
|
|
Suite *bitvec_suite(void)
|
|
{
|
|
Suite *s = suite_create("bitvec");
|
|
TCase *tc = tcase_create("bitvec tests");
|
|
tcase_add_test(tc, test_bitvec_1);
|
|
tcase_add_test(tc, test_bitvec_2);
|
|
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);
|
|
suite_add_tcase(s, tc);
|
|
|
|
return s;
|
|
}
|
|
|