From 70baf46d8ddfc07b488d17cf0f5d8e23cf7de14e Mon Sep 17 00:00:00 2001 From: Julien Chaffraix Date: Thu, 19 Aug 2010 00:27:04 +0200 Subject: test: added test 579 to verify progress callback for chunked post The 66 bytes checked are those 38 bytes with the chunked encoding headers added: 8+8+10+35+5 = 66 The three-letter words become 8 bytes on the wire because they are sent like: "3\r\none\r\n" ... and there's the trailing 5 bytes write after the four lines since the final chunk is sent (which is "0\r\n\r\n"). --- tests/libtest/lib579.c | 149 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 tests/libtest/lib579.c (limited to 'tests/libtest/lib579.c') diff --git a/tests/libtest/lib579.c b/tests/libtest/lib579.c new file mode 100644 index 000000000..01e91d8f0 --- /dev/null +++ b/tests/libtest/lib579.c @@ -0,0 +1,149 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + */ + +#include "test.h" + +#include "memdebug.h" + +static const char *post[]={ + "one", + "two", + "three", + "and a final longer crap: four", + NULL +}; + + +struct WriteThis { + int counter; +}; + +static int progress_callback(void *clientp, double dltotal, double dlnow, + double ultotal, double ulnow) +{ + FILE *moo; + (void)clientp; /* UNUSED */ + (void)dltotal; /* UNUSED */ + (void)dlnow; /* UNUSED */ + static int prev_ultotal = -1; + static int prev_ulnow = -1; + + /* to avoid depending on timing, which will cause this progress function to + get called a different number of times depending on circumstances, we + only log these lines if the numbers are different from the previous + invoke */ + if((prev_ultotal != (int)ultotal) || + (prev_ulnow != (int)ulnow)) { + + moo = fopen(libtest_arg2, "ab"); + if(moo) { + fprintf(moo, "Progress callback called with UL %d out of %d\n", + (int)ulnow, (int)ultotal); + fclose(moo); + } + prev_ulnow = (int) ulnow; + prev_ultotal = (int) ultotal; + } + return 0; +} + +static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *userp) +{ + struct WriteThis *pooh = (struct WriteThis *)userp; + const char *data; + + if(size*nmemb < 1) + return 0; + + data = post[pooh->counter]; + + if(data) { + size_t len = strlen(data); + memcpy(ptr, data, len); + pooh->counter++; /* advance pointer */ + return len; + } + return 0; /* no more data left to deliver */ +} + +int test(char *URL) +{ + CURL *curl; + CURLcode res=CURLE_OK; + struct curl_slist *slist = NULL; + struct WriteThis pooh; + pooh.counter = 0; + + if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { + fprintf(stderr, "curl_global_init() failed\n"); + return TEST_ERR_MAJOR_BAD; + } + + if ((curl = curl_easy_init()) == NULL) { + fprintf(stderr, "curl_easy_init() failed\n"); + curl_global_cleanup(); + return TEST_ERR_MAJOR_BAD; + } + + slist = curl_slist_append(slist, "Transfer-Encoding: chunked"); + if (slist == NULL) { + fprintf(stderr, "curl_slist_append() failed\n"); + curl_easy_cleanup(curl); + curl_global_cleanup(); + return TEST_ERR_MAJOR_BAD; + } + + /* First set the URL that is about to receive our POST. */ + test_setopt(curl, CURLOPT_URL, URL); + + /* Now specify we want to POST data */ + test_setopt(curl, CURLOPT_POST, 1L); + +#ifdef CURL_DOES_CONVERSIONS + /* Convert the POST data to ASCII */ + test_setopt(curl, CURLOPT_TRANSFERTEXT, 1L); +#endif + + /* we want to use our own read function */ + test_setopt(curl, CURLOPT_READFUNCTION, read_callback); + + /* pointer to pass to our read function */ + test_setopt(curl, CURLOPT_INFILE, &pooh); + + /* get verbose debug output please */ + test_setopt(curl, CURLOPT_VERBOSE, 1L); + + /* include headers in the output */ + test_setopt(curl, CURLOPT_HEADER, 1L); + + /* enforce chunked transfer by setting the header */ + test_setopt(curl, CURLOPT_HTTPHEADER, slist); + + test_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST); + test_setopt(curl, CURLOPT_USERPWD, "foo:bar"); + + /* we want to use our own progress function */ + test_setopt(curl, CURLOPT_NOPROGRESS, 0L); + test_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_callback); + + /* Perform the request, res will get the return code */ + res = curl_easy_perform(curl); + +test_cleanup: + + /* clean up the headers list */ + if(slist) + curl_slist_free_all(slist); + + /* always cleanup */ + curl_easy_cleanup(curl); + curl_global_cleanup(); + + return res; +} -- cgit v1.2.1 From ebbe694e78cb351c239c936375cc4439afe0a929 Mon Sep 17 00:00:00 2001 From: Dan Fandrich Date: Wed, 18 Aug 2010 22:16:46 -0700 Subject: Removed a C99ism & made an array const --- tests/libtest/lib579.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests/libtest/lib579.c') diff --git a/tests/libtest/lib579.c b/tests/libtest/lib579.c index 01e91d8f0..2b80ab0b6 100644 --- a/tests/libtest/lib579.c +++ b/tests/libtest/lib579.c @@ -11,7 +11,7 @@ #include "memdebug.h" -static const char *post[]={ +static const char * const post[]={ "one", "two", "three", @@ -28,11 +28,11 @@ static int progress_callback(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow) { FILE *moo; + static int prev_ultotal = -1; + static int prev_ulnow = -1; (void)clientp; /* UNUSED */ (void)dltotal; /* UNUSED */ (void)dlnow; /* UNUSED */ - static int prev_ultotal = -1; - static int prev_ulnow = -1; /* to avoid depending on timing, which will cause this progress function to get called a different number of times depending on circumstances, we -- cgit v1.2.1 From 1aeb635cdd296c16acb375a4a83a78f13166ccab Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 10 Mar 2011 11:48:02 +0100 Subject: sources: update source headers All C and H files now (should) feature the proper project curl source code header, which includes basic info, a copyright statement and some basic disclaimers. --- tests/libtest/lib579.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'tests/libtest/lib579.c') diff --git a/tests/libtest/lib579.c b/tests/libtest/lib579.c index 2b80ab0b6..ad8ba7e97 100644 --- a/tests/libtest/lib579.c +++ b/tests/libtest/lib579.c @@ -1,11 +1,24 @@ -/***************************************************************************** +/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - */ + * Copyright (C) 1998 - 2011, Daniel Stenberg, , 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 http://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" -- cgit v1.2.1 From c8ba8740b9c3e7a5054c2d7ba5689778aa26618b Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Tue, 6 Sep 2011 17:47:54 +0200 Subject: test suite: libtest header inclusion cleanup Added missing memoryTracking to test cases 560 and 583. If this triggers leak detection on these, it only means that previously it was going unnoticed. --- tests/libtest/lib579.c | 1 - 1 file changed, 1 deletion(-) (limited to 'tests/libtest/lib579.c') diff --git a/tests/libtest/lib579.c b/tests/libtest/lib579.c index ad8ba7e97..56193a181 100644 --- a/tests/libtest/lib579.c +++ b/tests/libtest/lib579.c @@ -19,7 +19,6 @@ * KIND, either express or implied. * ***************************************************************************/ - #include "test.h" #include "memdebug.h" -- cgit v1.2.1 From ce8a321dd0c1f06dea1b8edf7b1b76e9672caaeb Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Wed, 18 Apr 2012 21:03:20 +0200 Subject: Some explicit conversion to 'long' of curl_easy_setopt() third argument Explicit conversion to 'long' of curl_easy_setopt() third argument for options CURLOPT_HTTPAUTH and CURLOPT_PROXYAUTH given that this is how its bitmasks are docummented to be used. --- tests/libtest/lib579.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/libtest/lib579.c') diff --git a/tests/libtest/lib579.c b/tests/libtest/lib579.c index 56193a181..c5cf603bb 100644 --- a/tests/libtest/lib579.c +++ b/tests/libtest/lib579.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2011, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2012, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -137,7 +137,7 @@ int test(char *URL) /* enforce chunked transfer by setting the header */ test_setopt(curl, CURLOPT_HTTPHEADER, slist); - test_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST); + test_setopt(curl, CURLOPT_HTTPAUTH, (long)CURLAUTH_DIGEST); test_setopt(curl, CURLOPT_USERPWD, "foo:bar"); /* we want to use our own progress function */ -- cgit v1.2.1