Import Upstream version 1.8.5
[hcoop/debian/openafs.git] / tests / opr / time-t.c
1 /*
2 * Copyright (c) 2012 Your File System Inc. All rights reserved.
3 */
4
5 /* Some trivial tests for the very straightforwards OPR 100ns time
6 * implementation.
7 */
8
9 #include <afsconfig.h>
10 #include <afs/param.h>
11
12 #include <roken.h>
13
14 #include <tests/tap/basic.h>
15
16 #include <opr/time.h>
17
18 int
19 main(int argc, char **argv)
20 {
21 struct opr_time oprTime;
22 struct timeval osTimeval;
23 time_t osTime, osNow;
24 plan(4);
25
26 /* Check that FromSecs, then ToSecs results in the same value coming out */
27
28 opr_time_FromSecs(&oprTime, 1337065355);
29 osTime = opr_time_ToSecs(&oprTime);
30 ok(osTime == 1337065355, "ToSecs(FromSecs(time)) == time");
31
32 /* Check the FromTimeval, then ToTimeval result in the same value. Note that
33 * our chosen microseconds field is very close to overflow */
34
35 osTimeval.tv_sec = 1337065355;
36 osTimeval.tv_usec = 999;
37 opr_time_FromTimeval(&oprTime, &osTimeval);
38 opr_time_ToTimeval(&oprTime, &osTimeval);
39 ok(osTimeval.tv_sec == 1337065355 && osTimeval.tv_usec == 999,
40 "ToTimeval(FromTimeval(timeval) == timeval)");
41
42 /* Check that opr_time_Now looks reasonable */
43 is_int(0, opr_time_Now(&oprTime), "opr_time_Now succeeds");
44 osNow = time(NULL);
45 osTime = opr_time_ToSecs(&oprTime);
46 ok(labs(osTime - osNow) < 2, "opr_time_Now returns a reasonable value");
47
48 return 0;
49 }