2
0

lib599.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. static int progress_callback(void *clientp, double dltotal,
  27. double dlnow, double ultotal, double ulnow)
  28. {
  29. (void)clientp;
  30. (void)ulnow;
  31. (void)ultotal;
  32. if((dltotal > 0.0) && (dlnow > dltotal)) {
  33. /* this should not happen with test case 599 */
  34. printf("%.0f > %.0f !!\n", dltotal, dlnow);
  35. return -1;
  36. }
  37. return 0;
  38. }
  39. CURLcode test(char *URL)
  40. {
  41. CURL *curl;
  42. CURLcode res = CURLE_OK;
  43. double content_length = 0.0;
  44. if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
  45. fprintf(stderr, "curl_global_init() failed\n");
  46. return TEST_ERR_MAJOR_BAD;
  47. }
  48. curl = curl_easy_init();
  49. if(!curl) {
  50. fprintf(stderr, "curl_easy_init() failed\n");
  51. curl_global_cleanup();
  52. return TEST_ERR_MAJOR_BAD;
  53. }
  54. /* First set the URL that is about to receive our POST. */
  55. test_setopt(curl, CURLOPT_URL, URL);
  56. /* we want to use our own progress function */
  57. test_setopt(curl, CURLOPT_NOPROGRESS, 0L);
  58. CURL_IGNORE_DEPRECATION(
  59. test_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_callback);
  60. )
  61. /* get verbose debug output please */
  62. test_setopt(curl, CURLOPT_VERBOSE, 1L);
  63. /* follow redirects */
  64. test_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
  65. /* include headers in the output */
  66. test_setopt(curl, CURLOPT_HEADER, 1L);
  67. /* Perform the request, res will get the return code */
  68. res = curl_easy_perform(curl);
  69. if(!res) {
  70. FILE *moo;
  71. CURL_IGNORE_DEPRECATION(
  72. res = curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD,
  73. &content_length);
  74. )
  75. moo = fopen(libtest_arg2, "wb");
  76. if(moo) {
  77. fprintf(moo, "CL %.0f\n", content_length);
  78. fclose(moo);
  79. }
  80. }
  81. test_cleanup:
  82. /* always cleanup */
  83. curl_easy_cleanup(curl);
  84. curl_global_cleanup();
  85. return res;
  86. }