2 #include "libserialport.h"
3 #include "libserialport_internal.h"
7 int main(int argc
, char *argv
[])
15 printf("Testing arithmetic\n");
16 time_set_ms(&a
, 10050);
18 assert(time_greater(&a
, &b
));
19 assert(!time_greater(&b
, &a
));
21 assert(time_as_ms(&c
) == 10150);
23 assert(time_as_ms(&c
) == 9950);
24 time_as_timeval(&a
, &tv
);
25 assert(tv
.tv_sec
== 10);
26 assert(tv
.tv_usec
== 50000);
28 printf("Sleeping for 1s\n");
32 printf("Measured: %ums\n", time_as_ms(&c
));
33 assert(time_as_ms(&c
) >= 950);
34 assert(time_as_ms(&c
) <= 1050);
35 printf("Starting 3s timeout\n");
36 timeout_start(&to
, 3000);
37 printf("Time to wait: %dms\n", timeout_remaining_ms(&to
));
38 printf("Sleeping for 1s\n");
41 assert(!timeout_check(&to
));
42 printf("Sleeping for 1s\n");
45 assert(!timeout_check(&to
));
46 printf("Remaining: %ums\n", timeout_remaining_ms(&to
));
47 printf("Sleeping for 1s\n");
50 assert(timeout_check(&to
));
51 printf("Timeout expired\n");
52 printf("Starting 2s timeout\n");
53 timeout_start(&to
, 2000);
54 printf("Limiting steps to 1s\n");
55 timeout_limit(&to
, 1000);
56 printf("Time to wait: %ums\n", timeout_remaining_ms(&to
));
57 printf("Sleeping for 1s\n");
60 assert(!timeout_check(&to
));
61 printf("Remaining: %ums\n", timeout_remaining_ms(&to
));
62 printf("Sleeping for 1s\n");
65 assert(timeout_check(&to
));
66 printf("Timeout expired\n");