2
0

lib1534.c 3.9 KB

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