From: Adam Dickmeiss Date: Tue, 30 Apr 2013 09:25:15 +0000 (+0200) Subject: New test: test_zgdu X-Git-Tag: v4.2.57~13 X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=commitdiff_plain;h=a7f066f298c283530e1e542c87858b28d594238b;hp=1770f18530a45da520e9b47fedee3203d01e04af New test: test_zgdu Mostly to demonstrate how to decode HTTP response from a memory buffer. --- diff --git a/test/.gitignore b/test/.gitignore index 43f14b5..e93ecbd 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -42,6 +42,7 @@ test_libstemmer test_rpn2solr test_shared_ptr test_solr +test_zgdu *.log *.o *~ diff --git a/test/Makefile.am b/test/Makefile.am index 7800bee..163f09f 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -11,7 +11,7 @@ check_PROGRAMS = test_ccl test_comstack test_cql2ccl \ test_record_conv test_rpn2cql test_rpn2solr test_retrieval \ test_shared_ptr test_soap1 test_soap2 test_solr test_sortspec \ test_timing test_tpath test_wrbuf \ - test_xmalloc test_xml_include test_xmlquery + test_xmalloc test_xml_include test_xmlquery test_zgdu check_SCRIPTS = test_marc.sh test_marccol.sh test_cql2xcql.sh \ test_cql2pqf.sh test_icu.sh @@ -98,3 +98,4 @@ test_file_glob_SOURCES = test_file_glob.c test_shared_ptr_SOURCES = test_shared_ptr.c test_libstemmer_SOURCES = test_libstemmer.c test_embed_record_SOURCES = test_embed_record.c +test_zgdu_SOURCES = test_zgdu.c diff --git a/test/test_zgdu.c b/test/test_zgdu.c new file mode 100644 index 0000000..4298d3e --- /dev/null +++ b/test/test_zgdu.c @@ -0,0 +1,60 @@ +/* This file is part of the YAZ toolkit. + * Copyright (C) 1995-2013 Index Data + * See the file LICENSE for details. + */ +#if HAVE_CONFIG_H +#include +#endif + +#include +#include +#include + +#include +#include +#include +#include + +static void tst_http_response(void) +{ + { + /* response, content */ + const char *http_buf = + /*123456789012345678 */ + "HTTP/1.1 200 OK\r\n" + "Content-Length: 2\r\n" + "\r\n" + "12"; + + int r; + Z_GDU *zgdu; + ODR odr = odr_createmem(ODR_DECODE); + odr_setbuf(odr, (char *) http_buf, strlen(http_buf), 0); + r = z_GDU(odr, &zgdu, 0, 0); + YAZ_CHECK(r); + if (r) + { + YAZ_CHECK_EQ(zgdu->which, Z_GDU_HTTP_Response); + } + odr_destroy(odr); + } +} + + +int main (int argc, char **argv) +{ + YAZ_CHECK_INIT(argc, argv); + YAZ_CHECK_LOG(); + tst_http_response(); + YAZ_CHECK_TERM; +} + +/* + * Local variables: + * c-basic-offset: 4 + * c-file-style: "Stroustrup" + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ +