3 #include <canutil/read.h>
5 const uint64_t BIG_ENDIAN_TEST_DATA = __builtin_bswap64(0xEB00000000000000);
6 const uint8_t ARRAY_TEST_DATA[] = {0xEB, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
8 START_TEST (test_eightbyte_parse_float)
10 float result = eightbyte_parse_float(BIG_ENDIAN_TEST_DATA, 2, 4, 1001.0,
12 float correctResult = 0xA * 1001.0 - 30000.0;
13 fail_unless(result == correctResult,
14 "parse is incorrect: %f but should be %f", result, correctResult);
18 START_TEST (test_eightbyte_parse_bool)
20 bool result = eightbyte_parse_bool(BIG_ENDIAN_TEST_DATA, 0, 1, 1.0, 0);
21 bool correctResult = true;
22 fail_unless(result == correctResult,
23 "parse is incorrect: %d but should be %d", result, correctResult);
27 START_TEST (test_bitfield_parse_float)
29 float result = bitfield_parse_float(ARRAY_TEST_DATA,
30 sizeof(ARRAY_TEST_DATA), 2, 4, 1001.0, -30000.0);
31 float correctResult = 0xA * 1001.0 - 30000.0;
32 fail_unless(result == correctResult,
33 "parse is incorrect: %f but should be %f", result, correctResult);
37 START_TEST (test_bitfield_parse_bool)
39 fail_unless(bitfield_parse_bool(ARRAY_TEST_DATA, sizeof(ARRAY_TEST_DATA),
44 Suite* canreadSuite(void) {
45 Suite* s = suite_create("read");
46 TCase *tc_core = tcase_create("core");
47 tcase_add_checked_fixture(tc_core, NULL, NULL);
48 tcase_add_test(tc_core, test_eightbyte_parse_float);
49 tcase_add_test(tc_core, test_eightbyte_parse_bool);
50 tcase_add_test(tc_core, test_bitfield_parse_float);
51 tcase_add_test(tc_core, test_bitfield_parse_bool);
52 suite_add_tcase(s, tc_core);
59 Suite* s = canreadSuite();
60 SRunner *sr = srunner_create(s);
61 // Don't fork so we can actually use gdb
62 srunner_set_fork_status(sr, CK_NOFORK);
63 srunner_run_all(sr, CK_NORMAL);
64 numberFailed = srunner_ntests_failed(sr);
66 return (numberFailed == 0) ? 0 : 1;