summaryrefslogtreecommitdiffstats
path: root/tests/write_tests.c
blob: da5ee89cbc1d279f5b94c4a0ed23a43b0be4c6eb (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
#include <canutil/write.h>
#include <check.h>
#include <stdint.h>

START_TEST (test_encode_can_signal)
{
    uint64_t value = encodeFloat(0, 1, 3, 1, 0);
    ck_assert_int_eq(value, 0);
}
END_TEST

START_TEST (test_encode_can_signal_rounding_precision)
{
    uint64_t value = encodeFloat(50, 2, 19, 0.001, 0);
    ck_assert_int_eq(value, 0x061a800000000000LLU);
}
END_TEST

Suite* canwriteSuite(void) {
    Suite* s = suite_create("write");
    TCase *tc_core = tcase_create("core");
    tcase_add_checked_fixture(tc_core, NULL, NULL);
    tcase_add_test(tc_core, test_encode_can_signal);
    tcase_add_test(tc_core, test_encode_can_signal_rounding_precision);
    suite_add_tcase(s, tc_core);

    return s;
}

int main(void) {
    int numberFailed;
    Suite* s = canwriteSuite();
    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;
}