unit1308.c
Go to the documentation of this file.
1 /***************************************************************************
2  * _ _ ____ _
3  * Project ___| | | | _ \| |
4  * / __| | | | |_) | |
5  * | (__| |_| | _ <| |___
6  * \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) 1998 - 2017, 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.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 "curlcheck.h"
23 
24 #include <curl/curl.h>
25 
26 static CURLcode unit_setup(void)
27 {
28  return CURLE_OK;
29 }
30 
31 static void unit_stop(void)
32 {
33 
34 }
35 
36 static size_t print_httppost_callback(void *arg, const char *buf, size_t len)
37 {
38  fwrite(buf, len, 1, stdout);
39  (*(size_t *) arg) += len;
40  return len;
41 }
42 
44  int rc;
45  struct curl_httppost *post = NULL;
46  struct curl_httppost *last = NULL;
47  size_t total_size = 0;
48  char buffer[] = "test buffer";
49 
50  rc = curl_formadd(&post, &last, CURLFORM_COPYNAME, "name",
51  CURLFORM_COPYCONTENTS, "content", CURLFORM_END);
52 
53  fail_unless(rc == 0, "curl_formadd returned error");
54 
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");
58 
59  rc = curl_formadd(&post, &last, CURLFORM_COPYNAME, "htmlcode",
60  CURLFORM_COPYCONTENTS, "<HTML></HTML>",
61  CURLFORM_CONTENTTYPE, "text/html", CURLFORM_END);
62 
63  fail_unless(rc == 0, "curl_formadd returned error");
64 
65  rc = curl_formadd(&post, &last, CURLFORM_COPYNAME, "name_for_ptrcontent",
66  CURLFORM_PTRCONTENTS, buffer, CURLFORM_END);
67 
68  fail_unless(rc == 0, "curl_formadd returned error");
69 
71 
72  fail_unless(rc == 0, "curl_formget returned error");
73 
74  fail_unless(total_size == 488, "curl_formget got wrong size back");
75 
76  curl_formfree(post);
77 
78  /* start a new formpost with a file upload and formget */
79  post = last = NULL;
80 
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",
85  CURLFORM_END);
86 
87  fail_unless(rc == 0, "curl_formadd returned error");
88 
90  fail_unless(rc == 0, "curl_formget returned error");
91  fail_unless(total_size == 851, "curl_formget got wrong size back");
92 
93  curl_formfree(post);
94 
#define UNITTEST_START
Definition: curlcheck.h:86
struct curl_httppost * post
Definition: unit1308.c:45
static size_t print_httppost_callback(void *arg, const char *buf, size_t len)
Definition: unit1308.c:36
CURLcode
Definition: curl.h:454
UNITTEST_START int rc
Definition: unit1308.c:44
char buffer[]
Definition: unit1308.c:48
size_t len
Definition: curl_sasl.c:55
struct curl_httppost * last
Definition: unit1308.c:46
CURL_EXTERN CURLFORMcode curl_formadd(struct curl_httppost **httppost, struct curl_httppost **last_post,...)
Definition: formdata.c:743
static CURLcode unit_setup(void)
Definition: unit1308.c:26
Definition: curl.h:455
#define UNITTEST_STOP
Definition: curlcheck.h:95
CURL_EXTERN int curl_formget(struct curl_httppost *form, void *arg, curl_formget_callback append)
Definition: formdata.c:762
size_t total_size
Definition: unit1308.c:47
char buf[3]
Definition: unit1398.c:32
fail_unless(rc==0,"curl_formadd returned error")
curl_formfree(post)
size_t fwrite(const void *, size_t, size_t, FILE *)
static void unit_stop(void)
Definition: unit1308.c:31


rc_tagdetect_client
Author(s): Monika Florek-Jasinska , Raphael Schaller
autogenerated on Sat Feb 13 2021 03:42:16