1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2008 Index Data
3 * See the file LICENSE for details.
7 #include <yaz/oid_util.h>
8 #include "tstodrcodec.h"
12 #define MYOID "1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19"
14 void tst_MySequence1(ODR encode, ODR decode)
19 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 = (unsigned char *) "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 ret = yc_MySequence(encode, &s, 0, 0);
39 ber_buf = odr_getbuf(encode, &ber_len, 0);
41 odr_setbuf(decode, ber_buf, ber_len, 0);
43 ret = yc_MySequence(decode, &t, 0, 0);
50 YAZ_CHECK(t->first && *t->first == 12345);
52 YAZ_CHECK(t->second && t->second->buf && t->second->len == 5);
54 YAZ_CHECK(t->second && t->second->buf && t->second->len == 5 &&
55 memcmp(t->second->buf, "hello", t->second->len) == 0);
57 YAZ_CHECK(t->third && *t->third == 1);
61 YAZ_CHECK(t->fifth && *t->fifth == YC_MySequence_enum1);
66 Odr_oid *myoid = odr_getoidbystr(decode, MYOID);
68 YAZ_CHECK(oid_oidcmp(myoid, t->myoid) == 0);
72 void tst_MySequence2(ODR encode, ODR decode)
75 Yc_MySequence *s = odr_malloc(encode, sizeof(*s));
78 s->first = 0; /* deliberately miss this .. */
79 s->second = odr_malloc(encode, sizeof(*s->second));
80 s->second->buf = (unsigned char *) "hello";
83 s->third = odr_intdup(encode, 1);
84 s->fourth = odr_nullval();
85 s->fifth = odr_intdup(encode, YC_MySequence_enum1);
86 s->myoid = odr_getoidbystr(encode, MYOID);
88 ret = yc_MySequence(encode, &s, 0, 0); /* should fail */
91 YAZ_CHECK(odr_geterror(encode) == OREQUIRED);
93 YAZ_CHECK(strcmp(odr_getelement(encode), "first") == 0);
96 YAZ_CHECK(odr_geterror(encode) == ONONE);
98 YAZ_CHECK(strcmp(odr_getelement(encode), "") == 0);
101 void tst_MySequence3(ODR encode, ODR decode)
108 for (i = 0; i<1000; i++)
111 for (j = 0; j<sizeof(buf); j++)
114 for (j = 1; j<sizeof(buf); j++)
116 odr_setbuf(decode, buf, j, 0);
117 yc_MySequence(decode, &t, 0, 0);
123 static void tst(void)
125 ODR odr_encode = odr_createmem(ODR_ENCODE);
126 ODR odr_decode = odr_createmem(ODR_DECODE);
128 YAZ_CHECK(odr_encode);
129 YAZ_CHECK(odr_decode);
131 tst_MySequence1(odr_encode, odr_decode);
132 tst_MySequence2(odr_encode, odr_decode);
133 tst_MySequence3(odr_encode, odr_decode);
135 odr_destroy(odr_encode);
136 odr_destroy(odr_decode);
139 int main(int argc, char **argv)
141 YAZ_CHECK_INIT(argc, argv);
149 * indent-tabs-mode: nil
151 * vim: shiftwidth=4 tabstop=8 expandtab