blob: 592425c595c5dc091d84b6e04a05fcfb298dd35e [file] [log] [blame]
Lev Walkine14480f2013-03-24 03:28:00 -07001#undef NDEBUG
2#include <stdio.h>
3#include <stdlib.h>
4#include <sys/types.h>
5#include <string.h>
6#include <assert.h>
7#include <ctype.h>
8#include <errno.h>
9
10#include <T.h>
11
12static void
13verify(int testNo, T_t *ti) {
14 asn_enc_rval_t er;
15 asn_dec_rval_t rv;
16 unsigned char buf[2];
17 T_t *to = 0;
18
19 er = uper_encode_to_buffer(&asn_DEF_T, ti, buf, sizeof buf);
Lev Walkin1715b322013-03-28 04:02:13 -070020 fprintf(stderr, "%d IN: %d => %zd\n", testNo, ti->present, er.encoded);
Lev Walkinfb2a30b2014-01-14 02:11:37 -080021 assert(er.encoded >= 1 && er.encoded <= (ssize_t)(8 * sizeof(buf)));
Lev Walkine14480f2013-03-24 03:28:00 -070022
23 rv = uper_decode(0, &asn_DEF_T, (void *)&to, buf, sizeof buf, 0, 0);
24 assert(rv.code == RC_OK);
25
26 fprintf(stderr, "%d ENC: %2x%2x\n", testNo,
27 buf[0], buf[1]);
28 fprintf(stderr, "%d OUT: %d\n", testNo, ti->present);
29 assert(ti->present == to->present);
30 if(ti->present == T_PR_second) {
31 assert(ti->choice.second == to->choice.second);
32 } else {
33 assert(ti->choice.first.present == to->choice.first.present);
34 assert(ti->choice.first.choice.nothing == to->choice.first.choice.nothing);
35 }
36
37 xer_fprint(stderr, &asn_DEF_T, ti);
38 xer_fprint(stderr, &asn_DEF_T, to);
39}
40
41int main() {
42 T_t t;
43
44 memset(&t, 0, sizeof(t));
45 t.present = T_PR_first;
46 t.choice.first.present = first_PR_nothing;
47 t.choice.first.choice.nothing = 5;
48 verify(0, &t);
49
50 memset(&t, 0, sizeof(t));
51 t.present = T_PR_first;
52 t.choice.first.present = first_PR_nothing;
53 t.choice.first.choice.nothing = 6;
54 verify(1, &t);
55
56 memset(&t, 0, sizeof(t));
57 t.present = T_PR_second;
58 t.choice.second = 7;
59 verify(2, &t);
60
61 return 0;
62}