commit f98a7bfd3952944b56fbfb0aef1531472d4c2354 Author: Jeff Garzik <jeff@xxxxxxxxxx> Date: Sun Mar 7 07:58:25 2010 -0500 [test] add new hdr-content-type test Verifies that user-provided Content-type header is stored and returned on subsequent GET requests. Signed-off-by: Jeff Garzik <jgarzik@xxxxxxxxxx> diff --git a/test/.gitignore b/test/.gitignore index c99d4e2..26ba541 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -5,4 +5,5 @@ basic-object it-works large-object wait-for-listen +hdr-content-type diff --git a/test/Makefile.am b/test/Makefile.am index 2e18349..62b279e 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -24,11 +24,12 @@ TESTS = \ basic-bucket \ basic-object \ large-object \ + hdr-content-type \ stop-daemon \ clean-db check_PROGRAMS = basic-bucket basic-object it-works large-object \ - wait-for-listen + hdr-content-type wait-for-listen TESTLDADD = ../lib/libhttpstor.la \ ../lib/libhttputil.a \ @@ -36,6 +37,7 @@ TESTLDADD = ../lib/libhttpstor.la \ basic_bucket_LDADD = $(TESTLDADD) basic_object_LDADD = $(TESTLDADD) large_object_LDADD = $(TESTLDADD) +hdr_content_type_LDADD = $(TESTLDADD) it_works_LDADD = $(TESTLDADD) wait_for_listen_LDADD = ../lib/libhttputil.a diff --git a/test/hdr-content-type.c b/test/hdr-content-type.c new file mode 100644 index 0000000..0fc3641 --- /dev/null +++ b/test/hdr-content-type.c @@ -0,0 +1,130 @@ + +/* + * Copyright 2008-2009 Red Hat, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ +/* + * A large object test verifies the workings of bizarrely complicated and + * subtle mechanics of the sliding windows and flow control when tabled + * pipes the data between its client and the back-end chunkservers. + * As such, we have to defend against hungs as well as corruption. + */ + +#define _GNU_SOURCE +#include "tabled-config.h" + +#include <stdbool.h> +#include <string.h> +#include <stdlib.h> +#include <ctype.h> +#include <locale.h> +#include <httpstor.h> +#include <httputil.h> +#include "test.h" + +static char bucket[] = "test-hdr-ctt"; +static char key[] = "Key of HDR ctt test"; +static char value[] = "Value of HDR ctt test"; + +static char *user_hdrs[] = { + "Content-type: text/x-tabled-test", + NULL +}; + +static bool find_our_hdr(const void *data, size_t data_len) +{ + const void *p = data; + size_t len = data_len; + + while (len > 0) { + void *eol; + size_t llen, real_len; + const char *s; + + eol = memchr(p, '\n', len); + if (!eol) + llen = len; + else + llen = eol - p + 1; + + real_len = llen; + s = p; + while (real_len > 0) { + if (!isspace(s[real_len - 1])) + break; + + real_len--; + } + + if (!strncasecmp(user_hdrs[0], p, real_len)) + return true; + + p += llen; + len -= llen; + } + + return false; +} + +static void runtest(struct httpstor_client *httpstor) +{ + bool rcb; + void *data = NULL; + size_t data_len = 0; + + rcb = httpstor_put_inline(httpstor, bucket, key, + value, strlen(value) + 1, user_hdrs); + OK(rcb); + + data = httpstor_get_inline(httpstor, bucket, key, true, &data_len); + OK(data); + OK(data_len > 0); + + rcb = find_our_hdr(data, data_len); + OK(rcb); + + free(data); +} + +int main(int argc, char *argv[]) +{ + struct httpstor_client *httpstor; + char accbuf[80]; + int rc; + bool rcb; + + setlocale(LC_ALL, "C"); + + rc = tb_readport(TEST_FILE_TB, accbuf, sizeof(accbuf)); + OK(rc > 0); + + httpstor = httpstor_new(accbuf, TEST_HOST, TEST_USER, TEST_USER_KEY); + OK(httpstor); + + /* add bucket - since tests are independent, we do not rely on others */ + rcb = httpstor_add_bucket(httpstor, bucket); + OK(rcb); + + runtest(httpstor); + + rcb = httpstor_del(httpstor, bucket, key); + OK(rcb); + + rcb = httpstor_del_bucket(httpstor, bucket); + OK(rcb); + + return 0; +} -- To unsubscribe from this list: send the line "unsubscribe hail-devel" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html