3 #include <canutil/read.h>
5 const uint64_t BIG_ENDIAN_TEST_DATA = __builtin_bswap64(0xEB00000000000000);
7 START_TEST (test_parse_float)
9 float result = bitfield_parse_float(BIG_ENDIAN_TEST_DATA, 2, 4, 1001.0,
11 float correctResult = 0xA * 1001.0 - 30000.0;
12 fail_unless(result == correctResult,
13 "parse is incorrect: %f but should be %f", result, correctResult);
17 START_TEST (test_parse_bool)
19 float result = bitfield_parse_bool(BIG_ENDIAN_TEST_DATA, 0, 1, 1.0, 0);
20 float correctResult = true;
21 fail_unless(result == correctResult,
22 "parse is incorrect: %d but should be %d", result, correctResult);
26 Suite* canreadSuite(void) {
27 Suite* s = suite_create("read");
28 TCase *tc_core = tcase_create("core");
29 tcase_add_checked_fixture(tc_core, NULL, NULL);
30 tcase_add_test(tc_core, test_parse_float);
31 tcase_add_test(tc_core, test_parse_bool);
32 suite_add_tcase(s, tc_core);
39 Suite* s = canreadSuite();
40 SRunner *sr = srunner_create(s);
41 // Don't fork so we can actually use gdb
42 srunner_set_fork_status(sr, CK_NOFORK);
43 srunner_run_all(sr, CK_NORMAL);
44 numberFailed = srunner_ntests_failed(sr);
46 return (numberFailed == 0) ? 0 : 1;