summaryrefslogtreecommitdiffstats
path: root/tests/read_tests.c
blob: 71b0ab656143ddf80e7425e7f42a17414cca1a08 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <check.h>
#include <stdint.h>
#include <canutil/read.h>

const uint64_t BIG_ENDIAN_TEST_DATA = __builtin_bswap64(0xEB00000000000000);

START_TEST (test_parse_float)
{
    float result = bitfield_parse_float(BIG_ENDIAN_TEST_DATA, 2, 4, 1001.0,
            -30000.0);
    float correctResult = 0xA * 1001.0 - 30000.0;
    fail_unless(result == correctResult,
            "parse is incorrect: %f but should be %f", result, correctResult);
}
END_TEST

START_TEST (test_parse_bool)
{
    float result = bitfield_parse_bool(BIG_ENDIAN_TEST_DATA, 0, 1, 1.0, 0);
    float correctResult = true;
    fail_unless(result == correctResult,
            "parse is incorrect: %d but should be %d", result, correctResult);
}
END_TEST

Suite* canreadSuite(void) {
    Suite* s = suite_create("read");
    TCase *tc_core = tcase_create("core");
    tcase_add_checked_fixture(tc_core, NULL, NULL);
    tcase_add_test(tc_core, test_parse_float);
    tcase_add_test(tc_core, test_parse_bool);
    suite_add_tcase(s, tc_core);

    return s;
}

int main(void) {
    int numberFailed;
    Suite* s = canreadSuite();
    SRunner *sr = srunner_create(s);
    // Don't fork so we can actually use gdb
    srunner_set_fork_status(sr, CK_NOFORK);
    srunner_run_all(sr, CK_NORMAL);
    numberFailed = srunner_ntests_failed(sr);
    srunner_free(sr);
    return (numberFailed == 0) ? 0 : 1;
}