X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=test%2Ftstodr.c;h=a16251bd4f38a451190b8589f09f44c0bca1dcbc;hp=268224da99dc8f17882bc80e896a60d252576f96;hb=950a4ac3bd94072bb5cf880f0f411bb2c8dc80bd;hpb=06ae818deffa84ec4bc1308051ef411845dd4ce5 diff --git a/test/tstodr.c b/test/tstodr.c index 268224d..a16251b 100644 --- a/test/tstodr.c +++ b/test/tstodr.c @@ -1,14 +1,10 @@ -/* - * 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.8 2006-01-29 21:59:13 adam Exp $ - * */ #include #include -#include -#include +#include #include "tstodrcodec.h" #include @@ -20,16 +16,16 @@ 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 = (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); + s->third = odr_booldup(encode, 1); s->fourth = odr_nullval(); s->fifth = odr_intdup(encode, YC_MySequence_enum1); @@ -67,7 +63,7 @@ void tst_MySequence1(ODR encode, ODR decode) YAZ_CHECK(t->myoid); if (t->myoid) { - int *myoid = odr_getoidbystr(decode, MYOID); + Odr_oid *myoid = odr_getoidbystr(decode, MYOID); YAZ_CHECK(oid_oidcmp(myoid, t->myoid) == 0); } @@ -76,15 +72,15 @@ void tst_MySequence1(ODR encode, ODR decode) void tst_MySequence2(ODR encode, ODR decode) { int ret; - Yc_MySequence *s = odr_malloc(encode, sizeof(*s)); + 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 = (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); + s->third = odr_booldup(encode, 1); s->fourth = odr_nullval(); s->fifth = odr_intdup(encode, YC_MySequence_enum1); s->myoid = odr_getoidbystr(encode, MYOID); @@ -140,6 +136,44 @@ static void tst(void) odr_destroy(odr_decode); } +/* example from documentation.. 'Using Odr' */ +void do_nothing_useful(Odr_int value) +{ + ODR encode, decode; + Odr_int *valp, *resvalp; + char *bufferp; + int len; + + /* allocate streams */ + if (!(encode = odr_createmem(ODR_ENCODE))) + return; + if (!(decode = odr_createmem(ODR_DECODE))) + return; + + valp = &value; + if (odr_integer(encode, &valp, 0, 0) == 0) + { + printf("encoding went bad\n"); + return; + } + bufferp = odr_getbuf(encode, &len, 0); + printf("length of encoded data is %d\n", len); + + /* now let's decode the thing again */ + odr_setbuf(decode, bufferp, len, 0); + if (odr_integer(decode, &resvalp, 0, 0) == 0) + { + printf("decoding went bad\n"); + return; + } + /* ODR_INT_PRINTF format for printf (such as %d) */ + printf("the value is " ODR_INT_PRINTF "\n", *resvalp); + + /* clean up */ + odr_destroy(encode); + odr_destroy(decode); +} + int main(int argc, char **argv) { YAZ_CHECK_INIT(argc, argv); @@ -150,6 +184,7 @@ int main(int argc, char **argv) /* * Local variables: * c-basic-offset: 4 + * c-file-style: "Stroustrup" * indent-tabs-mode: nil * End: * vim: shiftwidth=4 tabstop=8 expandtab