aboutsummaryrefslogtreecommitdiffstats
path: root/asn1c/tests/check-src/check-127.-gen-PER.c
blob: 34b6d748fd17e0cc702014c77b1ddb90d0c203a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#undef	NDEBUG
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <string.h>
#include <assert.h>
#include <ctype.h>
#include <errno.h>

#include <T.h>

static void
verify(int testNo, T_t *ti) {
	asn_enc_rval_t er;
	asn_dec_rval_t rv;
	unsigned char buf[16];
	T_t *to = 0;

	fprintf(stderr, "%d IN: { %ld, %ld, %lu, %lu }\n", testNo,
		ti->small32range, ti->full32range,
		ti->unsigned32, ti->unsplit32);

	er = uper_encode_to_buffer(&asn_DEF_T, ti, buf, sizeof buf);
	assert(er.encoded == 8 * sizeof(buf));

	rv = uper_decode(0, &asn_DEF_T, (void *)&to, buf, sizeof buf, 0, 0);
	assert(rv.code == RC_OK);

	fprintf(stderr, "%d ENC: %2x%2x%2x%2x %2x%2x%2x%2x\n", testNo,
		buf[0], buf[1], buf[2], buf[3],
		buf[4], buf[5], buf[6], buf[7]);
	fprintf(stderr, "%d OUT: { %ld, %ld, %lu, %lu } vs { %ld, %ld, %lu, %lu }\n",
		testNo,
		ti->small32range, ti->full32range,
			ti->unsigned32, ti->unsplit32,
		to->small32range, to->full32range,
			to->unsigned32, to->unsplit32);
	assert(ti->small32range == to->small32range);
	assert(ti->full32range == to->full32range);
	assert(ti->unsigned32 == to->unsigned32);
	assert(ti->unsplit32 == to->unsplit32);

	xer_fprint(stderr, &asn_DEF_T, ti);
	xer_fprint(stderr, &asn_DEF_T, to);
}

int main() {
	T_t ti;

	ti.small32range = 0;
	ti.full32range = 0;
	ti.unsigned32 = 0;
	ti.unsplit32 = 5;
	verify(1, &ti);

	ti.small32range = -1;
	ti.full32range = -1;
	ti.unsigned32 = 1;
	ti.unsplit32 = 300;
	verify(2, &ti);

	ti.small32range = -2000000000;
	ti.full32range = (-2147483647L - 1);
	ti.unsigned32 = 4000000000;
	ti.unsplit32 = 500;
	verify(3, &ti);

	ti.small32range = -1999999999;
	ti.full32range = (-2147483647L);
	ti.unsigned32 = 4294967295UL;
	ti.unsplit32 = 600;
	verify(4, &ti);

	ti.small32range = 2000000000;
	ti.full32range = 2147483647;
	ti.unsigned32 = 4294967295UL - 100;
	ti.unsplit32 = 4294967290UL;
	verify(5, &ti);

	ti.small32range = 1999999999;
	ti.full32range = 2147483647 - 1;
	ti.unsigned32 = 4294967295UL - 1;
	ti.unsplit32 = 4294967290UL - 1;
	verify(6, &ti);

	return 0;
}