From 8f7c9a27753894afb11d443b1c58419d81251bd1 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Wed, 8 May 2013 16:27:21 +0200 Subject: [PATCH] Add check for content_length stuff --- test/test_zgdu.c | 54 +++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 17 deletions(-) diff --git a/test/test_zgdu.c b/test/test_zgdu.c index 4298d3e..6a1db0f 100644 --- a/test/test_zgdu.c +++ b/test/test_zgdu.c @@ -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); } -- 1.7.10.4