blob: 34b6d748fd17e0cc702014c77b1ddb90d0c203a2 [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
23 er = uper_encode_to_buffer(&asn_DEF_T, 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);
45}
46
47int main() {
48 T_t ti;
49
50 ti.small32range = 0;
51 ti.full32range = 0;
Lev Walkin8bb57a22007-12-03 13:41:36 +000052 ti.unsigned32 = 0;
53 ti.unsplit32 = 5;
54 verify(1, &ti);
Lev Walkina105cbc2007-11-06 02:35:13 +000055
56 ti.small32range = -1;
57 ti.full32range = -1;
Lev Walkin8bb57a22007-12-03 13:41:36 +000058 ti.unsigned32 = 1;
59 ti.unsplit32 = 300;
60 verify(2, &ti);
Lev Walkina105cbc2007-11-06 02:35:13 +000061
62 ti.small32range = -2000000000;
63 ti.full32range = (-2147483647L - 1);
Lev Walkin8bb57a22007-12-03 13:41:36 +000064 ti.unsigned32 = 4000000000;
65 ti.unsplit32 = 500;
66 verify(3, &ti);
Lev Walkina105cbc2007-11-06 02:35:13 +000067
68 ti.small32range = -1999999999;
69 ti.full32range = (-2147483647L);
Lev Walkin8bb57a22007-12-03 13:41:36 +000070 ti.unsigned32 = 4294967295UL;
71 ti.unsplit32 = 600;
72 verify(4, &ti);
Lev Walkina105cbc2007-11-06 02:35:13 +000073
74 ti.small32range = 2000000000;
75 ti.full32range = 2147483647;
Lev Walkin8bb57a22007-12-03 13:41:36 +000076 ti.unsigned32 = 4294967295UL - 100;
77 ti.unsplit32 = 4294967290UL;
78 verify(5, &ti);
Lev Walkina105cbc2007-11-06 02:35:13 +000079
80 ti.small32range = 1999999999;
81 ti.full32range = 2147483647 - 1;
Lev Walkin8bb57a22007-12-03 13:41:36 +000082 ti.unsigned32 = 4294967295UL - 1;
83 ti.unsplit32 = 4294967290UL - 1;
84 verify(6, &ti);
Lev Walkina105cbc2007-11-06 02:35:13 +000085
86 return 0;
87}