NativeEnumerated.c vars NULL init and check
[com/asn1c.git] / tests / tests-c-compiler / check-src / check-44.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
8 #include <T.h>
9
10 uint8_t buf1[] = {
11         32 | ((3 << 6) + 1),    /* [PRIVATE 1], constructed */
12         4,      /* L */
13         ((3 << 6) + 2),         /* [PRIVATE 2], primitive */
14         0,      /* L */
15         ((3 << 6) + 5),         /* [PRIVATE 5], primitive */
16         0,      /* L */
17 };
18
19 uint8_t buf2[] = {
20         32 | ((3 << 6) + 1),    /* [PRIVATE 1], constructed */
21         6,      /* L */
22         ((3 << 6) + 2),         /* [PRIVATE 2], primitive */
23         0,      /* L */
24         32 | ((3 << 6) + 9),    /* [PRIVATE 9], constructed */
25         2,
26         ((3 << 6) + 1),         /* [PRIVATE 1], primitive */
27         0,      /* L */
28 };
29
30 static void
31 check(int is_ok, uint8_t *buf, size_t size, size_t consumed) {
32         T_t t, *tp;
33         asn_dec_rval_t rval;
34
35         tp = memset(&t, 0, sizeof(t));
36
37         fprintf(stderr, "Buf %p\n", buf);
38         rval = ber_decode(0, &asn_DEF_T, (void **)&tp, buf, size);
39         fprintf(stderr, "Returned code %d, consumed %zd\n",
40                 (int)rval.code, rval.consumed);
41
42         if(is_ok) {
43                 assert(rval.code == RC_OK);
44                 assert(rval.consumed == consumed);
45         } else {
46                 if(rval.code == RC_OK) {
47                 }
48                 assert(rval.consumed <= consumed);
49         }
50 }
51
52 int
53 main(int ac, char **av) {
54
55         (void)ac;       /* Unused argument */
56         (void)av;       /* Unused argument */
57
58         check(1, buf1, sizeof(buf1), sizeof(buf1));
59         check(0, buf1, sizeof(buf1) - 1, sizeof(buf1) - 1);
60         check(0, buf1, sizeof(buf1) - 2, sizeof(buf1) - 2);
61
62         check(1, buf2, sizeof(buf2), sizeof(buf2));
63         check(0, buf2, sizeof(buf2) - 1, sizeof(buf2));
64
65         return 0;
66 }