NativeEnumerated.c vars NULL init and check
[com/asn1c.git] / tests / tests-c-compiler / check-src / check-132.-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[2];
17         T_t *to = 0;
18
19         er = uper_encode_to_buffer(&asn_DEF_T, 0, ti, buf, sizeof buf);
20         fprintf(stderr, "%d IN: %d => %zd\n", testNo, ti->present, er.encoded);
21         assert(er.encoded >= 1 && er.encoded <= (ssize_t)(8 * sizeof(buf)));
22
23         rv = uper_decode(0, &asn_DEF_T, (void *)&to, buf, sizeof buf, 0, 0);
24         assert(rv.code == RC_OK);
25
26         fprintf(stderr, "%d ENC: %2x%2x\n", testNo,
27                 buf[0], buf[1]);
28         fprintf(stderr, "%d OUT: %d\n", testNo, ti->present);
29         assert(ti->present == to->present);
30         if(ti->present == T_PR_second) {
31                 assert(ti->choice.second == to->choice.second);
32         } else {
33                 assert(ti->choice.first.present == to->choice.first.present);
34                 assert(ti->choice.first.choice.nothing == to->choice.first.choice.nothing);
35         }
36
37         xer_fprint(stderr, &asn_DEF_T, ti);
38         xer_fprint(stderr, &asn_DEF_T, to);
39
40         ASN_STRUCT_FREE(asn_DEF_T, to);
41 }
42
43 int main() {
44         T_t t;
45
46         memset(&t, 0, sizeof(t));
47         t.present = T_PR_first;
48         t.choice.first.present = first_PR_nothing;
49         t.choice.first.choice.nothing = 5;
50         verify(0, &t);
51
52         memset(&t, 0, sizeof(t));
53         t.present = T_PR_first;
54         t.choice.first.present = first_PR_nothing;
55         t.choice.first.choice.nothing = 6;
56         verify(1, &t);
57
58         memset(&t, 0, sizeof(t));
59         t.present = T_PR_second;
60         t.choice.second = 7;
61         verify(2, &t);
62
63         return 0;
64 }