Fix parse_bool tests.
authorChristopher Peplin <chris.peplin@rhubarbtech.com>
Sat, 4 Jan 2014 16:51:14 +0000 (11:51 -0500)
committerChristopher Peplin <chris.peplin@rhubarbtech.com>
Sat, 4 Jan 2014 16:51:14 +0000 (11:51 -0500)
src/bitfield/bitfield.c
src/canutil/read.c
src/canutil/read.h
tests/read_tests.c

index dddb0ee..e40ab1a 100644 (file)
@@ -38,6 +38,7 @@ uint64_t get_bitfield(const uint8_t source[], const uint8_t source_length,
         uint64_t whole;
         uint8_t bytes[sizeof(uint64_t)];
     } combined;
+    memset(combined.bytes, 0, sizeof(combined.bytes));
     copy_bits_right_aligned(source, source_length, offset, bit_count,
             combined.bytes, sizeof(combined.bytes));
     if(BYTE_ORDER == LITTLE_ENDIAN) {
index 3931721..b662e9b 100644 (file)
@@ -23,7 +23,7 @@ float bitfield_parse_float(const uint8_t source[], const uint16_t source_length,
     return raw * factor + offset;
 }
 
-float bitfield_parse_bool(const uint8_t source[], const uint16_t source_length,
+bool bitfield_parse_bool(const uint8_t source[], const uint16_t source_length,
         const uint8_t bit_offset, const uint8_t bit_size, const float factor,
         const float offset) {
     float value = bitfield_parse_float(source, source_length, bit_offset,
index 733e350..86fea78 100644 (file)
@@ -70,7 +70,7 @@ bool eightbyte_parse_bool(uint64_t source, uint8_t bit_offset, uint8_t bit_size,
  *
  * Returns false if the value was 0, otherwise true.
  */
-float bitfield_parse_float(const uint8_t source[], const uint16_t source_size,
+bool bitfield_parse_bool(const uint8_t source[], const uint16_t source_size,
         const uint8_t bit_offset, const uint8_t bit_size, const float factor,
         const float offset);
 
index 512d87e..5008cc5 100644 (file)
@@ -36,11 +36,8 @@ END_TEST
 
 START_TEST (test_bitfield_parse_bool)
 {
-    bool result = bitfield_parse_bool(ARRAY_TEST_DATA, sizeof(ARRAY_TEST_DATA),
-            0, 1, 1.0, 0);
-    bool correctResult = true;
-    fail_unless(result == correctResult,
-            "parse is incorrect: %d but should be %d", result, correctResult);
+    fail_unless(bitfield_parse_bool(ARRAY_TEST_DATA, sizeof(ARRAY_TEST_DATA),
+            0, 1, 1.0, 0));
 }
 END_TEST