blob: eca680b384220115b916fdbd788d3f2678cb85f9 [file] [log] [blame]
Lev Walkina105cbc2007-11-06 02:35:13 +00001#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 Walkin8bb57a22007-12-03 13:41:36 +000012static void
13verify(int testNo, T_t *ti) {
Lev Walkina105cbc2007-11-06 02:35:13 +000014 asn_enc_rval_t er;
15 asn_dec_rval_t rv;
Lev Walkin8bb57a22007-12-03 13:41:36 +000016 unsigned char buf[16];
Lev Walkina105cbc2007-11-06 02:35:13 +000017 T_t *to = 0;
18
Lev Walkin8bb57a22007-12-03 13:41:36 +000019 fprintf(stderr, "%d IN: { %ld, %ld, %lu, %lu }\n", testNo,
20 ti->small32range, ti->full32range,
21 ti->unsigned32, ti->unsplit32);
Lev Walkina105cbc2007-11-06 02:35:13 +000022
Lev Walkin56153042017-10-24 00:47:03 -070023 er = uper_encode_to_buffer(&asn_DEF_T, 0, ti, buf, sizeof buf);
Lev Walkin8bb57a22007-12-03 13:41:36 +000024 assert(er.encoded == 8 * sizeof(buf));
Lev Walkina105cbc2007-11-06 02:35:13 +000025
26 rv = uper_decode(0, &asn_DEF_T, (void *)&to, buf, sizeof buf, 0, 0);
27 assert(rv.code == RC_OK);
28
Lev Walkin8bb57a22007-12-03 13:41:36 +000029 fprintf(stderr, "%d ENC: %2x%2x%2x%2x %2x%2x%2x%2x\n", testNo,
Lev Walkina105cbc2007-11-06 02:35:13 +000030 buf[0], buf[1], buf[2], buf[3],
31 buf[4], buf[5], buf[6], buf[7]);
Lev Walkin8bb57a22007-12-03 13:41:36 +000032 fprintf(stderr, "%d OUT: { %ld, %ld, %lu, %lu } vs { %ld, %ld, %lu, %lu }\n",
33 testNo,
Lev Walkina105cbc2007-11-06 02:35:13 +000034 ti->small32range, ti->full32range,
Lev Walkin8bb57a22007-12-03 13:41:36 +000035 ti->unsigned32, ti->unsplit32,
36 to->small32range, to->full32range,
37 to->unsigned32, to->unsplit32);
Lev Walkina105cbc2007-11-06 02:35:13 +000038 assert(ti->small32range == to->small32range);
39 assert(ti->full32range == to->full32range);
Lev Walkin8bb57a22007-12-03 13:41:36 +000040 assert(ti->unsigned32 == to->unsigned32);
41 assert(ti->unsplit32 == to->unsplit32);
Lev Walkina105cbc2007-11-06 02:35:13 +000042
43 xer_fprint(stderr, &asn_DEF_T, ti);
44 xer_fprint(stderr, &asn_DEF_T, to);
Vasil Velichkovcef21e02017-10-09 23:40:17 +030045
46 ASN_STRUCT_FREE(asn_DEF_T, to);
Lev Walkina105cbc2007-11-06 02:35:13 +000047}
48
49int main() {
50 T_t ti;
51
52 ti.small32range = 0;
53 ti.full32range = 0;
Lev Walkin8bb57a22007-12-03 13:41:36 +000054 ti.unsigned32 = 0;
55 ti.unsplit32 = 5;
56 verify(1, &ti);
Lev Walkina105cbc2007-11-06 02:35:13 +000057
58 ti.small32range = -1;
59 ti.full32range = -1;
Lev Walkin8bb57a22007-12-03 13:41:36 +000060 ti.unsigned32 = 1;
61 ti.unsplit32 = 300;
62 verify(2, &ti);
Lev Walkina105cbc2007-11-06 02:35:13 +000063
64 ti.small32range = -2000000000;
65 ti.full32range = (-2147483647L - 1);
Lev Walkin8bb57a22007-12-03 13:41:36 +000066 ti.unsigned32 = 4000000000;
67 ti.unsplit32 = 500;
68 verify(3, &ti);
Lev Walkina105cbc2007-11-06 02:35:13 +000069
70 ti.small32range = -1999999999;
71 ti.full32range = (-2147483647L);
Lev Walkin8bb57a22007-12-03 13:41:36 +000072 ti.unsigned32 = 4294967295UL;
73 ti.unsplit32 = 600;
74 verify(4, &ti);
Lev Walkina105cbc2007-11-06 02:35:13 +000075
76 ti.small32range = 2000000000;
77 ti.full32range = 2147483647;
Lev Walkin8bb57a22007-12-03 13:41:36 +000078 ti.unsigned32 = 4294967295UL - 100;
79 ti.unsplit32 = 4294967290UL;
80 verify(5, &ti);
Lev Walkina105cbc2007-11-06 02:35:13 +000081
82 ti.small32range = 1999999999;
83 ti.full32range = 2147483647 - 1;
Lev Walkin8bb57a22007-12-03 13:41:36 +000084 ti.unsigned32 = 4294967295UL - 1;
85 ti.unsplit32 = 4294967290UL - 1;
86 verify(6, &ti);
Lev Walkina105cbc2007-11-06 02:35:13 +000087
88 return 0;
89}