2 * Copyright (C) 1995-2007, Index Data ApS
3 * See the file LICENSE for details.
5 * $Id: tstodr.c,v 1.12 2007-08-13 16:23:30 mike Exp $
10 #include <yaz/oid_util.h>
11 #include "tstodrcodec.h"
15 #define MYOID "1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19"
17 void tst_MySequence1(ODR encode, ODR decode)
22 Yc_MySequence *s = odr_malloc(encode, sizeof(*s));
26 s->first = odr_intdup(encode, 12345);
27 s->second = odr_malloc(encode, sizeof(*s->second));
28 s->second->buf = (unsigned char *) "hello";
31 s->third = odr_intdup(encode, 1);
32 s->fourth = odr_nullval();
33 s->fifth = odr_intdup(encode, YC_MySequence_enum1);
35 s->myoid = odr_getoidbystr(decode, MYOID);
37 ret = yc_MySequence(encode, &s, 0, 0);
42 ber_buf = odr_getbuf(encode, &ber_len, 0);
44 odr_setbuf(decode, ber_buf, ber_len, 0);
46 ret = yc_MySequence(decode, &t, 0, 0);
53 YAZ_CHECK(t->first && *t->first == 12345);
55 YAZ_CHECK(t->second && t->second->buf && t->second->len == 5);
57 YAZ_CHECK(t->second && t->second->buf && t->second->len == 5 &&
58 memcmp(t->second->buf, "hello", t->second->len) == 0);
60 YAZ_CHECK(t->third && *t->third == 1);
64 YAZ_CHECK(t->fifth && *t->fifth == YC_MySequence_enum1);
69 Odr_oid *myoid = odr_getoidbystr(decode, MYOID);
71 YAZ_CHECK(oid_oidcmp(myoid, t->myoid) == 0);
75 void tst_MySequence2(ODR encode, ODR decode)
78 Yc_MySequence *s = odr_malloc(encode, sizeof(*s));
81 s->first = 0; /* deliberately miss this .. */
82 s->second = odr_malloc(encode, sizeof(*s->second));
83 s->second->buf = (unsigned char *) "hello";
86 s->third = odr_intdup(encode, 1);
87 s->fourth = odr_nullval();
88 s->fifth = odr_intdup(encode, YC_MySequence_enum1);
89 s->myoid = odr_getoidbystr(encode, MYOID);
91 ret = yc_MySequence(encode, &s, 0, 0); /* should fail */
94 YAZ_CHECK(odr_geterror(encode) == OREQUIRED);
96 YAZ_CHECK(strcmp(odr_getelement(encode), "first") == 0);
99 YAZ_CHECK(odr_geterror(encode) == ONONE);
101 YAZ_CHECK(strcmp(odr_getelement(encode), "") == 0);
104 void tst_MySequence3(ODR encode, ODR decode)
111 for (i = 0; i<1000; i++)
114 for (j = 0; j<sizeof(buf); j++)
117 for (j = 1; j<sizeof(buf); j++)
119 odr_setbuf(decode, buf, j, 0);
120 yc_MySequence(decode, &t, 0, 0);
126 static void tst(void)
128 ODR odr_encode = odr_createmem(ODR_ENCODE);
129 ODR odr_decode = odr_createmem(ODR_DECODE);
131 YAZ_CHECK(odr_encode);
132 YAZ_CHECK(odr_decode);
134 tst_MySequence1(odr_encode, odr_decode);
135 tst_MySequence2(odr_encode, odr_decode);
136 tst_MySequence3(odr_encode, odr_decode);
138 odr_destroy(odr_encode);
139 odr_destroy(odr_decode);
142 int main(int argc, char **argv)
144 YAZ_CHECK_INIT(argc, argv);
152 * indent-tabs-mode: nil
154 * vim: shiftwidth=4 tabstop=8 expandtab