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