2
0

lib1534.c 3.9 KB

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