2 * Copyright (C) 1995-2005, Index Data ApS
3 * See the file LICENSE for details.
5 * $Id: tstodr.c,v 1.3 2005-01-15 19:47:15 adam Exp $
10 #include "tstodrcodec.h"
12 void tst_MySequence1(ODR encode, ODR decode)
16 Yc_MySequence *s = odr_malloc(encode, sizeof(*s));
19 s->first = odr_intdup(encode, 12345);
20 s->second = odr_malloc(encode, sizeof(*s->second));
21 s->second->buf = "hello";
24 s->third = odr_intdup(encode, 1);
25 s->fourth = odr_nullval();
26 s->fifth = odr_intdup(encode, YC_MySequence_enum1);
28 if (!yc_MySequence(encode, &s, 0, 0))
31 ber_buf = odr_getbuf(encode, &ber_len, 0);
33 odr_setbuf(decode, ber_buf, ber_len, 0);
35 if (!yc_MySequence(decode, &t, 0, 0))
37 if (!t->first || *t->first != 12345)
39 if (!t->second || !t->second->buf || t->second->len != 5)
41 if (memcmp(t->second->buf, "hello", t->second->len))
43 if (!t->third || *t->third != 1)
47 if (!t->fifth || *t->fifth != YC_MySequence_enum1)
51 void tst_MySequence2(ODR encode, ODR decode)
53 Yc_MySequence *s = odr_malloc(encode, sizeof(*s));
55 s->first = 0; /* deliberately miss this .. */
56 s->second = odr_malloc(encode, sizeof(*s->second));
57 s->second->buf = "hello";
60 s->third = odr_intdup(encode, 1);
61 s->fourth = odr_nullval();
62 s->fifth = odr_intdup(encode, YC_MySequence_enum1);
64 if (yc_MySequence(encode, &s, 0, 0)) /* should fail */
66 if (odr_geterror(encode) != OREQUIRED)
68 if (strcmp(odr_getelement(encode), "first"))
72 if (odr_geterror(encode) != ONONE)
74 if (strcmp(odr_getelement(encode), ""))
78 void tst_MySequence3(ODR encode, ODR decode)
85 for (i = 0; i<1000; i++)
88 for (j = 0; j<sizeof(buf); j++)
91 for (j = 1; j<sizeof(buf); j++)
93 odr_setbuf(decode, buf, j, 0);
94 yc_MySequence(decode, &t, 0, 0);
100 int main(int argc, char **argv)
102 ODR odr_encode = odr_createmem(ODR_ENCODE);
103 ODR odr_decode = odr_createmem(ODR_DECODE);
105 tst_MySequence1(odr_encode, odr_decode);
106 tst_MySequence2(odr_encode, odr_decode);
107 tst_MySequence3(odr_encode, odr_decode);
109 odr_destroy(odr_encode);
110 odr_destroy(odr_decode);