9060a6b9e2d30811c3d47e9ba447f1cd2c6aa0e2
[com/asn1c.git] / tests / tests-c-compiler / check-src / check-135.-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     asn_enc_rval_t er =
23         oer_encode_to_buffer(&asn_DEF_T, 0, &source, tmpbuf, sizeof(tmpbuf));
24     assert(er.encoded != -1);
25
26     asn_dec_rval_t dr =
27         oer_decode(0, &asn_DEF_T, (void **)&decoded, tmpbuf, er.encoded);
28
29     assert(dr.code == RC_OK);
30     if((ssize_t)dr.consumed != er.encoded) {
31         ASN_DEBUG("Consumed %zu, expected %zu", dr.consumed, er.encoded);
32         assert((ssize_t)dr.consumed == er.encoded);
33     }
34
35     if(XEQ_SUCCESS != xer_equivalent(&asn_DEF_T, &source, decoded, stderr)) {
36         return 1;
37     }
38
39     ASN_STRUCT_RESET(asn_DEF_T, &source);
40     ASN_STRUCT_FREE(asn_DEF_T, decoded);
41     return 0;
42 }
43