NativeEnumerated.c vars NULL init and check
[com/asn1c.git] / tests / tests-c-compiler / check-src / check-127.-gen-PER.c
1 #undef  NDEBUG
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <sys/types.h>
5 #include <string.h>
6 #include <assert.h>
7 #include <ctype.h>
8 #include <errno.h>
9
10 #include <T.h>
11
12 static void
13 verify(int testNo, T_t *ti) {
14         asn_enc_rval_t er;
15         asn_dec_rval_t rv;
16         unsigned char buf[16];
17         T_t *to = 0;
18
19         fprintf(stderr, "%d IN: { %ld, %ld, %lu, %lu }\n", testNo,
20                 ti->small32range, ti->full32range,
21                 ti->unsigned32, ti->unsplit32);
22
23         er = uper_encode_to_buffer(&asn_DEF_T, 0, ti, buf, sizeof buf);
24         assert(er.encoded == 8 * sizeof(buf));
25
26         rv = uper_decode(0, &asn_DEF_T, (void *)&to, buf, sizeof buf, 0, 0);
27         assert(rv.code == RC_OK);
28
29         fprintf(stderr, "%d ENC: %2x%2x%2x%2x %2x%2x%2x%2x\n", testNo,
30                 buf[0], buf[1], buf[2], buf[3],
31                 buf[4], buf[5], buf[6], buf[7]);
32         fprintf(stderr, "%d OUT: { %ld, %ld, %lu, %lu } vs { %ld, %ld, %lu, %lu }\n",
33                 testNo,
34                 ti->small32range, ti->full32range,
35                         ti->unsigned32, ti->unsplit32,
36                 to->small32range, to->full32range,
37                         to->unsigned32, to->unsplit32);
38         assert(ti->small32range == to->small32range);
39         assert(ti->full32range == to->full32range);
40         assert(ti->unsigned32 == to->unsigned32);
41         assert(ti->unsplit32 == to->unsplit32);
42
43         xer_fprint(stderr, &asn_DEF_T, ti);
44         xer_fprint(stderr, &asn_DEF_T, to);
45
46         ASN_STRUCT_FREE(asn_DEF_T, to);
47 }
48
49 int main() {
50         T_t ti;
51
52         ti.small32range = 0;
53         ti.full32range = 0;
54         ti.unsigned32 = 0;
55         ti.unsplit32 = 5;
56         verify(1, &ti);
57
58         ti.small32range = -1;
59         ti.full32range = -1;
60         ti.unsigned32 = 1;
61         ti.unsplit32 = 300;
62         verify(2, &ti);
63
64         ti.small32range = -2000000000;
65         ti.full32range = (-2147483647L - 1);
66         ti.unsigned32 = 4000000000;
67         ti.unsplit32 = 500;
68         verify(3, &ti);
69
70         ti.small32range = -1999999999;
71         ti.full32range = (-2147483647L);
72         ti.unsigned32 = 4294967295UL;
73         ti.unsplit32 = 600;
74         verify(4, &ti);
75
76         ti.small32range = 2000000000;
77         ti.full32range = 2147483647;
78         ti.unsigned32 = 4294967295UL - 100;
79         ti.unsplit32 = 4294967290UL;
80         verify(5, &ti);
81
82         ti.small32range = 1999999999;
83         ti.full32range = 2147483647 - 1;
84         ti.unsigned32 = 4294967295UL - 1;
85         ti.unsplit32 = 4294967290UL - 1;
86         verify(6, &ti);
87
88         return 0;
89 }