lib578.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. /* The size of data should be kept below MAX_INITIAL_POST_SIZE! */
  27. static char data[]="this is a short string.\n";
  28. static size_t data_size = sizeof(data) / sizeof(char);
  29. static int progress_callback(void *clientp, double dltotal, double dlnow,
  30. double ultotal, double ulnow)
  31. {
  32. FILE *moo = fopen(libtest_arg2, "wb");
  33. (void)clientp; /* UNUSED */
  34. (void)dltotal; /* UNUSED */
  35. (void)dlnow; /* UNUSED */
  36. if(moo) {
  37. if((size_t)ultotal == data_size && (size_t)ulnow == data_size)
  38. fprintf(moo, "PASSED, UL data matched data size\n");
  39. else
  40. fprintf(moo, "Progress callback called with UL %f out of %f\n",
  41. ulnow, ultotal);
  42. fclose(moo);
  43. }
  44. return 0;
  45. }
  46. int test(char *URL)
  47. {
  48. CURL *curl;
  49. CURLcode res = CURLE_OK;
  50. if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
  51. fprintf(stderr, "curl_global_init() failed\n");
  52. return TEST_ERR_MAJOR_BAD;
  53. }
  54. curl = curl_easy_init();
  55. if(!curl) {
  56. fprintf(stderr, "curl_easy_init() failed\n");
  57. curl_global_cleanup();
  58. return TEST_ERR_MAJOR_BAD;
  59. }
  60. /* First set the URL that is about to receive our POST. */
  61. test_setopt(curl, CURLOPT_URL, URL);
  62. /* Now specify we want to POST data */
  63. test_setopt(curl, CURLOPT_POST, 1L);
  64. /* Set the expected POST size */
  65. test_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)data_size);
  66. test_setopt(curl, CURLOPT_POSTFIELDS, data);
  67. /* we want to use our own progress function */
  68. CURL_IGNORE_DEPRECATION(
  69. test_setopt(curl, CURLOPT_NOPROGRESS, 0L);
  70. test_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_callback);
  71. )
  72. /* get verbose debug output please */
  73. test_setopt(curl, CURLOPT_VERBOSE, 1L);
  74. /* include headers in the output */
  75. test_setopt(curl, CURLOPT_HEADER, 1L);
  76. /* Perform the request, res will get the return code */
  77. res = curl_easy_perform(curl);
  78. test_cleanup:
  79. /* always cleanup */
  80. curl_easy_cleanup(curl);
  81. curl_global_cleanup();
  82. return res;
  83. }