2 * Copyright (C) 1995-2007, Index Data ApS
3 * See the file LICENSE for details.
5 * $Id: tstodr.c,v 1.9 2007-01-03 08:42:16 adam Exp $
12 #include "tstodrcodec.h"
16 #define MYOID "1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19"
18 void tst_MySequence1(ODR encode, ODR decode)
23 Yc_MySequence *s = odr_malloc(encode, sizeof(*s));
27 s->first = odr_intdup(encode, 12345);
28 s->second = odr_malloc(encode, sizeof(*s->second));
29 s->second->buf = (unsigned char *) "hello";
32 s->third = odr_intdup(encode, 1);
33 s->fourth = odr_nullval();
34 s->fifth = odr_intdup(encode, YC_MySequence_enum1);
36 s->myoid = odr_getoidbystr(decode, MYOID);
38 ret = yc_MySequence(encode, &s, 0, 0);
43 ber_buf = odr_getbuf(encode, &ber_len, 0);
45 odr_setbuf(decode, ber_buf, ber_len, 0);
47 ret = yc_MySequence(decode, &t, 0, 0);
54 YAZ_CHECK(t->first && *t->first == 12345);
56 YAZ_CHECK(t->second && t->second->buf && t->second->len == 5);
58 YAZ_CHECK(t->second && t->second->buf && t->second->len == 5 &&
59 memcmp(t->second->buf, "hello", t->second->len) == 0);
61 YAZ_CHECK(t->third && *t->third == 1);
65 YAZ_CHECK(t->fifth && *t->fifth == YC_MySequence_enum1);
70 int *myoid = odr_getoidbystr(decode, MYOID);
72 YAZ_CHECK(oid_oidcmp(myoid, t->myoid) == 0);
76 void tst_MySequence2(ODR encode, ODR decode)
79 Yc_MySequence *s = odr_malloc(encode, sizeof(*s));
82 s->first = 0; /* deliberately miss this .. */
83 s->second = odr_malloc(encode, sizeof(*s->second));
84 s->second->buf = (unsigned char *) "hello";
87 s->third = odr_intdup(encode, 1);
88 s->fourth = odr_nullval();
89 s->fifth = odr_intdup(encode, YC_MySequence_enum1);
90 s->myoid = odr_getoidbystr(encode, MYOID);
92 ret = yc_MySequence(encode, &s, 0, 0); /* should fail */
95 YAZ_CHECK(odr_geterror(encode) == OREQUIRED);
97 YAZ_CHECK(strcmp(odr_getelement(encode), "first") == 0);
100 YAZ_CHECK(odr_geterror(encode) == ONONE);
102 YAZ_CHECK(strcmp(odr_getelement(encode), "") == 0);
105 void tst_MySequence3(ODR encode, ODR decode)
112 for (i = 0; i<1000; i++)
115 for (j = 0; j<sizeof(buf); j++)
118 for (j = 1; j<sizeof(buf); j++)
120 odr_setbuf(decode, buf, j, 0);
121 yc_MySequence(decode, &t, 0, 0);
127 static void tst(void)
129 ODR odr_encode = odr_createmem(ODR_ENCODE);
130 ODR odr_decode = odr_createmem(ODR_DECODE);
132 YAZ_CHECK(odr_encode);
133 YAZ_CHECK(odr_decode);
135 tst_MySequence1(odr_encode, odr_decode);
136 tst_MySequence2(odr_encode, odr_decode);
137 tst_MySequence3(odr_encode, odr_decode);
139 odr_destroy(odr_encode);
140 odr_destroy(odr_decode);
143 int main(int argc, char **argv)
145 YAZ_CHECK_INIT(argc, argv);
153 * indent-tabs-mode: nil
155 * vim: shiftwidth=4 tabstop=8 expandtab