File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / curl / tests / unit / unit1308.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Wed Jun 3 10:01:16 2020 UTC (5 years ago) by misho
Branches: curl, MAIN
CVS tags: v7_70_0p4, HEAD
curl

    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: 
   43: UNITTEST_START
   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: 
   70:   rc = curl_formget(post, &total_size, print_httppost_callback);
   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: 
   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");
   92: 
   93:   curl_formfree(post);
   94: 
   95: UNITTEST_STOP

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>