summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorChristopher Peplin <chris.peplin@rhubarbtech.com>2013-12-29 15:15:16 -0500
committerChristopher Peplin <chris.peplin@rhubarbtech.com>2013-12-29 15:15:16 -0500
commit518430f122772016715660086a630ff595e4fcfd (patch)
treea3cbf7dd200101c5051a97a0dc023f33ab4867db /tests
parent9817085bc127532b9724d80e16343cb78e3ca27a (diff)
Add a function to set a single nibble in a bitarray.
Diffstat (limited to 'tests')
-rw-r--r--tests/bitfield_tests.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/bitfield_tests.c b/tests/bitfield_tests.c
index 3f54eee1..e0646e6a 100644
--- a/tests/bitfield_tests.c
+++ b/tests/bitfield_tests.c
@@ -12,6 +12,20 @@ START_TEST (test_get_byte)
}
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};
@@ -57,6 +71,7 @@ Suite* bitfieldSuite(void) {
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);