blob: 5b35cca03f8967d192d88e74d6fc4674ca01763a [file] [log] [blame]
xf.li6c8fc1e2023-08-12 00:11:09 -07001/***************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
7 *
8 * Copyright (C) 1998 - 2022, 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.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 * SPDX-License-Identifier: curl
22 *
23 ***************************************************************************/
24#include "test.h"
25
26#include "memdebug.h"
27
28static int progress_callback(void *clientp, double dltotal,
29 double dlnow, double ultotal, double ulnow)
30{
31 (void)clientp;
32 (void)ulnow;
33 (void)ultotal;
34
35 if((dltotal > 0.0) && (dlnow > dltotal)) {
36 /* this should not happen with test case 599 */
37 printf("%.0f > %.0f !!\n", dltotal, dlnow);
38 return -1;
39 }
40
41 return 0;
42}
43
44int test(char *URL)
45{
46 CURL *curl;
47 CURLcode res = CURLE_OK;
48 double content_length = 0.0;
49
50 if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
51 fprintf(stderr, "curl_global_init() failed\n");
52 return TEST_ERR_MAJOR_BAD;
53 }
54
55 curl = curl_easy_init();
56 if(!curl) {
57 fprintf(stderr, "curl_easy_init() failed\n");
58 curl_global_cleanup();
59 return TEST_ERR_MAJOR_BAD;
60 }
61
62 /* First set the URL that is about to receive our POST. */
63 test_setopt(curl, CURLOPT_URL, URL);
64
65 /* we want to use our own progress function */
66 test_setopt(curl, CURLOPT_NOPROGRESS, 0L);
67 test_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_callback);
68
69 /* get verbose debug output please */
70 test_setopt(curl, CURLOPT_VERBOSE, 1L);
71
72 /* follow redirects */
73 test_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
74
75 /* include headers in the output */
76 test_setopt(curl, CURLOPT_HEADER, 1L);
77
78 /* Perform the request, res will get the return code */
79 res = curl_easy_perform(curl);
80
81 if(!res) {
82 FILE *moo;
83 res = curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD,
84 &content_length);
85 moo = fopen(libtest_arg2, "wb");
86 if(moo) {
87 fprintf(moo, "CL %.0f\n", content_length);
88 fclose(moo);
89 }
90 }
91
92test_cleanup:
93
94 /* always cleanup */
95 curl_easy_cleanup(curl);
96 curl_global_cleanup();
97
98 return res;
99}