summaryrefslogtreecommitdiffstats
path: root/tests/bitfield_tests.c
diff options
context:
space:
mode:
authorChristopher Peplin <chris.peplin@rhubarbtech.com>2014-01-06 13:58:36 -0500
committerChristopher Peplin <chris.peplin@rhubarbtech.com>2014-01-06 13:58:36 -0500
commiteab0c42eac865a7e965878a7f2ad548371bd34d5 (patch)
tree1dc8c6e55cb51830bd0ca5de09d277d5ad206c84 /tests/bitfield_tests.c
parentcc2f44eeedac7d6e86005543c7e1596c3c78d551 (diff)
Standardize order of arguments - destination is always last.
Diffstat (limited to 'tests/bitfield_tests.c')
-rw-r--r--tests/bitfield_tests.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/bitfield_tests.c b/tests/bitfield_tests.c
index b03882a2..b8c83b59 100644
--- a/tests/bitfield_tests.c
+++ b/tests/bitfield_tests.c
@@ -26,6 +26,27 @@ START_TEST (test_set_nibble)
}
END_TEST
+START_TEST (test_set_bitfield)
+{
+ uint8_t data[4] = {0};
+ fail_unless(set_bitfield(0x12, 0, 8, data, sizeof(data)));
+ fail_unless(set_bitfield(bitmask(3), 10, 3, data, sizeof(data)));
+ ck_assert_int_eq(data[0], 0x12);
+ ck_assert_int_eq(data[1], 0x38);
+}
+END_TEST
+
+START_TEST (test_set_bitfield_doesnt_fit)
+{
+ uint8_t data[4] = {0};
+ fail_if(set_bitfield(0xffff, 0, 8, data, sizeof(data)));
+ ck_assert_int_eq(data[0], 0);
+ ck_assert_int_eq(data[1], 0);
+ ck_assert_int_eq(data[2], 0);
+ ck_assert_int_eq(data[3], 0);
+}
+END_TEST
+
START_TEST (test_get_nibble)
{
uint8_t data[4] = {0x12, 0x34, 0x56, 0x78};
@@ -87,6 +108,8 @@ Suite* bitfieldSuite(void) {
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_set_bitfield);
+ tcase_add_test(tc_core, test_set_bitfield_doesnt_fit);
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);