X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=test%2Ftstodr.c;h=a16251bd4f38a451190b8589f09f44c0bca1dcbc;hp=8ba386de895ef5ac0c0b473aa997b7448b16719b;hb=69c2dee55aa204cab368989b8385eda8b83bf2e2;hpb=2788a4851b551e1a3efb320a2878b809f2d8a9d7 diff --git a/test/tstodr.c b/test/tstodr.c index 8ba386d..a16251b 100644 --- a/test/tstodr.c +++ b/test/tstodr.c @@ -25,7 +25,7 @@ void tst_MySequence1(ODR encode, ODR decode) 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); @@ -80,7 +80,7 @@ void tst_MySequence2(ODR encode, ODR decode) 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); @@ -136,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); @@ -146,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