lib578.c 3.0 KB

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