1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
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.haxx.se/docs/copyright.html.
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.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ***************************************************************************/
26 /* The size of data should be kept below MAX_INITIAL_POST_SIZE! */
27 static char data[]="this is a short string.\n";
29 static size_t data_size = sizeof(data) / sizeof(char);
31 static int progress_callback(void *clientp, double dltotal, double dlnow,
32 double ultotal, double ulnow)
34 FILE *moo = fopen(libtest_arg2, "wb");
36 (void)clientp; /* UNUSED */
37 (void)dltotal; /* UNUSED */
38 (void)dlnow; /* UNUSED */
41 if((size_t)ultotal == data_size && (size_t)ulnow == data_size)
42 fprintf(moo, "PASSED, UL data matched data size\n");
44 fprintf(moo, "Progress callback called with UL %f out of %f\n",
54 CURLcode res=CURLE_OK;
56 if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
57 fprintf(stderr, "curl_global_init() failed\n");
58 return TEST_ERR_MAJOR_BAD;
61 if((curl = curl_easy_init()) == NULL) {
62 fprintf(stderr, "curl_easy_init() failed\n");
63 curl_global_cleanup();
64 return TEST_ERR_MAJOR_BAD;
67 /* First set the URL that is about to receive our POST. */
68 test_setopt(curl, CURLOPT_URL, URL);
70 /* Now specify we want to POST data */
71 test_setopt(curl, CURLOPT_POST, 1L);
73 #ifdef CURL_DOES_CONVERSIONS
74 /* Convert the POST data to ASCII */
75 test_setopt(curl, CURLOPT_TRANSFERTEXT, 1L);
78 /* Set the expected POST size */
79 test_setopt(curl, CURLOPT_POSTFIELDSIZE, data_size);
80 test_setopt(curl, CURLOPT_POSTFIELDS, data);
82 /* we want to use our own progress function */
83 test_setopt(curl, CURLOPT_NOPROGRESS, 0L);
84 test_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_callback);
86 /* pointer to pass to our read function */
88 /* get verbose debug output please */
89 test_setopt(curl, CURLOPT_VERBOSE, 1L);
91 /* include headers in the output */
92 test_setopt(curl, CURLOPT_HEADER, 1L);
94 /* Perform the request, res will get the return code */
95 res = curl_easy_perform(curl);
100 curl_easy_cleanup(curl);
101 curl_global_cleanup();