Lev Walkin | e14480f | 2013-03-24 03:28:00 -0700 | [diff] [blame] | 1 | #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 | |
| 12 | static void |
| 13 | verify(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 Walkin | 1715b32 | 2013-03-28 04:02:13 -0700 | [diff] [blame] | 20 | fprintf(stderr, "%d IN: %d => %zd\n", testNo, ti->present, er.encoded); |
Lev Walkin | fb2a30b | 2014-01-14 02:11:37 -0800 | [diff] [blame] | 21 | assert(er.encoded >= 1 && er.encoded <= (ssize_t)(8 * sizeof(buf))); |
Lev Walkin | e14480f | 2013-03-24 03:28:00 -0700 | [diff] [blame] | 22 | |
| 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 | |
| 41 | int 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 | } |