Add a sample test program to the new test suite
[openafs.git] / tests / util / ktime-t.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 #include <afsconfig.h>
11 #include <afs/param.h>
12
13 #include <stdio.h>
14
15 #include <afs/ktime.h>
16 #include <tap/basic.h>
17
18 static struct testTime {
19     char *time;
20     long code;
21     long sec;
22 } testTimes[] = {
23     { "now",                1,  0 }, /* lookup current time */
24     { "never",              0,  0xffffffff },
25     { "12/3/89",            0,  628664400 },
26     { "1/1/1",              0,  978325200 },
27     { "1/0/80",             -2, 0 },
28     { "13/1/80",            -2, 0 },
29     { "0/1/80",             -2, 0 },
30     { "1/32/80",            -2, 0 },
31     { "2/30/80",            0,  320734799 },
32     /*
33      * Oh, well: note that 2/30 is bigger than any real date in February, and
34      * since this algorithm approaches the correct value from below, this is
35      * the closest it can come.
36      */
37     { "3/1/80",             0,  320734800 },
38     { "3/1/80 0:00",        0,  320734800 },
39     { "2/30/80 24:00",      -2, 0 },
40     { "2/30/80 23:60",      -2, 0 },
41     { "22/22/22",           -2, 0 },
42     { "12/31/69 19:07",     0,  420 },
43     { "12/31/99 23:59",     0,  946702740 },
44     { "12/31/99 23:59:59",  0,  946702799 },
45     { "23:12",              -1, 0 },
46     { "22/12",              -1, 0 },
47     { "22/22/22 12",        -1, 0 },
48     { "12/31/199 23:59:59", -2, 0 },
49     { "12/31/1888",         -2, 0 },
50     { "-13/-44/22 -15:77",  -2, 0 },
51     { "4/14/24",            0,  1713070800 },
52     { "4/14/2024",          0,  1713070800 },
53     { "4/14/68",            0,  0x7fffffff }, /* legal but w/sign bit on */
54     { "4/14/69",            0,  0 },
55     { NULL,                 0,  0 }
56 };
57
58 int
59 main(void)
60 {
61     long code, temp;
62     int errors;
63     time_t t;
64     struct testTime *tt;
65
66     plan((sizeof(testTimes) / sizeof(testTimes[0]) - 1) * 2);
67
68     /* should do timezone and daylight savings time correction so this program
69      * work in other than EST */
70     putenv("TZ=EST");
71
72     errors = 0;
73     for (tt = testTimes; tt->time; tt++) {
74         t = 0;
75         code = ktime_DateToLong(tt->time, &t);
76         if (tt->code == 1) {
77             is_int(0, code, "ktime_DateToLong return for %s", tt->time);
78             ok((time(0) - t <= 1), "ktime_DateToLong result for %s", tt->time);
79         } else {
80             is_int(tt->code, code, "ktime_DateToLong return for %s", tt->time);
81             is_int(tt->sec, t, "ktime_DateToLong result for %s", tt->time);
82         }
83     }
84
85     return 0;
86 }