1/***************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
7 *
8 * Copyright (C) 1998 - 2016, 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#include "memdebug.h"
25
26/* Test CURLINFO_FILETIME */
27
28int test(char *URL)
29{
30 CURL *curl, *dupe = NULL;
31 long filetime;
32 int res = CURLE_OK;
33
34 global_init(CURL_GLOBAL_ALL);
35
36 easy_init(curl);
37
38 /* Test that a filetime is properly initialized on curl_easy_init.
39 */
40
41 res = curl_easy_getinfo(curl, CURLINFO_FILETIME, &filetime);
42 if(res) {
43 fprintf(stderr, "%s:%d curl_easy_getinfo() failed with code %d (%s)\n",
44 __FILE__, __LINE__, res, curl_easy_strerror(res));
45 goto test_cleanup;
46 }
47 if(filetime != -1) {
48 fprintf(stderr, "%s:%d filetime init failed; expected -1 but is %ld\n",
49 __FILE__, __LINE__, filetime);
50 res = CURLE_FAILED_INIT;
51 goto test_cleanup;
52 }
53
54 easy_setopt(curl, CURLOPT_URL, URL);
55 easy_setopt(curl, CURLOPT_FILETIME, 1L);
56
57 res = curl_easy_perform(curl);
58 if(res) {
59 fprintf(stderr, "%s:%d curl_easy_perform() failed with code %d (%s)\n",
60 __FILE__, __LINE__, res, curl_easy_strerror(res));
61 goto test_cleanup;
62 }
63
64 /* Test that a filetime is properly set after receiving an HTTP resource.
65 */
66
67 res = curl_easy_getinfo(curl, CURLINFO_FILETIME, &filetime);
68 if(res) {
69 fprintf(stderr, "%s:%d curl_easy_getinfo() failed with code %d (%s)\n",
70 __FILE__, __LINE__, res, curl_easy_strerror(res));
71 goto test_cleanup;
72 }
73 if(filetime != 30) {
74 fprintf(stderr, "%s:%d filetime of http resource is incorrect; "
75 "expected 30 but is %ld\n",
76 __FILE__, __LINE__, filetime);
77 res = CURLE_HTTP_RETURNED_ERROR;
78 goto test_cleanup;
79 }
80
81 /* Test that a filetime is properly initialized on curl_easy_duphandle.
82 */
83
84 dupe = curl_easy_duphandle(curl);
85 if(!dupe) {
86 fprintf(stderr, "%s:%d curl_easy_duphandle() failed\n",
87 __FILE__, __LINE__);
88 res = CURLE_FAILED_INIT;
89 goto test_cleanup;
90 }
91
92 res = curl_easy_getinfo(dupe, CURLINFO_FILETIME, &filetime);
93 if(res) {
94 fprintf(stderr, "%s:%d curl_easy_getinfo() failed with code %d (%s)\n",
95 __FILE__, __LINE__, res, curl_easy_strerror(res));
96 goto test_cleanup;
97 }
98 if(filetime != -1) {
99 fprintf(stderr, "%s:%d filetime init failed; expected -1 but is %ld\n",
100 __FILE__, __LINE__, filetime);
101 res = CURLE_FAILED_INIT;
102 goto test_cleanup;
103 }
104
105
106 /* Test that a filetime is properly initialized on curl_easy_reset.
107 */
108
109 curl_easy_reset(curl);
110
111 res = curl_easy_getinfo(curl, CURLINFO_FILETIME, &filetime);
112 if(res) {
113 fprintf(stderr, "%s:%d curl_easy_getinfo() failed with code %d (%s)\n",
114 __FILE__, __LINE__, res, curl_easy_strerror(res));
115 goto test_cleanup;
116 }
117 if(filetime != -1) {
118 fprintf(stderr, "%s:%d filetime init failed; expected -1 but is %ld\n",
119 __FILE__, __LINE__, filetime);
120 res = CURLE_FAILED_INIT;
121 goto test_cleanup;
122 }
123
124test_cleanup:
125 curl_easy_cleanup(curl);
126 curl_easy_cleanup(dupe);
127 curl_global_cleanup();
128 return res;
129}
130