1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2017, 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 ***************************************************************************/
22 #include "curlcheck.h"
24 #include <curl/curl.h>
26 static CURLcode unit_setup(void)
31 static void unit_stop(void)
36 static size_t print_httppost_callback(void *arg, const char *buf, size_t len)
38 fwrite(buf, len, 1, stdout);
39 (*(size_t *) arg) += len;
45 struct curl_httppost *post = NULL;
46 struct curl_httppost *last = NULL;
47 size_t total_size = 0;
48 char buffer[] = "test buffer";
50 rc = curl_formadd(&post, &last, CURLFORM_COPYNAME, "name",
51 CURLFORM_COPYCONTENTS, "content", CURLFORM_END);
53 fail_unless(rc == 0, "curl_formadd returned error");
55 /* after the first curl_formadd when there's a single entry, both pointers
56 should point to the same struct */
57 fail_unless(post == last, "post and last weren't the same");
59 rc = curl_formadd(&post, &last, CURLFORM_COPYNAME, "htmlcode",
60 CURLFORM_COPYCONTENTS, "<HTML></HTML>",
61 CURLFORM_CONTENTTYPE, "text/html", CURLFORM_END);
63 fail_unless(rc == 0, "curl_formadd returned error");
65 rc = curl_formadd(&post, &last, CURLFORM_COPYNAME, "name_for_ptrcontent",
66 CURLFORM_PTRCONTENTS, buffer, CURLFORM_END);
68 fail_unless(rc == 0, "curl_formadd returned error");
70 rc = curl_formget(post, &total_size, print_httppost_callback);
72 fail_unless(rc == 0, "curl_formget returned error");
74 fail_unless(total_size == 488, "curl_formget got wrong size back");
78 /* start a new formpost with a file upload and formget */
81 rc = curl_formadd(&post, &last,
82 CURLFORM_PTRNAME, "name of file field",
83 CURLFORM_FILE, "log/test-1308",
84 CURLFORM_FILENAME, "custom named file",
87 fail_unless(rc == 0, "curl_formadd returned error");
89 rc = curl_formget(post, &total_size, print_httppost_callback);
90 fail_unless(rc == 0, "curl_formget returned error");
91 fail_unless(total_size == 851, "curl_formget got wrong size back");