2 #include "libserialport.h"
3 #include "libserialport_internal.h"
7 int main(int argc
, char *argv
[])
14 printf("Testing arithmetic\n");
15 time_set_ms(&a
, 10050);
17 assert(time_greater(&a
, &b
));
18 assert(!time_greater(&b
, &a
));
20 assert(time_as_ms(&c
) == 10150);
22 assert(time_as_ms(&c
) == 9950);
23 time_as_timeval(&a
, &tv
);
24 assert(tv
.tv_sec
== 10);
25 assert(tv
.tv_usec
== 50000);
27 printf("Sleeping for 1s\n");
31 printf("Measured: %ums\n", time_as_ms(&c
));
32 assert(time_as_ms(&c
) >= 999);
33 assert(time_as_ms(&c
) <= 1001);
34 printf("Starting 3s timeout\n");
35 timeout_start(&to
, 3000);
36 printf("Time to wait: %dms\n", timeout_remaining_ms(&to
));
37 printf("Sleeping for 1s\n");
40 assert(!timeout_check(&to
));
41 printf("Sleeping for 1s\n");
44 assert(!timeout_check(&to
));
45 printf("Remaining: %ums\n", timeout_remaining_ms(&to
));
46 printf("Sleeping for 1s\n");
49 assert(timeout_check(&to
));
50 printf("Timeout expired\n");
51 printf("Starting 2s timeout\n");
52 timeout_start(&to
, 2000);
53 printf("Limiting steps to 1s\n");
54 timeout_limit(&to
, 1000);
55 printf("Time to wait: %ums\n", timeout_remaining_ms(&to
));
56 printf("Sleeping for 1s\n");
59 assert(!timeout_check(&to
));
60 printf("Remaining: %ums\n", timeout_remaining_ms(&to
));
61 printf("Sleeping for 1s\n");
64 assert(timeout_check(&to
));
65 printf("Timeout expired\n");