lib1534.c (4299B)
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 "first.h" 25 26 #include "memdebug.h" 27 28 /* Test CURLINFO_FILETIME */ 29 30 static CURLcode test_lib1534(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 /* Test that a filetime is properly initialized on curl_easy_reset. 114 */ 115 116 curl_easy_reset(curl); 117 118 res = curl_easy_getinfo(curl, CURLINFO_FILETIME, &filetime); 119 if(res) { 120 curl_mfprintf(stderr, 121 "%s:%d curl_easy_getinfo() failed with code %d (%s)\n", 122 __FILE__, __LINE__, res, curl_easy_strerror(res)); 123 goto test_cleanup; 124 } 125 if(filetime != -1) { 126 curl_mfprintf(stderr, 127 "%s:%d filetime init failed; expected -1 but is %ld\n", 128 __FILE__, __LINE__, filetime); 129 res = CURLE_FAILED_INIT; 130 goto test_cleanup; 131 } 132 133 test_cleanup: 134 curl_easy_cleanup(curl); 135 curl_easy_cleanup(dupe); 136 curl_global_cleanup(); 137 return res; 138 }