Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/pkg
Path: blob/main/external/curl/tests/libtest/lib1534.c
2066 views
1
/***************************************************************************
2
* _ _ ____ _
3
* Project ___| | | | _ \| |
4
* / __| | | | |_) | |
5
* | (__| |_| | _ <| |___
6
* \___|\___/|_| \_\_____|
7
*
8
* Copyright (C) Daniel Stenberg, <[email protected]>, 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
28
/* Test CURLINFO_FILETIME */
29
30
CURLcode test(char *URL)
31
{
32
CURL *curl, *dupe = NULL;
33
long filetime;
34
CURLcode res = CURLE_OK;
35
36
global_init(CURL_GLOBAL_ALL);
37
38
easy_init(curl);
39
40
/* Test that a filetime is properly initialized on curl_easy_init.
41
*/
42
43
res = curl_easy_getinfo(curl, CURLINFO_FILETIME, &filetime);
44
if(res) {
45
curl_mfprintf(stderr,
46
"%s:%d curl_easy_getinfo() failed with code %d (%s)\n",
47
__FILE__, __LINE__, res, curl_easy_strerror(res));
48
goto test_cleanup;
49
}
50
if(filetime != -1) {
51
curl_mfprintf(stderr,
52
"%s:%d filetime init failed; expected -1 but is %ld\n",
53
__FILE__, __LINE__, filetime);
54
res = CURLE_FAILED_INIT;
55
goto test_cleanup;
56
}
57
58
easy_setopt(curl, CURLOPT_URL, URL);
59
easy_setopt(curl, CURLOPT_FILETIME, 1L);
60
61
res = curl_easy_perform(curl);
62
if(res) {
63
curl_mfprintf(stderr,
64
"%s:%d curl_easy_perform() failed with code %d (%s)\n",
65
__FILE__, __LINE__, res, curl_easy_strerror(res));
66
goto test_cleanup;
67
}
68
69
/* Test that a filetime is properly set after receiving an HTTP resource.
70
*/
71
72
res = curl_easy_getinfo(curl, CURLINFO_FILETIME, &filetime);
73
if(res) {
74
curl_mfprintf(stderr,
75
"%s:%d curl_easy_getinfo() failed with code %d (%s)\n",
76
__FILE__, __LINE__, res, curl_easy_strerror(res));
77
goto test_cleanup;
78
}
79
if(filetime != 30) {
80
curl_mfprintf(stderr, "%s:%d filetime of http resource is incorrect; "
81
"expected 30 but is %ld\n",
82
__FILE__, __LINE__, filetime);
83
res = CURLE_HTTP_RETURNED_ERROR;
84
goto test_cleanup;
85
}
86
87
/* Test that a filetime is properly initialized on curl_easy_duphandle.
88
*/
89
90
dupe = curl_easy_duphandle(curl);
91
if(!dupe) {
92
curl_mfprintf(stderr, "%s:%d curl_easy_duphandle() failed\n",
93
__FILE__, __LINE__);
94
res = CURLE_FAILED_INIT;
95
goto test_cleanup;
96
}
97
98
res = curl_easy_getinfo(dupe, CURLINFO_FILETIME, &filetime);
99
if(res) {
100
curl_mfprintf(stderr,
101
"%s:%d curl_easy_getinfo() failed with code %d (%s)\n",
102
__FILE__, __LINE__, res, curl_easy_strerror(res));
103
goto test_cleanup;
104
}
105
if(filetime != -1) {
106
curl_mfprintf(stderr,
107
"%s:%d filetime init failed; expected -1 but is %ld\n",
108
__FILE__, __LINE__, filetime);
109
res = CURLE_FAILED_INIT;
110
goto test_cleanup;
111
}
112
113
114
/* Test that a filetime is properly initialized on curl_easy_reset.
115
*/
116
117
curl_easy_reset(curl);
118
119
res = curl_easy_getinfo(curl, CURLINFO_FILETIME, &filetime);
120
if(res) {
121
curl_mfprintf(stderr,
122
"%s:%d curl_easy_getinfo() failed with code %d (%s)\n",
123
__FILE__, __LINE__, res, curl_easy_strerror(res));
124
goto test_cleanup;
125
}
126
if(filetime != -1) {
127
curl_mfprintf(stderr,
128
"%s:%d filetime init failed; expected -1 but is %ld\n",
129
__FILE__, __LINE__, filetime);
130
res = CURLE_FAILED_INIT;
131
goto test_cleanup;
132
}
133
134
test_cleanup:
135
curl_easy_cleanup(curl);
136
curl_easy_cleanup(dupe);
137
curl_global_cleanup();
138
return res;
139
}
140
141