aboutsummaryrefslogtreecommitdiffstats
path: root/asn1c/tests/check-132.-fnative-types.-gen-PER.c
blob: d4037a54b15b18e141e81ad208b5d128aee67165 (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
#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[2];
	T_t *to = 0;

	er = uper_encode_to_buffer(&asn_DEF_T, ti, buf, sizeof buf);
	fprintf(stderr, "%d IN: %d => %d\n", testNo,
		ti->present, (int)er.encoded);
	assert(er.encoded >= 1 && 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\n", testNo,
		buf[0], buf[1]);
	fprintf(stderr, "%d OUT: %d\n", testNo, ti->present);
	assert(ti->present == to->present);
	if(ti->present == T_PR_second) {
		assert(ti->choice.second == to->choice.second);
	} else {
		assert(ti->choice.first.present == to->choice.first.present);
		assert(ti->choice.first.choice.nothing == to->choice.first.choice.nothing);
	}

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

int main() {
	T_t t;

	memset(&t, 0, sizeof(t));
	t.present = T_PR_first;
	t.choice.first.present = first_PR_nothing;
	t.choice.first.choice.nothing = 5;
	verify(0, &t);

	memset(&t, 0, sizeof(t));
	t.present = T_PR_first;
	t.choice.first.present = first_PR_nothing;
	t.choice.first.choice.nothing = 6;
	verify(1, &t);

	memset(&t, 0, sizeof(t));
	t.present = T_PR_second;
	t.choice.second = 7;
	verify(2, &t);

	return 0;
}