tests: verify OPEN/CLOSESOCKETFUNCTION
authorDaniel Stenberg <daniel@haxx.se>
Wed, 18 May 2011 19:48:14 +0000 (21:48 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Wed, 18 May 2011 20:56:46 +0000 (22:56 +0200)
Test 585 and 586 were added. Using a modified lib500.c

tests/data/Makefile.am
tests/data/test585 [new file with mode: 0644]
tests/data/test586 [new file with mode: 0644]
tests/libtest/Makefile.inc
tests/libtest/lib500.c

index ac52997..2249394 100644 (file)
@@ -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 (file)
index 0000000..32cb06f
--- /dev/null
@@ -0,0 +1,69 @@
+<testcase>
+<info>
+<keywords>
+HTTP
+HTTP GET
+multi
+CURLOPT_OPENSOCKETFUNCTION
+CURLOPT_CLOSESOCKETFUNCTION
+</keywords>
+</info>
+
+# Server-side
+<reply>
+<data>
+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
+
+</data>
+<datacheck>
+[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
+</datacheck>
+</reply>
+
+# Client-side
+<client>
+<server>
+http
+</server>
+<features>
+http
+</features>
+# tool is what to use instead of 'curl'
+<tool>
+lib585
+</tool>
+
+ <name>
+socket open/close callbacks
+ </name>
+ <command>
+http://%HOSTIP:%HTTPPORT/585
+</command>
+</client>
+
+# Verify data after the test has been "shot"
+<verify>
+<strip>
+^User-Agent:.*
+</strip>
+<protocol>
+GET /585 HTTP/1.1\r
+Host: %HOSTIP:%HTTPPORT\r
+Accept: */*\r
+\r
+</protocol>
+</verify>
+</testcase>
diff --git a/tests/data/test586 b/tests/data/test586
new file mode 100644 (file)
index 0000000..c0857bd
--- /dev/null
@@ -0,0 +1,59 @@
+<testcase>
+<info>
+<keywords>
+FTP
+PASV
+CURLOPT_PORT
+</keywords>
+</info>
+#
+# Server-side
+<reply>
+<data>
+line 1
+line 2
+last line
+</data>
+<datacheck>
+[OPEN] counter: 1
+[OPEN] counter: 2
+line 1
+line 2
+last line
+[CLOSE] counter: 2
+[CLOSE] counter: 1
+</datacheck>
+</reply>
+
+#
+# Client-side
+<client>
+<server>
+ftp
+</server>
+<tool>
+lib585
+</tool>
+ <name>
+FTP and open/close socket callbacks
+ </name>
+ <command>
+ftp://%HOSTIP:%FTPPORT/586
+</command>
+</client>
+
+#
+# Verify data after the test has been "shot"
+<verify>
+<protocol>
+USER anonymous\r
+PASS ftp@example.com\r
+PWD\r
+EPSV\r
+TYPE I\r
+SIZE 586\r
+RETR 586\r
+QUIT\r
+</protocol>
+</verify>
+</testcase>
index a210cbf..06cda1e 100644 (file)
@@ -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
index b88bfd8..166bb85 100644 (file)
 
 #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) {