Lev Walkin | a105cbc | 2007-11-06 02:35:13 +0000 | [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 | |
Lev Walkin | 8bb57a2 | 2007-12-03 13:41:36 +0000 | [diff] [blame] | 12 | static void |
| 13 | verify(int testNo, T_t *ti) { |
Lev Walkin | a105cbc | 2007-11-06 02:35:13 +0000 | [diff] [blame] | 14 | asn_enc_rval_t er; |
| 15 | asn_dec_rval_t rv; |
Lev Walkin | 8bb57a2 | 2007-12-03 13:41:36 +0000 | [diff] [blame] | 16 | unsigned char buf[16]; |
Lev Walkin | a105cbc | 2007-11-06 02:35:13 +0000 | [diff] [blame] | 17 | T_t *to = 0; |
| 18 | |
Lev Walkin | 8bb57a2 | 2007-12-03 13:41:36 +0000 | [diff] [blame] | 19 | fprintf(stderr, "%d IN: { %ld, %ld, %lu, %lu }\n", testNo, |
| 20 | ti->small32range, ti->full32range, |
| 21 | ti->unsigned32, ti->unsplit32); |
Lev Walkin | a105cbc | 2007-11-06 02:35:13 +0000 | [diff] [blame] | 22 | |
Lev Walkin | 5615304 | 2017-10-24 00:47:03 -0700 | [diff] [blame] | 23 | er = uper_encode_to_buffer(&asn_DEF_T, 0, ti, buf, sizeof buf); |
Lev Walkin | 8bb57a2 | 2007-12-03 13:41:36 +0000 | [diff] [blame] | 24 | assert(er.encoded == 8 * sizeof(buf)); |
Lev Walkin | a105cbc | 2007-11-06 02:35:13 +0000 | [diff] [blame] | 25 | |
| 26 | rv = uper_decode(0, &asn_DEF_T, (void *)&to, buf, sizeof buf, 0, 0); |
| 27 | assert(rv.code == RC_OK); |
| 28 | |
Lev Walkin | 8bb57a2 | 2007-12-03 13:41:36 +0000 | [diff] [blame] | 29 | fprintf(stderr, "%d ENC: %2x%2x%2x%2x %2x%2x%2x%2x\n", testNo, |
Lev Walkin | a105cbc | 2007-11-06 02:35:13 +0000 | [diff] [blame] | 30 | buf[0], buf[1], buf[2], buf[3], |
| 31 | buf[4], buf[5], buf[6], buf[7]); |
Lev Walkin | 8bb57a2 | 2007-12-03 13:41:36 +0000 | [diff] [blame] | 32 | fprintf(stderr, "%d OUT: { %ld, %ld, %lu, %lu } vs { %ld, %ld, %lu, %lu }\n", |
| 33 | testNo, |
Lev Walkin | a105cbc | 2007-11-06 02:35:13 +0000 | [diff] [blame] | 34 | ti->small32range, ti->full32range, |
Lev Walkin | 8bb57a2 | 2007-12-03 13:41:36 +0000 | [diff] [blame] | 35 | ti->unsigned32, ti->unsplit32, |
| 36 | to->small32range, to->full32range, |
| 37 | to->unsigned32, to->unsplit32); |
Lev Walkin | a105cbc | 2007-11-06 02:35:13 +0000 | [diff] [blame] | 38 | assert(ti->small32range == to->small32range); |
| 39 | assert(ti->full32range == to->full32range); |
Lev Walkin | 8bb57a2 | 2007-12-03 13:41:36 +0000 | [diff] [blame] | 40 | assert(ti->unsigned32 == to->unsigned32); |
| 41 | assert(ti->unsplit32 == to->unsplit32); |
Lev Walkin | a105cbc | 2007-11-06 02:35:13 +0000 | [diff] [blame] | 42 | |
| 43 | xer_fprint(stderr, &asn_DEF_T, ti); |
| 44 | xer_fprint(stderr, &asn_DEF_T, to); |
Vasil Velichkov | cef21e0 | 2017-10-09 23:40:17 +0300 | [diff] [blame] | 45 | |
| 46 | ASN_STRUCT_FREE(asn_DEF_T, to); |
Lev Walkin | a105cbc | 2007-11-06 02:35:13 +0000 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | int main() { |
| 50 | T_t ti; |
| 51 | |
| 52 | ti.small32range = 0; |
| 53 | ti.full32range = 0; |
Lev Walkin | 8bb57a2 | 2007-12-03 13:41:36 +0000 | [diff] [blame] | 54 | ti.unsigned32 = 0; |
| 55 | ti.unsplit32 = 5; |
| 56 | verify(1, &ti); |
Lev Walkin | a105cbc | 2007-11-06 02:35:13 +0000 | [diff] [blame] | 57 | |
| 58 | ti.small32range = -1; |
| 59 | ti.full32range = -1; |
Lev Walkin | 8bb57a2 | 2007-12-03 13:41:36 +0000 | [diff] [blame] | 60 | ti.unsigned32 = 1; |
| 61 | ti.unsplit32 = 300; |
| 62 | verify(2, &ti); |
Lev Walkin | a105cbc | 2007-11-06 02:35:13 +0000 | [diff] [blame] | 63 | |
| 64 | ti.small32range = -2000000000; |
| 65 | ti.full32range = (-2147483647L - 1); |
Lev Walkin | 8bb57a2 | 2007-12-03 13:41:36 +0000 | [diff] [blame] | 66 | ti.unsigned32 = 4000000000; |
| 67 | ti.unsplit32 = 500; |
| 68 | verify(3, &ti); |
Lev Walkin | a105cbc | 2007-11-06 02:35:13 +0000 | [diff] [blame] | 69 | |
| 70 | ti.small32range = -1999999999; |
| 71 | ti.full32range = (-2147483647L); |
Lev Walkin | 8bb57a2 | 2007-12-03 13:41:36 +0000 | [diff] [blame] | 72 | ti.unsigned32 = 4294967295UL; |
| 73 | ti.unsplit32 = 600; |
| 74 | verify(4, &ti); |
Lev Walkin | a105cbc | 2007-11-06 02:35:13 +0000 | [diff] [blame] | 75 | |
| 76 | ti.small32range = 2000000000; |
| 77 | ti.full32range = 2147483647; |
Lev Walkin | 8bb57a2 | 2007-12-03 13:41:36 +0000 | [diff] [blame] | 78 | ti.unsigned32 = 4294967295UL - 100; |
| 79 | ti.unsplit32 = 4294967290UL; |
| 80 | verify(5, &ti); |
Lev Walkin | a105cbc | 2007-11-06 02:35:13 +0000 | [diff] [blame] | 81 | |
| 82 | ti.small32range = 1999999999; |
| 83 | ti.full32range = 2147483647 - 1; |
Lev Walkin | 8bb57a2 | 2007-12-03 13:41:36 +0000 | [diff] [blame] | 84 | ti.unsigned32 = 4294967295UL - 1; |
| 85 | ti.unsplit32 = 4294967290UL - 1; |
| 86 | verify(6, &ti); |
Lev Walkin | a105cbc | 2007-11-06 02:35:13 +0000 | [diff] [blame] | 87 | |
| 88 | return 0; |
| 89 | } |