aboutsummaryrefslogtreecommitdiff
path: root/tests/libtest
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2018-08-10 13:57:50 +0200
committerDaniel Stenberg <daniel@haxx.se>2018-08-11 14:00:59 +0200
commit2a278fd73573d025e6d5ebde8b10d446c27d6d3f (patch)
tree19059ae179e76a0ce86d45cf8c4a4194e7a33200 /tests/libtest
parent53d211bfd1b209f62ded7e67045d584804c2309d (diff)
CURLINFO_SIZE_UPLOAD: fix missing counter update
Adds test 1522 for verification. Reported-by: cjmsoregan Fixes #2847 Closes #2864
Diffstat (limited to 'tests/libtest')
-rw-r--r--tests/libtest/Makefile.inc5
-rw-r--r--tests/libtest/lib1522.c87
2 files changed, 91 insertions, 1 deletions
diff --git a/tests/libtest/Makefile.inc b/tests/libtest/Makefile.inc
index ecb7d1dd4..61616ba1d 100644
--- a/tests/libtest/Makefile.inc
+++ b/tests/libtest/Makefile.inc
@@ -24,7 +24,7 @@ noinst_PROGRAMS = chkhostname libauthretry libntlmconnect \
lib1156 \
lib1500 lib1501 lib1502 lib1503 lib1504 lib1505 lib1506 lib1507 lib1508 \
lib1509 lib1510 lib1511 lib1512 lib1513 lib1514 lib1515 lib1517 \
- lib1520 lib1521 \
+ lib1520 lib1521 lib1522 \
lib1525 lib1526 lib1527 lib1528 lib1529 lib1530 lib1531 lib1532 lib1533 \
lib1534 lib1535 lib1536 lib1537 lib1538 \
lib1540 \
@@ -408,6 +408,9 @@ lib1520_CPPFLAGS = $(AM_CPPFLAGS) -DLIB1520
nodist_lib1521_SOURCES = lib1521.c $(SUPPORTFILES)
lib1521_CPPFLAGS = $(AM_CPPFLAGS) -I$(srcdir)
+lib1522_SOURCES = lib1522.c $(SUPPORTFILES)
+lib1522_CPPFLAGS = $(AM_CPPFLAGS)
+
lib1525_SOURCES = lib1525.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS)
lib1525_LDADD = $(TESTUTIL_LIBS)
lib1525_CPPFLAGS = $(AM_CPPFLAGS) -DLIB1525
diff --git a/tests/libtest/lib1522.c b/tests/libtest/lib1522.c
new file mode 100644
index 000000000..5a47a359c
--- /dev/null
+++ b/tests/libtest/lib1522.c
@@ -0,0 +1,87 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at https://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ***************************************************************************/
+#include "test.h"
+
+/* test case and code based on https://github.com/curl/curl/issues/2847 */
+
+#include "testutil.h"
+#include "warnless.h"
+#include "memdebug.h"
+
+static char g_Data[40 * 1024]; /* POST 40KB */
+
+static int sockopt_callback(void *clientp, curl_socket_t curlfd,
+ curlsocktype purpose)
+{
+ int sndbufsize = 4 * 1024; /* 4KB send buffer */
+ (void) clientp;
+ (void) purpose;
+#if defined(SOL_SOCKET) && defined(SO_SNDBUF)
+ setsockopt(curlfd, SOL_SOCKET, SO_SNDBUF,
+ (const char *)&sndbufsize, sizeof(sndbufsize));
+#else
+ (void)curlfd;
+#endif
+ return CURL_SOCKOPT_OK;
+}
+
+int test(char *URL)
+{
+ CURLcode code;
+ struct curl_slist *pHeaderList = NULL;
+ CURL *pCurl = curl_easy_init();
+ memset(g_Data, 'A', sizeof(g_Data)); /* send As! */
+
+ curl_easy_setopt(pCurl, CURLOPT_SOCKOPTFUNCTION, sockopt_callback);
+ curl_easy_setopt(pCurl, CURLOPT_URL, URL);
+ curl_easy_setopt(pCurl, CURLOPT_POSTFIELDS, g_Data);
+ curl_easy_setopt(pCurl, CURLOPT_POSTFIELDSIZE, sizeof(g_Data));
+
+ /* Remove "Expect: 100-continue" */
+ pHeaderList = curl_slist_append(pHeaderList, "Expect:");
+
+ curl_easy_setopt(pCurl, CURLOPT_HTTPHEADER, pHeaderList);
+
+ code = curl_easy_perform(pCurl);
+
+ if(code == CURLE_OK) {
+ curl_off_t uploadSize;
+ curl_easy_getinfo(pCurl, CURLINFO_SIZE_UPLOAD_T, &uploadSize);
+
+ printf("uploadSize = %ld\n", (long)uploadSize);
+
+ if((size_t) uploadSize == sizeof(g_Data)) {
+ printf("!!!!!!!!!! PASS\n");
+ }
+ else {
+ printf("!!!!!!!!!! FAIL\n");
+ }
+ }
+ else {
+ printf("curl_easy_perform() failed. e = %d\n", code);
+ }
+
+ curl_slist_free_all(pHeaderList);
+ curl_easy_cleanup(pCurl);
+
+ return 0;
+}