X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=test%2Ftstodr.c;h=8aa01549aa4c3ec924633cba8cee7dfed77782fa;hp=33d366bbbae34c387f69db29218e7025980113ea;hb=29b3b3213c4c8ad38bab054b56f8b70f1b14d67a;hpb=fb6d99a0c7e07d9cc4a315c447deaf6564a85505 diff --git a/test/tstodr.c b/test/tstodr.c index 33d366b..8aa0154 100644 --- a/test/tstodr.c +++ b/test/tstodr.c @@ -1,28 +1,28 @@ -/* - * Copyright (C) 1995-2005, Index Data ApS +/* This file is part of the YAZ toolkit. + * Copyright (C) 1995-2009 Index Data * See the file LICENSE for details. - * - * $Id: tstodr.c,v 1.6 2005-06-25 15:46:07 adam Exp $ - * */ #include #include -#include -#include +#include #include "tstodrcodec.h" +#include + #define MYOID "1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19" void tst_MySequence1(ODR encode, ODR decode) { + int ret; char *ber_buf; int ber_len; - Yc_MySequence *s = odr_malloc(encode, sizeof(*s)); + Yc_MySequence *s = (Yc_MySequence *) odr_malloc(encode, sizeof(*s)); Yc_MySequence *t; + YAZ_CHECK(s); s->first = odr_intdup(encode, 12345); - s->second = odr_malloc(encode, sizeof(*s->second)); - s->second->buf = "hello"; + s->second = (Odr_oct *) odr_malloc(encode, sizeof(*s->second)); + s->second->buf = (unsigned char *) "hello"; s->second->len = 5; s->second->size = 0; s->third = odr_intdup(encode, 1); @@ -31,47 +31,53 @@ void tst_MySequence1(ODR encode, ODR decode) s->myoid = odr_getoidbystr(decode, MYOID); - if (!yc_MySequence(encode, &s, 0, 0)) - exit(1); + ret = yc_MySequence(encode, &s, 0, 0); + YAZ_CHECK(ret); + if (!ret) + return; ber_buf = odr_getbuf(encode, &ber_len, 0); odr_setbuf(decode, ber_buf, ber_len, 0); - if (!yc_MySequence(decode, &t, 0, 0)) - exit(2); - if (!t->first || *t->first != 12345) - exit(3); - if (!t->second || !t->second->buf || t->second->len != 5) - exit(4); - if (memcmp(t->second->buf, "hello", t->second->len)) - exit(5); - if (!t->third || *t->third != 1) - exit(6); - if (!t->fourth) - exit(7); - if (!t->fifth || *t->fifth != YC_MySequence_enum1) - exit(8); - if (!t->myoid) - exit(9); - else + ret = yc_MySequence(decode, &t, 0, 0); + YAZ_CHECK(ret); + if (!ret) + return; + + YAZ_CHECK(t); + + YAZ_CHECK(t->first && *t->first == 12345); + + YAZ_CHECK(t->second && t->second->buf && t->second->len == 5); + + YAZ_CHECK(t->second && t->second->buf && t->second->len == 5 && + memcmp(t->second->buf, "hello", t->second->len) == 0); + + YAZ_CHECK(t->third && *t->third == 1); + + YAZ_CHECK(t->fourth); + + YAZ_CHECK(t->fifth && *t->fifth == YC_MySequence_enum1); + + YAZ_CHECK(t->myoid); + if (t->myoid) { - int *myoid = odr_getoidbystr(decode, MYOID); - struct oident *oident; + Odr_oid *myoid = odr_getoidbystr(decode, MYOID); - if (oid_oidcmp(myoid, t->myoid)) - exit(10); - oident = oid_getentbyoid(t->myoid); + YAZ_CHECK(oid_oidcmp(myoid, t->myoid) == 0); } } void tst_MySequence2(ODR encode, ODR decode) { - Yc_MySequence *s = odr_malloc(encode, sizeof(*s)); + int ret; + Yc_MySequence *s = (Yc_MySequence *) odr_malloc(encode, sizeof(*s)); + YAZ_CHECK(s); s->first = 0; /* deliberately miss this .. */ - s->second = odr_malloc(encode, sizeof(*s->second)); - s->second->buf = "hello"; + s->second = (Odr_oct *) odr_malloc(encode, sizeof(*s->second)); + s->second->buf = (unsigned char *) "hello"; s->second->len = 5; s->second->size = 0; s->third = odr_intdup(encode, 1); @@ -79,18 +85,17 @@ void tst_MySequence2(ODR encode, ODR decode) s->fifth = odr_intdup(encode, YC_MySequence_enum1); s->myoid = odr_getoidbystr(encode, MYOID); - if (yc_MySequence(encode, &s, 0, 0)) /* should fail */ - exit(9); - if (odr_geterror(encode) != OREQUIRED) - exit(10); - if (strcmp(odr_getelement(encode), "first")) - exit(11); + ret = yc_MySequence(encode, &s, 0, 0); /* should fail */ + YAZ_CHECK(!ret); + + YAZ_CHECK(odr_geterror(encode) == OREQUIRED); + + YAZ_CHECK(strcmp(odr_getelement(encode), "first") == 0); odr_reset(encode); - if (odr_geterror(encode) != ONONE) - exit(12); - if (strcmp(odr_getelement(encode), "")) - exit(13); + YAZ_CHECK(odr_geterror(encode) == ONONE); + + YAZ_CHECK(strcmp(odr_getelement(encode), "") == 0); } void tst_MySequence3(ODR encode, ODR decode) @@ -115,22 +120,33 @@ void tst_MySequence3(ODR encode, ODR decode) } } -int main(int argc, char **argv) +static void tst(void) { ODR odr_encode = odr_createmem(ODR_ENCODE); ODR odr_decode = odr_createmem(ODR_DECODE); + YAZ_CHECK(odr_encode); + YAZ_CHECK(odr_decode); + tst_MySequence1(odr_encode, odr_decode); tst_MySequence2(odr_encode, odr_decode); tst_MySequence3(odr_encode, odr_decode); odr_destroy(odr_encode); odr_destroy(odr_decode); - exit(0); } + +int main(int argc, char **argv) +{ + YAZ_CHECK_INIT(argc, argv); + tst(); + YAZ_CHECK_TERM; +} + /* * Local variables: * c-basic-offset: 4 + * c-file-style: "Stroustrup" * indent-tabs-mode: nil * End: * vim: shiftwidth=4 tabstop=8 expandtab