unit1308.c
Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                  _   _ ____  _
00003  *  Project                     ___| | | |  _ \| |
00004  *                             / __| | | | |_) | |
00005  *                            | (__| |_| |  _ <| |___
00006  *                             \___|\___/|_| \_\_____|
00007  *
00008  * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
00009  *
00010  * This software is licensed as described in the file COPYING, which
00011  * you should have received as part of this distribution. The terms
00012  * are also available at https://curl.haxx.se/docs/copyright.html.
00013  *
00014  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
00015  * copies of the Software, and permit persons to whom the Software is
00016  * furnished to do so, under the terms of the COPYING file.
00017  *
00018  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
00019  * KIND, either express or implied.
00020  *
00021  ***************************************************************************/
00022 #include "curlcheck.h"
00023 
00024 #include <curl/curl.h>
00025 
00026 static CURLcode unit_setup(void)
00027 {
00028   return CURLE_OK;
00029 }
00030 
00031 static void unit_stop(void)
00032 {
00033 
00034 }
00035 
00036 static size_t print_httppost_callback(void *arg, const char *buf, size_t len)
00037 {
00038   fwrite(buf, len, 1, stdout);
00039   (*(size_t *) arg) += len;
00040   return len;
00041 }
00042 
00043 UNITTEST_START
00044   int rc;
00045   struct curl_httppost *post = NULL;
00046   struct curl_httppost *last = NULL;
00047   size_t total_size = 0;
00048   char buffer[] = "test buffer";
00049 
00050   rc = curl_formadd(&post, &last, CURLFORM_COPYNAME, "name",
00051                     CURLFORM_COPYCONTENTS, "content", CURLFORM_END);
00052 
00053   fail_unless(rc == 0, "curl_formadd returned error");
00054 
00055   /* after the first curl_formadd when there's a single entry, both pointers
00056      should point to the same struct */
00057   fail_unless(post == last, "post and last weren't the same");
00058 
00059   rc = curl_formadd(&post, &last, CURLFORM_COPYNAME, "htmlcode",
00060                     CURLFORM_COPYCONTENTS, "<HTML></HTML>",
00061                     CURLFORM_CONTENTTYPE, "text/html", CURLFORM_END);
00062 
00063   fail_unless(rc == 0, "curl_formadd returned error");
00064 
00065   rc = curl_formadd(&post, &last, CURLFORM_COPYNAME, "name_for_ptrcontent",
00066                    CURLFORM_PTRCONTENTS, buffer, CURLFORM_END);
00067 
00068   fail_unless(rc == 0, "curl_formadd returned error");
00069 
00070   rc = curl_formget(post, &total_size, print_httppost_callback);
00071 
00072   fail_unless(rc == 0, "curl_formget returned error");
00073 
00074   fail_unless(total_size == 486, "curl_formget got wrong size back");
00075 
00076   curl_formfree(post);
00077 
00078   /* start a new formpost with a file upload and formget */
00079   post = last = NULL;
00080 
00081   rc = curl_formadd(&post, &last,
00082                     CURLFORM_PTRNAME, "name of file field",
00083                     CURLFORM_FILE, "log/test-1308",
00084                     CURLFORM_FILENAME, "custom named file",
00085                     CURLFORM_END);
00086 
00087   fail_unless(rc == 0, "curl_formadd returned error");
00088 
00089   rc = curl_formget(post, &total_size, print_httppost_callback);
00090   fail_unless(rc == 0, "curl_formget returned error");
00091   fail_unless(total_size == 847, "curl_formget got wrong size back");
00092 
00093   curl_formfree(post);
00094 
00095 UNITTEST_STOP


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:07