From 873d70a6d8863346f4b70001b5a3d6d161086171 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 18 May 2011 21:48:14 +0200 Subject: tests: verify OPEN/CLOSESOCKETFUNCTION Test 585 and 586 were added. Using a modified lib500.c --- tests/data/Makefile.am | 3 +- tests/data/test585 | 69 ++++++++++++++++++++++++++++++++++++++++++++++ tests/data/test586 | 59 +++++++++++++++++++++++++++++++++++++++ tests/libtest/Makefile.inc | 5 +++- tests/libtest/lib500.c | 35 +++++++++++++++++++++++ 5 files changed, 169 insertions(+), 2 deletions(-) create mode 100644 tests/data/test585 create mode 100644 tests/data/test586 diff --git a/tests/data/Makefile.am b/tests/data/Makefile.am index ac5299714..2249394d9 100644 --- a/tests/data/Makefile.am +++ b/tests/data/Makefile.am @@ -47,7 +47,8 @@ test542 test543 test544 test545 test546 test547 test548 test549 test550 \ test551 test552 test553 test554 test555 test556 test557 test560 test561 \ test562 test563 test564 test565 test566 test567 test568 test569 test570 \ test571 test572 test573 test574 test575 test576 test578 test579 test580 \ -test581 test582 test583 test584 test600 test601 test602 test603 test604 \ +test581 test582 test583 test584 test585 test586 \ +test600 test601 test602 test603 test604 \ test605 test606 test607 test608 test609 test610 test611 test612 test613 \ test614 test615 test616 test617 test618 test619 test620 test621 test622 \ test623 test624 test625 test626 test627 test628 test629 test630 test631 \ diff --git a/tests/data/test585 b/tests/data/test585 new file mode 100644 index 000000000..32cb06fec --- /dev/null +++ b/tests/data/test585 @@ -0,0 +1,69 @@ + + + +HTTP +HTTP GET +multi +CURLOPT_OPENSOCKETFUNCTION +CURLOPT_CLOSESOCKETFUNCTION + + + +# Server-side + + +HTTP/1.1 302 eat this! +Date: Thu, 09 Nov 2010 14:49:00 GMT +Server: test-server/fake +Location: this-is-the-first.html +Content-Length: 0 +Connection: close + + + +[OPEN] counter: 1 +HTTP/1.1 302 eat this! +Date: Thu, 09 Nov 2010 14:49:00 GMT +Server: test-server/fake +Location: this-is-the-first.html +Content-Length: 0 +Connection: close + +[CLOSE] counter: 1 + + + +# Client-side + + +http + + +http + +# tool is what to use instead of 'curl' + +lib585 + + + +socket open/close callbacks + + +http://%HOSTIP:%HTTPPORT/585 + + + +# Verify data after the test has been "shot" + + +^User-Agent:.* + + +GET /585 HTTP/1.1 +Host: %HOSTIP:%HTTPPORT +Accept: */* + + + + diff --git a/tests/data/test586 b/tests/data/test586 new file mode 100644 index 000000000..c0857bdd8 --- /dev/null +++ b/tests/data/test586 @@ -0,0 +1,59 @@ + + + +FTP +PASV +CURLOPT_PORT + + +# +# Server-side + + +line 1 +line 2 +last line + + +[OPEN] counter: 1 +[OPEN] counter: 2 +line 1 +line 2 +last line +[CLOSE] counter: 2 +[CLOSE] counter: 1 + + + +# +# Client-side + + +ftp + + +lib585 + + +FTP and open/close socket callbacks + + +ftp://%HOSTIP:%FTPPORT/586 + + + +# +# Verify data after the test has been "shot" + + +USER anonymous +PASS ftp@example.com +PWD +EPSV +TYPE I +SIZE 586 +RETR 586 +QUIT + + + diff --git a/tests/libtest/Makefile.inc b/tests/libtest/Makefile.inc index a210cbfe3..06cda1e92 100644 --- a/tests/libtest/Makefile.inc +++ b/tests/libtest/Makefile.inc @@ -12,7 +12,7 @@ noinst_PROGRAMS = chkhostname \ lib579 lib529 lib530 lib532 lib533 lib536 lib537 lib540 lib541 lib542 \ lib543 lib544 lib545 lib547 lib548 lib549 lib552 lib553 lib554 lib555 \ lib556 lib539 lib557 lib560 lib562 lib564 lib565 lib566 lib567 lib568 \ - lib569 lib570 lib571 lib572 lib573 lib582 lib583 + lib569 lib570 lib571 lib572 lib573 lib582 lib583 lib585 chkhostname_SOURCES = chkhostname.c $(top_srcdir)/lib/curl_gethostname.c chkhostname_LDADD = @CURL_NETWORK_LIBS@ @@ -160,3 +160,6 @@ lib579_SOURCES = lib579.c $(SUPPORTFILES) lib582_SOURCES = lib582.c $(SUPPORTFILES) $(TESTUTIL) lib583_SOURCES = lib583.c $(SUPPORTFILES) + +lib585_SOURCES = lib500.c $(SUPPORTFILES) +lib585_CFLAGS = -DLIB585 diff --git a/tests/libtest/lib500.c b/tests/libtest/lib500.c index b88bfd8bc..166bb85ab 100644 --- a/tests/libtest/lib500.c +++ b/tests/libtest/lib500.c @@ -23,6 +23,39 @@ #include "memdebug.h" +#ifdef LIB585 + +int counter; + +static int opensocket(void *clientp, + curlsocktype purpose, + struct curl_sockaddr *addr) +{ + (void)clientp; + (void)purpose; + printf("[OPEN] counter: %d\n", ++counter); + return socket(addr->family, addr->socktype, addr->protocol); +} + +static int closesocket(void *clientp, curl_socket_t sock) +{ + (void)clientp; + printf("[CLOSE] counter: %d\n", counter--); + return sclose(sock); +} + +static void setupcallbacks(CURL *curl) +{ + curl_easy_setopt(curl, CURLOPT_OPENSOCKETFUNCTION, opensocket); + curl_easy_setopt(curl, CURLOPT_CLOSESOCKETFUNCTION, closesocket); + counter = 0; +} + +#else +#define setupcallbacks(x) +#endif + + int test(char *URL) { CURLcode res; @@ -43,6 +76,8 @@ int test(char *URL) test_setopt(curl, CURLOPT_URL, URL); test_setopt(curl, CURLOPT_HEADER, 1L); + setupcallbacks(curl); + res = curl_easy_perform(curl); if(!res) { -- cgit v1.2.3