~ubuntu-branches/ubuntu/dapper/asn1c/dapper

« back to all changes in this revision

Viewing changes to skeletons/tests/check-GeneralizedTime.c

  • Committer: Bazaar Package Importer
  • Author(s): W. Borgert
  • Date: 2005-05-28 12:36:42 UTC
  • Revision ID: james.westby@ubuntu.com-20050528123642-3h6kstws5u0xcovl
Tags: upstream-0.9.14
ImportĀ upstreamĀ versionĀ 0.9.14

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#define __NO_ASN_TABLE__
 
2
#include <GeneralizedTime.c>
 
3
#include <constraints.c>
 
4
 
 
5
static void
 
6
check(char *time_str, time_t expect, int as_gmt) {
 
7
        GeneralizedTime_t gt;
 
8
        struct tm tm;
 
9
        time_t tloc;
 
10
 
 
11
        gt.buf = time_str;
 
12
        gt.size = strlen(time_str);
 
13
 
 
14
        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);
 
17
 
 
18
        if(tloc != -1) {
 
19
                printf("\t%04d-%02d-%02dT%02d:%02d:%02d%+03ld%02ld\n",
 
20
                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,
 
26
                (GMTOFF(tm) / 3600),
 
27
                labs(GMTOFF(tm) % 3600)
 
28
                );
 
29
        }
 
30
        assert(tloc == expect);
 
31
 
 
32
#ifdef  HAVE_TM_GMTOFF
 
33
        assert(tloc == -1 || as_gmt == 0 || GMTOFF(tm) == 0);
 
34
#endif
 
35
 
 
36
        if(!as_gmt) check(time_str, expect, 1);
 
37
}
 
38
 
 
39
static void
 
40
rcheck(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);
 
52
                assert(gt->size == (int)strlen(gt->buf));
 
53
                assert(!strcmp(gt->buf, expect));
 
54
        } else {
 
55
                assert(!expect);
 
56
        }
 
57
}
 
58
 
 
59
int
 
60
main(int ac, char **av) {
 
61
 
 
62
        (void)av;
 
63
 
 
64
        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);
 
70
 
 
71
        /* 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);
 
84
 
 
85
        rcheck(1075023007, "20040125093007Z", 1);
 
86
 
 
87
        if(ac > 1) {
 
88
                /* These will be valid only inside PST time zone */
 
89
                check("20040125093007", 1075051807, 0);
 
90
                check("200401250930", 1075051800, 0);
 
91
                check("20040125093000,01", 1075051800, 0);
 
92
                check("20040125093000,1234", 1075051800, 0);
 
93
 
 
94
                rcheck(1075023007, "20040125013007-0800", 0);
 
95
        }
 
96
 
 
97
        return 0;
 
98
}
 
99
 
 
100
/*
 
101
 * Dummy function.
 
102
 */
 
103
 
 
104
asn_enc_rval_t
 
105
OCTET_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) {
 
106
        asn_enc_rval_t erval;
 
107
 
 
108
        (void)td;
 
109
        (void)ptr;
 
110
        (void)tag_mode;
 
111
        (void)tag;
 
112
        (void)cb;
 
113
        (void)app_key;
 
114
 
 
115
        return erval;
 
116
}
 
117
 
 
118
asn_enc_rval_t
 
119
OCTET_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) {
 
120
        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
}