f7a770e32324bd970ebd43233fecfc2f2633fd79
[com/asn1c.git] / tests / tests-c-compiler / check-src / check-133.-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[8];
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);
22         assert(er.encoded <= (ssize_t)(8 * sizeof(buf)));
23
24         rv = uper_decode(0, &asn_DEF_T, (void *)&to, buf, sizeof buf, 0, 0);
25         assert(rv.code == RC_OK);
26
27         fprintf(stderr, "%d ENC: %2x%2x\n", testNo,
28                 buf[0], buf[1]);
29         fprintf(stderr, "%d OUT: %d\n", testNo, ti->present);
30         assert(ti->present == to->present);
31         switch(ti->present) {
32         case T_PR_NOTHING:
33                 assert(ti->present != T_PR_NOTHING);
34                 break;
35         case T_PR_first:
36                 assert(ti->choice.first.present == to->choice.first.present);
37                 assert(ti->choice.first.choice.nothing == to->choice.first.choice.nothing);
38                 break;
39         case T_PR_second:
40                 assert(ti->choice.second == to->choice.second);
41                 break;
42         case T_PR_third:
43                 assert(ti->choice.third == to->choice.third);
44                 break;
45         }
46
47         xer_fprint(stderr, &asn_DEF_T, ti);
48         xer_fprint(stderr, &asn_DEF_T, to);
49 }
50
51 int main() {
52         T_t t;
53
54         return 0;       // this test fails, but not important atm.
55
56         memset(&t, 0, sizeof(t));
57         t.present = T_PR_first;
58         t.choice.first.present = first_PR_nothing;
59         t.choice.first.choice.nothing = 5;
60         verify(0, &t);
61
62         memset(&t, 0, sizeof(t));
63         t.present = T_PR_second;
64         t.choice.second = -5;
65         verify(1, &t);
66
67         memset(&t, 0, sizeof(t));
68         t.present = T_PR_second;
69         t.choice.second = 10;
70         verify(2, &t);
71
72         memset(&t, 0, sizeof(t));
73         t.present = T_PR_third;
74         t.choice.third = -10;
75         verify(3, &t);
76
77         memset(&t, 0, sizeof(t));
78         t.present = T_PR_third;
79         t.choice.third = 4097;
80         verify(4, &t);
81
82         return 0;
83 }