MCPcopy Create free account
hub / github.com/ElementsProject/lightning / main

Function main

ccan/ccan/time/test/run.c:5–163  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3#include <ccan/tap/tap.h>
4
5int main(void)
6{
7 struct timeabs t1, t2;
8 struct timerel t3, t4, zero = { { 0, 0 } };
9
10 plan_tests(66);
11
12 /* Test time_now */
13 t1 = time_now();
14 t2 = time_now();
15
16 /* Test time_between. */
17 t3 = time_between(t2, t1);
18 ok1(t3.ts.tv_sec > 0 || t3.ts.tv_nsec >= 0);
19 t3 = time_between(t2, t2);
20 ok1(t3.ts.tv_sec == 0 && t3.ts.tv_nsec == 0);
21 t3 = time_between(t1, t1);
22 ok1(t3.ts.tv_sec == 0 && t3.ts.tv_nsec == 0);
23
24 /* Test timeabs_eq / timerel_eq */
25 ok1(timeabs_eq(t1, t1));
26 ok1(timeabs_eq(t2, t2));
27 t3.ts.tv_sec = 0;
28 t3.ts.tv_nsec = 1;
29 ok1(!timerel_eq(t3, zero));
30 ok1(!timerel_eq(t3, zero));
31
32 /* Make sure t2 > t1. */
33 t2 = timeabs_add(t2, t3);
34
35 /* Test time_after and time_before. */
36 ok1(!timeabs_eq(t1, t2));
37 ok1(!time_after(t1, t2));
38 ok1(time_before(t1, t2));
39 ok1(time_after(t2, t1));
40 ok1(!time_before(t2, t1));
41 t3.ts.tv_sec = 0;
42 t3.ts.tv_nsec = 999999999;
43 t2 = timeabs_add(t2, t3);
44 ok1(!timeabs_eq(t1, t2));
45 ok1(!time_after(t1, t2));
46 ok1(time_before(t1, t2));
47 ok1(time_after(t2, t1));
48 ok1(!time_before(t2, t1));
49
50 /* Test time_less and time_greater. */
51 ok1(time_less(zero, t3));
52 ok1(!time_greater(zero, t3));
53 ok1(!time_less(t3, zero));
54 ok1(time_greater(t3, zero));
55
56 /* Test time_sub */
57 t3 = time_sub(t3, t3);
58 ok1(timerel_eq(t3, zero));
59
60 /* Test time_between */
61 t3 = time_between(t2, t2);
62 ok1(timerel_eq(t3, zero));

Callers

nothing calls this directly

Calls 15

time_nowFunction · 0.85
time_betweenFunction · 0.85
timeabs_eqFunction · 0.85
timerel_eqFunction · 0.85
timeabs_addFunction · 0.85
time_afterFunction · 0.85
time_beforeFunction · 0.85
time_lessFunction · 0.85
time_greaterFunction · 0.85
time_subFunction · 0.85
time_from_secFunction · 0.85
time_to_secFunction · 0.85

Tested by

no test coverage detected