blob: ff20772b5a4957af9744d9c8f471e0e1d14ae720 [file] [log] [blame]
Lev Walkinf15320b2004-06-03 03:38:44 +00001#define __NO_ASN_TABLE__
Lev Walkin44212662004-08-19 13:26:54 +00002#include <GeneralizedTime.c>
3#include <constraints.c>
Lev Walkinf15320b2004-06-03 03:38:44 +00004
5static void
Lev Walkin99006362004-08-07 03:52:26 +00006check(char *time_str, time_t expect, int as_gmt) {
Lev Walkinf15320b2004-06-03 03:38:44 +00007 GeneralizedTime_t gt;
8 struct tm tm;
9 time_t tloc;
10
11 gt.buf = time_str;
12 gt.size = strlen(time_str);
13
Lev Walkin99006362004-08-07 03:52:26 +000014 tloc = asn_GT2time(&gt, &tm, as_gmt);
15 printf("%s: [%s] -> %ld == %ld\n",
16 as_gmt?"GMT":"ofs", time_str, (long)tloc, (long)expect);
Lev Walkina460ba32004-10-20 15:40:04 +000017
18 if(tloc != -1) {
19 printf("\t%04d-%02d-%02dT%02d:%02d:%02d%+03ld%02ld\n",
Lev Walkinf15320b2004-06-03 03:38:44 +000020 tm.tm_year + 1900,
21 tm.tm_mon + 1,
22 tm.tm_mday,
23 tm.tm_hour,
24 tm.tm_min,
25 tm.tm_sec,
Lev Walkina460ba32004-10-20 15:40:04 +000026 (GMTOFF(tm) / 3600),
27 labs(GMTOFF(tm) % 3600)
28 );
29 }
Lev Walkin99006362004-08-07 03:52:26 +000030 assert(tloc == expect);
31
Lev Walkina460ba32004-10-20 15:40:04 +000032#ifdef HAVE_TM_GMTOFF
33 assert(tloc == -1 || as_gmt == 0 || GMTOFF(tm) == 0);
34#endif
Lev Walkin99006362004-08-07 03:52:26 +000035
36 if(!as_gmt) check(time_str, expect, 1);
37}
38
39static void
40rcheck(time_t tloc, const char *expect, int force_gmt) {
41 GeneralizedTime_t *gt;
42 struct tm tm, *tmp;
43
44 tmp = localtime_r(&tloc, &tm);
45 assert(tmp);
46
47 gt = asn_time2GT(0, &tm, force_gmt);
48 if(gt) {
49 assert(expect);
50 printf("[%s] vs [%s] (%d)\n",
51 gt->buf, expect, force_gmt);
Lev Walkin44212662004-08-19 13:26:54 +000052 assert(gt->size == (int)strlen(gt->buf));
Lev Walkin99006362004-08-07 03:52:26 +000053 assert(!strcmp(gt->buf, expect));
54 } else {
55 assert(!expect);
56 }
Lev Walkinf15320b2004-06-03 03:38:44 +000057}
58
59int
60main(int ac, char **av) {
61
Lev Walkin44212662004-08-19 13:26:54 +000062 (void)av;
63
Lev Walkin99006362004-08-07 03:52:26 +000064 check("200401250", -1, 0);
65 check("2004012509300", -1, 0);
66 check("20040125093000-", -1, 0);
67 check("20040125093007-0", -1, 0);
68 check("20040125093007-080", -1, 0);
69 check("200401250930.01Z", -1, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +000070
Lev Walkin99006362004-08-07 03:52:26 +000071 /* These six are from X.690:11.7.5 */
72 check("19920520240000Z", -1, 0); /* midnight represented incorrectly */
73 //check("19920622123421.0Z", -1, 0); /* spurious trailing zeros */
74 //check("19920722132100.30Z", -1, 0); /* spurious trailing zeros */
75 check("19920521000000Z", 706406400, 0);
76 check("19920622123421Z", 709216461, 0);
77 check("19920722132100.3Z", 711811260, 0);
78
79 check("20040125093007Z", 1075023007, 0);
80 check("20040125093007+00", 1075023007, 0);
81 check("20040125093007.01+0000", 1075023007, 0);
82 check("20040125093007,1+0000", 1075023007, 0);
83 check("20040125093007-0800", 1075051807, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +000084
Lev Walkin91d40d42004-08-07 04:16:42 +000085 rcheck(1075023007, "20040125093007Z", 1);
86
Lev Walkinf15320b2004-06-03 03:38:44 +000087 if(ac > 1) {
88 /* These will be valid only inside PST time zone */
Lev Walkin99006362004-08-07 03:52:26 +000089 check("20040125093007", 1075051807, 0);
90 check("200401250930", 1075051800, 0);
91 check("20040125093000,01", 1075051800, 0);
92 check("20040125093000,1234", 1075051800, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +000093
Lev Walkin91d40d42004-08-07 04:16:42 +000094 rcheck(1075023007, "20040125013007-0800", 0);
95 }
Lev Walkin99006362004-08-07 03:52:26 +000096
Lev Walkinf15320b2004-06-03 03:38:44 +000097 return 0;
98}
Lev Walkin99006362004-08-07 03:52:26 +000099
100/*
101 * Dummy function.
102 */
103
Lev Walkina9cc46e2004-09-22 16:06:28 +0000104asn_enc_rval_t
Lev Walkin5e033762004-09-29 13:26:15 +0000105OCTET_STRING_encode_der(asn_TYPE_descriptor_t *td, void *ptr, int tag_mode, ber_tlv_tag_t tag, asn_app_consume_bytes_f *cb, void *app_key) {
Lev Walkina9cc46e2004-09-22 16:06:28 +0000106 asn_enc_rval_t erval;
Lev Walkin44212662004-08-19 13:26:54 +0000107
108 (void)td;
109 (void)ptr;
110 (void)tag_mode;
111 (void)tag;
112 (void)cb;
113 (void)app_key;
114
Lev Walkin99006362004-08-07 03:52:26 +0000115 return erval;
116}
Lev Walkina9cc46e2004-09-22 16:06:28 +0000117
118asn_enc_rval_t
Lev Walkindc06f6b2004-10-20 15:50:55 +0000119OCTET_STRING_encode_xer_utf8(asn_TYPE_descriptor_t *td, void *ptr, int ilevel, enum xer_encoder_flags_e flags, asn_app_consume_bytes_f *cb, void *app_key) {
Lev Walkina9cc46e2004-09-22 16:06:28 +0000120 asn_enc_rval_t erval;
121
122 (void)td;
123 (void)ptr;
124 (void)ilevel;
125 (void)flags;
126 (void)cb;
127 (void)app_key;
128
129 return erval;
130}