blob: f7c283544921740c81ce9b93a1d8defd001a80b8 [file] [log] [blame]
Lev Walkined54c592004-06-06 07:22:03 +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
8#include <T.h>
9
10uint8_t buf1[] = {
11 32 | ((3 << 6) + 1), /* [PRIVATE 1], constructed */
12 4, /* L */
13 ((3 << 6) + 2), /* [PRIVATE 2], primitive */
14 0, /* L */
15 ((3 << 6) + 5), /* [PRIVATE 5], primitive */
16 0, /* L */
17};
18
19uint8_t buf2[] = {
20 32 | ((3 << 6) + 1), /* [PRIVATE 1], constructed */
21 6, /* L */
22 ((3 << 6) + 2), /* [PRIVATE 2], primitive */
23 0, /* L */
24 32 | ((3 << 6) + 9), /* [PRIVATE 9], constructed */
25 2,
26 ((3 << 6) + 1), /* [PRIVATE 1], primitive */
27 0, /* L */
28};
29
30static void
Lev Walkin1715b322013-03-28 04:02:13 -070031check(int is_ok, uint8_t *buf, size_t size, size_t consumed) {
Lev Walkined54c592004-06-06 07:22:03 +000032 T_t t, *tp;
Lev Walkin90bf7ae2004-10-20 15:46:56 +000033 asn_dec_rval_t rval;
Lev Walkined54c592004-06-06 07:22:03 +000034
35 tp = memset(&t, 0, sizeof(t));
36
37 fprintf(stderr, "Buf %p\n", buf);
Lev Walkinc7400c52004-09-29 13:14:36 +000038 rval = ber_decode(0, &asn_DEF_T, (void **)&tp, buf, size);
Lev Walkin1715b322013-03-28 04:02:13 -070039 fprintf(stderr, "Returned code %d, consumed %zd\n",
40 (int)rval.code, rval.consumed);
Lev Walkined54c592004-06-06 07:22:03 +000041
42 if(is_ok) {
43 assert(rval.code == RC_OK);
44 assert(rval.consumed == consumed);
45 } else {
46 if(rval.code == RC_OK) {
47 }
48 assert(rval.consumed <= consumed);
49 }
50}
51
52int
53main(int ac, char **av) {
54
55 (void)ac; /* Unused argument */
56 (void)av; /* Unused argument */
57
58 check(1, buf1, sizeof(buf1), sizeof(buf1));
59 check(0, buf1, sizeof(buf1) - 1, sizeof(buf1) - 1);
60 check(0, buf1, sizeof(buf1) - 2, sizeof(buf1) - 2);
61
62 check(1, buf2, sizeof(buf2), sizeof(buf2));
63 check(0, buf2, sizeof(buf2) - 1, sizeof(buf2));
64
65 return 0;
66}