Annotation of embedaddon/curl/tests/libtest/lib1523.c, revision 1.1
1.1 ! misho 1: /***************************************************************************
! 2: * _ _ ____ _
! 3: * Project ___| | | | _ \| |
! 4: * / __| | | | |_) | |
! 5: * | (__| |_| | _ <| |___
! 6: * \___|\___/|_| \_\_____|
! 7: *
! 8: * Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
! 9: *
! 10: * This software is licensed as described in the file COPYING, which
! 11: * you should have received as part of this distribution. The terms
! 12: * are also available at https://curl.haxx.se/docs/copyright.html.
! 13: *
! 14: * You may opt to use, copy, modify, merge, publish, distribute and/or sell
! 15: * copies of the Software, and permit persons to whom the Software is
! 16: * furnished to do so, under the terms of the COPYING file.
! 17: *
! 18: * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
! 19: * KIND, either express or implied.
! 20: *
! 21: ***************************************************************************/
! 22: #include "test.h"
! 23:
! 24: /* test case and code based on https://github.com/curl/curl/issues/3927 */
! 25:
! 26: #include "testutil.h"
! 27: #include "warnless.h"
! 28: #include "memdebug.h"
! 29:
! 30: static int dload_progress_cb(void *a, curl_off_t b, curl_off_t c,
! 31: curl_off_t d, curl_off_t e)
! 32: {
! 33: (void)a;
! 34: (void)b;
! 35: (void)c;
! 36: (void)d;
! 37: (void)e;
! 38: return 0;
! 39: }
! 40:
! 41: static size_t write_cb(char *d, size_t n, size_t l, void *p)
! 42: {
! 43: /* take care of the data here, ignored in this example */
! 44: (void)d;
! 45: (void)p;
! 46: return n*l;
! 47: }
! 48:
! 49: static CURLcode run(CURL *hnd, long limit, long time)
! 50: {
! 51: curl_easy_setopt(hnd, CURLOPT_LOW_SPEED_LIMIT, limit);
! 52: curl_easy_setopt(hnd, CURLOPT_LOW_SPEED_TIME, time);
! 53: return curl_easy_perform(hnd);
! 54: }
! 55:
! 56: int test(char *URL)
! 57: {
! 58: CURLcode ret;
! 59: CURL *hnd = curl_easy_init();
! 60: char buffer[CURL_ERROR_SIZE];
! 61: curl_easy_setopt(hnd, CURLOPT_URL, URL);
! 62: curl_easy_setopt(hnd, CURLOPT_WRITEFUNCTION, write_cb);
! 63: curl_easy_setopt(hnd, CURLOPT_ERRORBUFFER, buffer);
! 64: curl_easy_setopt(hnd, CURLOPT_NOPROGRESS, 0L);
! 65: curl_easy_setopt(hnd, CURLOPT_XFERINFOFUNCTION, dload_progress_cb);
! 66:
! 67: printf("Start: %d\n", time(NULL));
! 68: ret = run(hnd, 1, 2);
! 69: if(ret)
! 70: fprintf(stderr, "error %d: %s\n", ret, buffer);
! 71:
! 72: ret = run(hnd, 12000, 1);
! 73: if(ret != CURLE_OPERATION_TIMEDOUT)
! 74: fprintf(stderr, "error %d: %s\n", ret, buffer);
! 75: else
! 76: ret = 0;
! 77:
! 78: printf("End: %d\n", time(NULL));
! 79: curl_easy_cleanup(hnd);
! 80:
! 81: return (int)ret;
! 82: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>