Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "test.h"
00023
00024 #include "memdebug.h"
00025
00026
00027 static char data[]="this is a short string.\n";
00028
00029 static size_t data_size = sizeof(data) / sizeof(char);
00030
00031 static int progress_callback(void *clientp, double dltotal, double dlnow,
00032 double ultotal, double ulnow)
00033 {
00034 FILE *moo = fopen(libtest_arg2, "wb");
00035
00036 (void)clientp;
00037 (void)dltotal;
00038 (void)dlnow;
00039
00040 if(moo) {
00041 if((size_t)ultotal == data_size && (size_t)ulnow == data_size)
00042 fprintf(moo, "PASSED, UL data matched data size\n");
00043 else
00044 fprintf(moo, "Progress callback called with UL %f out of %f\n",
00045 ulnow, ultotal);
00046 fclose(moo);
00047 }
00048 return 0;
00049 }
00050
00051 int test(char *URL)
00052 {
00053 CURL *curl;
00054 CURLcode res=CURLE_OK;
00055
00056 if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
00057 fprintf(stderr, "curl_global_init() failed\n");
00058 return TEST_ERR_MAJOR_BAD;
00059 }
00060
00061 curl = curl_easy_init();
00062 if(!curl) {
00063 fprintf(stderr, "curl_easy_init() failed\n");
00064 curl_global_cleanup();
00065 return TEST_ERR_MAJOR_BAD;
00066 }
00067
00068
00069 test_setopt(curl, CURLOPT_URL, URL);
00070
00071
00072 test_setopt(curl, CURLOPT_POST, 1L);
00073
00074 #ifdef CURL_DOES_CONVERSIONS
00075
00076 test_setopt(curl, CURLOPT_TRANSFERTEXT, 1L);
00077 #endif
00078
00079
00080 test_setopt(curl, CURLOPT_POSTFIELDSIZE, data_size);
00081 test_setopt(curl, CURLOPT_POSTFIELDS, data);
00082
00083
00084 test_setopt(curl, CURLOPT_NOPROGRESS, 0L);
00085 test_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_callback);
00086
00087
00088
00089
00090 test_setopt(curl, CURLOPT_VERBOSE, 1L);
00091
00092
00093 test_setopt(curl, CURLOPT_HEADER, 1L);
00094
00095
00096 res = curl_easy_perform(curl);
00097
00098 test_cleanup:
00099
00100
00101 curl_easy_cleanup(curl);
00102 curl_global_cleanup();
00103
00104 return res;
00105 }