b21b0c57af6a0af3bd38116e88c1fdc7e2f85e32
[com/asn1c.git] / tests / tests-c-compiler / check-src / check-137.-gen-OER.c
1 /*
2  * Verify OER with constrained and unconstrained strings.
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     OCTET_STRING_fromBuf(&source.unconstrained.unc_ia5, "foo", 3);
23     OCTET_STRING_fromBuf(&source.unconstrained.unc_utf8, "bar-whatever", 12);
24     OCTET_STRING_fromBuf(&source.unconstrained.unc_universal,
25                          "\0\0\0b\0\0\0a\0\0\0z", 12);
26
27     OCTET_STRING_fromBuf(&source.constrained.con_ia5, "ab", 2);
28     OCTET_STRING_fromBuf(&source.constrained.con_utf8, "cd-whatever", 11);
29     OCTET_STRING_fromBuf(&source.constrained.con_universal, "\0\0\0e\0\0\0f",
30                          8);
31
32     asn_enc_rval_t er =
33         oer_encode_to_buffer(&asn_DEF_T, 0, &source, tmpbuf, sizeof(tmpbuf));
34     assert(er.encoded != -1);
35
36     asn_dec_rval_t dr =
37         oer_decode(0, &asn_DEF_T, (void **)&decoded, tmpbuf, er.encoded);
38
39     assert(dr.code == RC_OK);
40     if(dr.consumed != er.encoded) {
41         ASN_DEBUG("Consumed %zu, expected %zu", dr.consumed, er.encoded);
42         assert(dr.consumed == er.encoded);
43     }
44
45     if(XEQ_SUCCESS != xer_equivalent(&asn_DEF_T, &source, decoded, stderr)) {
46         return 1;
47     }
48
49     return 0;
50 }
51