2 * Copyright (C) 1995-2005, Index Data ApS
3 * See the file LICENSE for details.
5 * $Id: tstodr.c,v 1.4 2005-02-01 17:23:36 adam Exp $
11 #include "tstodrcodec.h"
13 void tst_MySequence1(ODR encode, ODR decode)
17 Yc_MySequence *s = odr_malloc(encode, sizeof(*s));
20 s->first = odr_intdup(encode, 12345);
21 s->second = odr_malloc(encode, sizeof(*s->second));
22 s->second->buf = "hello";
25 s->third = odr_intdup(encode, 1);
26 s->fourth = odr_nullval();
27 s->fifth = odr_intdup(encode, YC_MySequence_enum1);
29 if (!yc_MySequence(encode, &s, 0, 0))
32 ber_buf = odr_getbuf(encode, &ber_len, 0);
34 odr_setbuf(decode, ber_buf, ber_len, 0);
36 if (!yc_MySequence(decode, &t, 0, 0))
38 if (!t->first || *t->first != 12345)
40 if (!t->second || !t->second->buf || t->second->len != 5)
42 if (memcmp(t->second->buf, "hello", t->second->len))
44 if (!t->third || *t->third != 1)
48 if (!t->fifth || *t->fifth != YC_MySequence_enum1)
52 void tst_MySequence2(ODR encode, ODR decode)
54 Yc_MySequence *s = odr_malloc(encode, sizeof(*s));
56 s->first = 0; /* deliberately miss this .. */
57 s->second = odr_malloc(encode, sizeof(*s->second));
58 s->second->buf = "hello";
61 s->third = odr_intdup(encode, 1);
62 s->fourth = odr_nullval();
63 s->fifth = odr_intdup(encode, YC_MySequence_enum1);
65 if (yc_MySequence(encode, &s, 0, 0)) /* should fail */
67 if (odr_geterror(encode) != OREQUIRED)
69 if (strcmp(odr_getelement(encode), "first"))
73 if (odr_geterror(encode) != ONONE)
75 if (strcmp(odr_getelement(encode), ""))
79 void tst_MySequence3(ODR encode, ODR decode)
86 for (i = 0; i<1000; i++)
89 for (j = 0; j<sizeof(buf); j++)
92 for (j = 1; j<sizeof(buf); j++)
94 odr_setbuf(decode, buf, j, 0);
95 yc_MySequence(decode, &t, 0, 0);
101 int main(int argc, char **argv)
103 ODR odr_encode = odr_createmem(ODR_ENCODE);
104 ODR odr_decode = odr_createmem(ODR_DECODE);
106 tst_MySequence1(odr_encode, odr_decode);
107 tst_MySequence2(odr_encode, odr_decode);
108 tst_MySequence3(odr_encode, odr_decode);
110 odr_destroy(odr_encode);
111 odr_destroy(odr_decode);