2 * Copyright (C) 1995-2005, Index Data ApS
3 * See the file LICENSE for details.
5 * $Id: tstodr.c,v 1.5 2005-05-26 21:47:16 adam Exp $
12 #include "tstodrcodec.h"
14 #define MYOID "1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19"
16 void tst_MySequence1(ODR encode, ODR decode)
20 Yc_MySequence *s = odr_malloc(encode, sizeof(*s));
23 s->first = odr_intdup(encode, 12345);
24 s->second = odr_malloc(encode, sizeof(*s->second));
25 s->second->buf = "hello";
28 s->third = odr_intdup(encode, 1);
29 s->fourth = odr_nullval();
30 s->fifth = odr_intdup(encode, YC_MySequence_enum1);
32 s->myoid = odr_getoidbystr(decode, MYOID);
34 if (!yc_MySequence(encode, &s, 0, 0))
37 ber_buf = odr_getbuf(encode, &ber_len, 0);
39 odr_setbuf(decode, ber_buf, ber_len, 0);
41 if (!yc_MySequence(decode, &t, 0, 0))
43 if (!t->first || *t->first != 12345)
45 if (!t->second || !t->second->buf || t->second->len != 5)
47 if (memcmp(t->second->buf, "hello", t->second->len))
49 if (!t->third || *t->third != 1)
53 if (!t->fifth || *t->fifth != YC_MySequence_enum1)
59 int *myoid = odr_getoidbystr(decode, MYOID);
60 struct oident *oident;
62 if (oid_oidcmp(myoid, t->myoid))
64 oident = oid_getentbyoid(t->myoid);
68 void tst_MySequence2(ODR encode, ODR decode)
70 Yc_MySequence *s = odr_malloc(encode, sizeof(*s));
72 s->first = 0; /* deliberately miss this .. */
73 s->second = odr_malloc(encode, sizeof(*s->second));
74 s->second->buf = "hello";
77 s->third = odr_intdup(encode, 1);
78 s->fourth = odr_nullval();
79 s->fifth = odr_intdup(encode, YC_MySequence_enum1);
80 s->myoid = odr_getoidbystr(encode, MYOID);
82 if (yc_MySequence(encode, &s, 0, 0)) /* should fail */
84 if (odr_geterror(encode) != OREQUIRED)
86 if (strcmp(odr_getelement(encode), "first"))
90 if (odr_geterror(encode) != ONONE)
92 if (strcmp(odr_getelement(encode), ""))
96 void tst_MySequence3(ODR encode, ODR decode)
103 for (i = 0; i<1000; i++)
106 for (j = 0; j<sizeof(buf); j++)
109 for (j = 1; j<sizeof(buf); j++)
111 odr_setbuf(decode, buf, j, 0);
112 yc_MySequence(decode, &t, 0, 0);
118 int main(int argc, char **argv)
120 ODR odr_encode = odr_createmem(ODR_ENCODE);
121 ODR odr_decode = odr_createmem(ODR_DECODE);
123 tst_MySequence1(odr_encode, odr_decode);
124 tst_MySequence2(odr_encode, odr_decode);
125 tst_MySequence3(odr_encode, odr_decode);
127 odr_destroy(odr_encode);
128 odr_destroy(odr_decode);