unit1606.c
Go to the documentation of this file.
1 /***************************************************************************
2  * _ _ ____ _
3  * Project ___| | | | _ \| |
4  * / __| | | | |_) | |
5  * | (__| |_| | _ <| |___
6  * \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) 1998 - 2017, 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 "curlcheck.h"
23 
24 #include "speedcheck.h"
25 #include "urldata.h"
26 
27 static CURL *easy;
28 
29 static CURLcode unit_setup(void)
30 {
31  int res = CURLE_OK;
32 
34  easy = curl_easy_init();
35  if(!easy)
36  return CURLE_OUT_OF_MEMORY;
37  return res;
38 }
39 
40 static void unit_stop(void)
41 {
44 }
45 
46 static int runawhile(long time_limit,
47  long speed_limit,
48  curl_off_t speed,
49  int dec)
50 {
51  int counter = 1;
52  struct curltime now = {1, 0};
54  int finaltime;
55 
56  curl_easy_setopt(easy, CURLOPT_LOW_SPEED_LIMIT, speed_limit);
57  curl_easy_setopt(easy, CURLOPT_LOW_SPEED_TIME, time_limit);
59 
60  do {
61  /* fake the current transfer speed */
62  easy->progress.current_speed = speed;
63  result = Curl_speedcheck(easy, now);
64  if(result)
65  break;
66  /* step the time */
67  now.tv_sec = ++counter;
68  speed -= dec;
69  } while(counter < 100);
70 
71  finaltime = (int)(now.tv_sec - 1);
72 
73  return finaltime;
74 }
75 
77  fail_unless(runawhile(41, 41, 40, 0) == 41,
78  "wrong low speed timeout");
79  fail_unless(runawhile(21, 21, 20, 0) == 21,
80  "wrong low speed timeout");
81  fail_unless(runawhile(60, 60, 40, 0) == 60,
82  "wrong log speed timeout");
83  fail_unless(runawhile(50, 50, 40, 0) == 50,
84  "wrong log speed timeout");
85  fail_unless(runawhile(40, 40, 40, 0) == 99,
86  "should not time out");
87  fail_unless(runawhile(10, 50, 100, 2) == 36,
88  "bad timeout");
static void unit_stop(void)
Definition: unit1606.c:40
#define UNITTEST_START
Definition: curlcheck.h:86
time_t tv_sec
Definition: timeval.h:33
#define global_init(A)
Definition: test.h:431
static CURLcode unit_setup(void)
Definition: unit1606.c:29
CURLcode
Definition: curl.h:454
static int res
UNITTEST_START int result
Definition: unit1304.c:49
#define curl_easy_setopt(handle, option, value)
Definition: typecheck-gcc.h:41
static int counter[MAX_EASY_HANDLES]
CURL_EXTERN CURL * curl_easy_init(void)
Definition: easy.c:343
CURL_EXTERN void curl_easy_cleanup(CURL *curl)
CURL_TYPEOF_CURL_OFF_T curl_off_t
Definition: system.h:420
void Curl_speedinit(struct Curl_easy *data)
Definition: speedcheck.c:31
Definition: curl.h:455
CURLcode Curl_speedcheck(struct Curl_easy *data, struct curltime now)
Definition: speedcheck.c:39
static CURL * easy
Definition: unit1606.c:27
#define UNITTEST_STOP
Definition: curlcheck.h:95
UNITTEST_START fail_unless(runawhile(41, 41, 40, 0)==41,"wrong low speed timeout")
void CURL
Definition: curl.h:102
static int runawhile(long time_limit, long speed_limit, curl_off_t speed, int dec)
Definition: unit1606.c:46
CURL_EXTERN void curl_global_cleanup(void)
curl_global_cleanup() globally cleanups curl, uses the value of "init_flags" to determine what needs ...
Definition: easy.c:312
#define CURL_GLOBAL_ALL
Definition: curl.h:2519


rc_tagdetect_client
Author(s): Monika Florek-Jasinska , Raphael Schaller
autogenerated on Sat Feb 13 2021 03:42:16