NativeEnumerated.c vars NULL init and check
[com/asn1c.git] / tests / tests-c-compiler / check-src / check64-136.-gen-OER.c
1 /*
2  * Verify OER with constrained INTEGER code gen.
3  */
4 #undef  NDEBUG
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <sys/types.h>
8 #include <string.h>
9 #include <assert.h>
10 #include <ctype.h>
11 #include <errno.h>
12
13 #include <T.h>
14
15 int main() {
16     uint8_t tmpbuf[128];
17     T_t source;
18     T_t *decoded = 0; /* "= 0" is important */
19
20     memset(&source, 0, sizeof(source));
21
22     /* Fill in complex INTEGER */
23     asn_long2INTEGER(&source.unsigned33, 0);
24
25     asn_enc_rval_t er =
26         oer_encode_to_buffer(&asn_DEF_T, 0, &source, tmpbuf, sizeof(tmpbuf));
27     assert(er.encoded != -1);
28
29     asn_dec_rval_t dr =
30         oer_decode(0, &asn_DEF_T, (void **)&decoded, tmpbuf, er.encoded);
31
32     assert(dr.code == RC_OK);
33     if((ssize_t)dr.consumed != er.encoded) {
34         ASN_DEBUG("Consumed %zd, expected %zu", dr.consumed, er.encoded);
35         assert((ssize_t)dr.consumed == er.encoded);
36     }
37
38     if(XEQ_SUCCESS != xer_equivalent(&asn_DEF_T, &source, decoded, stderr)) {
39         return 1;
40     }
41     ASN_STRUCT_RESET(asn_DEF_T, &source);
42     ASN_STRUCT_FREE(asn_DEF_T, decoded);
43     return 0;
44 }
45