diff options
Diffstat (limited to 'tests/bitfield_tests.c')
-rw-r--r-- | tests/bitfield_tests.c | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/tests/bitfield_tests.c b/tests/bitfield_tests.c index e0646e6a..b03882a2 100644 --- a/tests/bitfield_tests.c +++ b/tests/bitfield_tests.c @@ -42,7 +42,8 @@ START_TEST (test_get_bits_out_of_range) { uint8_t data[4] = {0x12, 0x34, 0x56, 0x78}; uint8_t result[4]; - fail_if(copy_bits_right_aligned(data, 4, 25, 16, result, 4)); + fail_if(copy_bits_right_aligned(data, sizeof(data), 25, 16, result, + sizeof(result))); } END_TEST @@ -50,9 +51,22 @@ START_TEST (test_get_bits) { uint8_t data[4] = {0x12, 0x34, 0x56, 0x78}; uint8_t result[4] = {0}; - fail_unless(copy_bits_right_aligned(data, 4, 0, 16, result, 4)); - ck_assert_int_eq(result[0], 0x12); + fail_unless(copy_bits_right_aligned(data, sizeof(data), 0, 16, result, + sizeof(result))); + ck_assert_int_eq(result[2], 0x12); + ck_assert_int_eq(result[3], 0x34); +} +END_TEST + +START_TEST (test_copy_bytes) +{ + uint8_t data[4] = {0x12, 0x34, 0x56, 0x78}; + uint8_t result[4] = {0}; + fail_unless(copy_bytes_right_aligned(data, sizeof(data), 1, 3, result, + sizeof(result))); ck_assert_int_eq(result[1], 0x34); + ck_assert_int_eq(result[2], 0x56); + ck_assert_int_eq(result[3], 0x78); } END_TEST @@ -60,9 +74,10 @@ START_TEST (test_get_uneven_bits) { uint8_t data[4] = {0x12, 0x34, 0x56, 0x78}; uint8_t result[4] = {0}; - fail_unless(copy_bits_right_aligned(data, 4, 4, 12, result, 4)); - ck_assert_int_eq(result[0], 0x2); - ck_assert_int_eq(result[1], 0x34); + fail_unless(copy_bits_right_aligned(data, sizeof(data), 4, 12, result, + sizeof(result))); + ck_assert_int_eq(result[2], 0x2); + ck_assert_int_eq(result[3], 0x34); } END_TEST @@ -73,6 +88,7 @@ Suite* bitfieldSuite(void) { tcase_add_test(tc_core, test_get_nibble); tcase_add_test(tc_core, test_set_nibble); tcase_add_test(tc_core, test_get_bits); + tcase_add_test(tc_core, test_copy_bytes); tcase_add_test(tc_core, test_get_bits_out_of_range); tcase_add_test(tc_core, test_get_uneven_bits); suite_add_tcase(s, tc_core); |