summaryrefslogtreecommitdiffstats
path: root/tests/bitfield_tests.c
diff options
context:
space:
mode:
authorChristopher Peplin <chris.peplin@rhubarbtech.com>2013-12-29 11:34:10 -0500
committerChristopher Peplin <chris.peplin@rhubarbtech.com>2013-12-29 11:34:10 -0500
commit6830d35b449141305f137f78f09c2b879bfb9b33 (patch)
tree3674285c457282211f612daa2cbd27d331f81475 /tests/bitfield_tests.c
parent20bb0f507694482d7e0c6a381e3025544aa9cb5a (diff)
Clean up bitfield API a bit.
Diffstat (limited to 'tests/bitfield_tests.c')
-rw-r--r--tests/bitfield_tests.c25
1 files changed, 17 insertions, 8 deletions
diff --git a/tests/bitfield_tests.c b/tests/bitfield_tests.c
index 056f8c13..e2304ea0 100644
--- a/tests/bitfield_tests.c
+++ b/tests/bitfield_tests.c
@@ -193,9 +193,9 @@ END_TEST
START_TEST (test_get_byte)
{
uint8_t data[4] = {0x12, 0x34, 0x56, 0x78};
- uint8_t result = getByte(0, data, sizeof(data), ENDIANNESS_BIG_ENDIAN);
+ uint8_t result = getByte(0, data, sizeof(data));
ck_assert_int_eq(result, 0x12);
- result = getByte(3, data, sizeof(data), ENDIANNESS_BIG_ENDIAN);
+ result = getByte(3, data, sizeof(data));
ck_assert_int_eq(result, 0x78);
}
END_TEST
@@ -203,20 +203,28 @@ END_TEST
START_TEST (test_get_nibble)
{
uint8_t data[4] = {0x12, 0x34, 0x56, 0x78};
- uint8_t result = getNibble(0, data, sizeof(data), ENDIANNESS_BIG_ENDIAN);
+ uint8_t result = getNibble(0, data, sizeof(data));
ck_assert_int_eq(result, 0x1);
- result = getNibble(1, data, sizeof(data), ENDIANNESS_BIG_ENDIAN);
+ result = getNibble(1, data, sizeof(data));
ck_assert_int_eq(result, 0x2);
- result = getNibble(2, data, sizeof(data), ENDIANNESS_BIG_ENDIAN);
+ result = getNibble(2, data, sizeof(data));
ck_assert_int_eq(result, 0x3);
}
END_TEST
-START_TEST (test_get_bits)
+START_TEST (test_get_bits_out_of_range)
{
uint8_t data[4] = {0x12, 0x34, 0x56, 0x78};
uint8_t result[4];
- getBits(0, 16, data, 36, ENDIANNESS_BIG_ENDIAN, result);
+ fail_if(copyBitsRightAligned(data, 4, 25, 16, result, 4));
+}
+END_TEST
+
+START_TEST (test_get_bits)
+{
+ uint8_t data[4] = {0x12, 0x34, 0x56, 0x78};
+ uint8_t result[4] = {0};
+ fail_unless(copyBitsRightAligned(data, 4, 0, 16, result, 4));
ck_assert_int_eq(result[0], 0x12);
ck_assert_int_eq(result[1], 0x34);
}
@@ -226,7 +234,7 @@ START_TEST (test_get_uneven_bits)
{
uint8_t data[4] = {0x12, 0x34, 0x56, 0x78};
uint8_t result[4] = {0};
- getBits(4, 12, data, 36, ENDIANNESS_BIG_ENDIAN, result);
+ fail_unless(copyBitsRightAligned(data, 4, 4, 12, result, 4));
ck_assert_int_eq(result[0], 0x2);
ck_assert_int_eq(result[1], 0x34);
}
@@ -252,6 +260,7 @@ 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_get_bits);
+ 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);