aboutsummaryrefslogtreecommitdiffstats
path: root/asn1c/tests/check-src/check-131.-gen-PER.c
blob: 7cc744f48657c76f2f137a036824bec2ca934937 (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
#undef	NDEBUG
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <string.h>
#include <assert.h>

#include "T.h"
#include "per_opentype.h"

int
main() {
	asn_per_data_t pd;
	asn_per_outp_t po;
	asn_dec_rval_t rv;
	T_t t;
	T_t *t2 = 0;
	size_t i;

	memset(&po, 0, sizeof po);
	po.buffer = po.tmpspace;
	po.nbits = sizeof(po.tmpspace) * 8;

	memset(&t, 0, sizeof t);

	printf("Checking uper_open_type_put():\n");
	assert(0 == uper_open_type_put(&asn_DEF_T, 0, &t, &po));
	assert(po.nbits == (-1 + sizeof(po.tmpspace)) * 8);
	printf("po{nboff=%zd; nbits=%zd; buffer=%p; tmpspace=%p}\n",
		po.nboff, po.nbits, po.buffer, po.tmpspace);
	/* One byte length and one byte 0x00 */
	assert(    (po.nboff == 8 && po.buffer == &po.tmpspace[1])
		|| (po.nboff == 0 && po.buffer == &po.tmpspace[2]));
	assert(po.tmpspace[0] == 0x01);
	assert(po.tmpspace[1] == 0x00);

	printf("\nChecking uper_open_type_get():\n");
	for(i = 0; i < 16; i++) {
		FREEMEM(t2); t2 = 0;
		memset(&pd, 0, sizeof pd);
		pd.buffer = po.tmpspace;
		pd.nboff = 0;
		pd.nbits = i;
		rv = uper_open_type_get(0, &asn_DEF_T, 0, (void **)&t2, &pd);
		assert(rv.code == RC_WMORE);
	}

	memset(&pd, 0, sizeof pd);
	pd.buffer = po.tmpspace;
	pd.nboff = 0;
	pd.nbits = 16;
	rv = uper_open_type_get(0, &asn_DEF_T, 0, (void **)&t2, &pd);
	assert(rv.code == RC_OK);
	assert(    (pd.nboff == 8 && pd.buffer == &po.tmpspace[1])
		|| (pd.nboff == 16 && pd.buffer == &po.tmpspace[0]));
	assert(pd.nboff + pd.nbits == 16);

	return 0;
}