X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=test%2Ftest_zgdu.c;h=e18828b2d63ffb199e73da2240ab9f30ff9ee863;hp=4298d3e095d536528271e7c3434555d0e022e1b1;hb=6b3366d135740d9ab37bdcd3f00b115fedf30a9d;hpb=a7f066f298c283530e1e542c87858b28d594238b diff --git a/test/test_zgdu.c b/test/test_zgdu.c index 4298d3e..e18828b 100644 --- a/test/test_zgdu.c +++ b/test/test_zgdu.c @@ -1,5 +1,5 @@ /* This file is part of the YAZ toolkit. - * Copyright (C) 1995-2013 Index Data + * Copyright (C) Index Data * See the file LICENSE for details. */ #if HAVE_CONFIG_H @@ -17,27 +17,47 @@ 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 enc = odr_createmem(ODR_ENCODE); + ODR dec = odr_createmem(ODR_DECODE); + odr_setbuf(dec, (char *) http_buf, strlen(http_buf), 0); + r = z_GDU(dec, &zgdu, 0, 0); + YAZ_CHECK(r); + if (r) { - /* 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) + char *http_buf1; + int http_len1; + YAZ_CHECK_EQ(zgdu->which, Z_GDU_HTTP_Response); + + zgdu->u.HTTP_Response->content_len = 1; + /* we now have Content-Length=2, but content_len=1 */ + z_GDU(enc, &zgdu, 0, 0); + http_buf1 = odr_getbuf(enc, &http_len1, 0); + YAZ_CHECK(http_buf1); + if (http_buf1) { - YAZ_CHECK_EQ(zgdu->which, Z_GDU_HTTP_Response); + const char *http_buf2 = + /*123456789012345678 */ + "HTTP/1.1 200 OK\r\n" + "Content-Length: 1\r\n" /* content_len takes precedence */ + "\r\n" + "1"; + YAZ_CHECK_EQ(http_len1, strlen(http_buf2)); + YAZ_CHECK(http_len1 == strlen(http_buf2) && + memcmp(http_buf1, http_buf2, http_len1) == 0); } - odr_destroy(odr); } + odr_destroy(enc); + odr_destroy(dec); }