blob: 866fd71df7ee4c9e9a4256c65c02a794cbb42843 [file] [log] [blame]
Lev Walkinb2284472017-07-14 15:18:30 +04001/*
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
15int main() {
Lev Walkin4a06e6a2017-07-20 14:52:46 +030016 uint8_t tmpbuf[128];
Lev Walkin7eac0df2017-07-25 09:32:01 -070017 T_t source;
18 T_t *decoded = 0; /* "= 0" is important */
Lev Walkinb2284472017-07-14 15:18:30 +040019
Lev Walkin7eac0df2017-07-25 09:32:01 -070020 memset(&source, 0, sizeof(source));
Lev Walkinb2284472017-07-14 15:18:30 +040021
Lev Walkin6cea1452017-07-24 01:49:39 +040022 /* Fill in complex INTEGER */
Lev Walkin7eac0df2017-07-25 09:32:01 -070023 asn_long2INTEGER(&source.unsigned33, 0);
Lev Walkin6cea1452017-07-24 01:49:39 +040024
Lev Walkin4a06e6a2017-07-20 14:52:46 +030025 asn_enc_rval_t er =
Lev Walkin7eac0df2017-07-25 09:32:01 -070026 oer_encode_to_buffer(&asn_DEF_T, 0, &source, tmpbuf, sizeof(tmpbuf));
Lev Walkin4a06e6a2017-07-20 14:52:46 +030027 assert(er.encoded != -1);
28
29 asn_dec_rval_t dr =
Lev Walkin7eac0df2017-07-25 09:32:01 -070030 oer_decode(0, &asn_DEF_T, (void **)&decoded, tmpbuf, er.encoded);
Lev Walkin4a06e6a2017-07-20 14:52:46 +030031
32 assert(dr.code == RC_OK);
Lev Walkinbc09dd42017-10-19 02:16:35 -070033 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);
Lev Walkin6cea1452017-07-24 01:49:39 +040036 }
37
Lev Walkin7eac0df2017-07-25 09:32:01 -070038 if(XEQ_SUCCESS != xer_equivalent(&asn_DEF_T, &source, decoded, stderr)) {
39 return 1;
40 }
Vasil Velichkovcef21e02017-10-09 23:40:17 +030041 ASN_STRUCT_RESET(asn_DEF_T, &source);
42 ASN_STRUCT_FREE(asn_DEF_T, decoded);
Lev Walkin4a06e6a2017-07-20 14:52:46 +030043 return 0;
Lev Walkinb2284472017-07-14 15:18:30 +040044}
45