lib578.c 3.0 KB

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