}
return 0;
}
+
+bool set_nibble(const uint16_t nibble_index, const uint8_t value,
+ uint8_t* destination, const uint16_t destination_length) {
+ return copy_bits(&value, CHAR_BIT, NIBBLE_SIZE, NIBBLE_SIZE, destination,
+ destination_length, nibble_index * NIBBLE_SIZE);
+}
const uint16_t offset, const uint16_t bit_count,
uint8_t* destination, const uint16_t destination_length);
+bool set_nibble(const uint16_t nibble_index, const uint8_t value,
+ uint8_t* destination, const uint16_t destination_length);
+
#ifdef __cplusplus
}
#endif
}
END_TEST
+START_TEST (test_set_nibble)
+{
+ uint8_t data[4] = {0};
+ fail_unless(set_nibble(0, 0x1, data, sizeof(data)));
+ fail_unless(set_nibble(1, 0x2, data, sizeof(data)));
+ fail_unless(set_nibble(2, 0x3, data, sizeof(data)));
+ fail_unless(set_nibble(3, 0x4, data, sizeof(data)));
+ fail_unless(set_nibble(4, 0x5, data, sizeof(data)));
+ ck_assert_int_eq(data[0], 0x12);
+ ck_assert_int_eq(data[1], 0x34);
+ ck_assert_int_eq(data[2], 0x50);
+}
+END_TEST
+
START_TEST (test_get_nibble)
{
uint8_t data[4] = {0x12, 0x34, 0x56, 0x78};
TCase *tc_core = tcase_create("core");
tcase_add_test(tc_core, test_get_byte);
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_get_bits_out_of_range);
tcase_add_test(tc_core, test_get_uneven_bits);