X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=test%2Ftest_comstack.c;h=381ecb88f79dbbe54e8a9d635046f75997f90e51;hp=0e5233d820210b5b3981fa73aa3eb2c8f1906826;hb=2a624ff1daa841601aebca86c0196039da6978b3;hpb=6e0314cce5d9c3d346d4d968a7ea07f92d8761b1 diff --git a/test/test_comstack.c b/test/test_comstack.c index 0e5233d..381ecb8 100644 --- a/test/test_comstack.c +++ b/test/test_comstack.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 @@ -223,18 +223,23 @@ static int comstack_example(const char *server_address_str) } server_address_ip = cs_straddr(stack, server_address_str); - if (!server_address_ip) - { + if (!server_address_ip) { fprintf(stderr, "cs_straddr: address could not be resolved\n"); return -1; } status = cs_connect(stack, server_address_ip); - if (status != 0) { + if (status) { fprintf(stderr, "cs_connect: %s\n", cs_strerror(stack)); return -1; } + status = cs_rcvconnect(stack); + if (status) { + fprintf(stderr, "cs_rcvconnect: %s\n", cs_strerror(stack)); + return -1; + } + status = cs_put(stack, protocol_package, protocol_package_length); if (status) { fprintf(stderr, "cs_put: %s\n", cs_strerror(stack)); @@ -242,7 +247,6 @@ static int comstack_example(const char *server_address_str) } /* Now get a response */ - length_incoming = cs_get(stack, &buf, &size); if (!length_incoming) { fprintf(stderr, "Connection closed\n"); @@ -258,10 +262,37 @@ static int comstack_example(const char *server_address_str) /* clean up */ cs_close(stack); if (buf) - free(buf); + xfree(buf); return 0; } +static void tst_cs_get_host_args(void) +{ + const char *arg = 0; + + cs_get_host_args("http://localhost:9999", &arg); + YAZ_CHECK(arg && !strcmp(arg, "")); + cs_get_host_args("http://localhost:9999/x", &arg); + YAZ_CHECK(arg && !strcmp(arg, "x")); + cs_get_host_args("http://localhost:9999?x", &arg); + YAZ_CHECK(arg && !strcmp(arg, "")); + cs_get_host_args("localhost:9999", &arg); + YAZ_CHECK(arg && !strcmp(arg, "")); + cs_get_host_args("localhost:9999/", &arg); + YAZ_CHECK(arg && !strcmp(arg, "")); + cs_get_host_args("localhost:9999/x&url=http://some.host", &arg); + YAZ_CHECK(arg && !strcmp(arg, "x&url=http://some.host")); + cs_get_host_args("http://localhost:9999/x&url=http://some.host", &arg); + YAZ_CHECK(arg && !strcmp(arg, "x&url=http://some.host")); + cs_get_host_args("http:/localhost:9999/x", &arg); + YAZ_CHECK(arg && !strcmp(arg, "localhost:9999/x")); + cs_get_host_args("http//localhost:9999/x", &arg); + YAZ_CHECK(arg && !strcmp(arg, "/localhost:9999/x")); + cs_get_host_args("http://y/x", &arg); + YAZ_CHECK(arg && !strcmp(arg, "x")); + cs_get_host_args("http:///x", &arg); + YAZ_CHECK(arg && !strcmp(arg, "x")); +} int main (int argc, char **argv) { @@ -271,6 +302,7 @@ int main (int argc, char **argv) comstack_example(argv[1]); tst_http_request(); tst_http_response(); + tst_cs_get_host_args(); YAZ_CHECK_TERM; }