2
0

lib599.c 2.7 KB

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