quickjs-tart

quickjs-based runtime for wallet-core logic
Log | Files | Refs | README | LICENSE

lib578.c (3104B)


      1 /***************************************************************************
      2  *                                  _   _ ____  _
      3  *  Project                     ___| | | |  _ \| |
      4  *                             / __| | | | |_) | |
      5  *                            | (__| |_| |  _ <| |___
      6  *                             \___|\___/|_| \_\_____|
      7  *
      8  * Copyright (C) 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.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  * SPDX-License-Identifier: curl
     22  *
     23  ***************************************************************************/
     24 #include "first.h"
     25 
     26 #include "memdebug.h"
     27 
     28 /* The size of data should be kept below MAX_INITIAL_POST_SIZE! */
     29 static char t578_testdata[] = "this is a short string.\n";
     30 
     31 static size_t data_size = CURL_ARRAYSIZE(t578_testdata);
     32 
     33 static int t578_progress_callback(void *clientp, double dltotal, double dlnow,
     34                                   double ultotal, double ulnow)
     35 {
     36   FILE *moo = fopen(libtest_arg2, "wb");
     37 
     38   (void)clientp; /* UNUSED */
     39   (void)dltotal; /* UNUSED */
     40   (void)dlnow; /* UNUSED */
     41 
     42   if(moo) {
     43     if((size_t)ultotal == data_size && (size_t)ulnow == data_size)
     44       curl_mfprintf(moo, "PASSED, UL data matched data size\n");
     45     else
     46       curl_mfprintf(moo, "Progress callback called with UL %f out of %f\n",
     47                     ulnow, ultotal);
     48     fclose(moo);
     49   }
     50   return 0;
     51 }
     52 
     53 static CURLcode test_lib578(char *URL)
     54 {
     55   CURL *curl;
     56   CURLcode res = CURLE_OK;
     57 
     58   if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
     59     curl_mfprintf(stderr, "curl_global_init() failed\n");
     60     return TEST_ERR_MAJOR_BAD;
     61   }
     62 
     63   curl = curl_easy_init();
     64   if(!curl) {
     65     curl_mfprintf(stderr, "curl_easy_init() failed\n");
     66     curl_global_cleanup();
     67     return TEST_ERR_MAJOR_BAD;
     68   }
     69 
     70   /* First set the URL that is about to receive our POST. */
     71   test_setopt(curl, CURLOPT_URL, URL);
     72 
     73   /* Now specify we want to POST data */
     74   test_setopt(curl, CURLOPT_POST, 1L);
     75 
     76   /* Set the expected POST size */
     77   test_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)data_size);
     78   test_setopt(curl, CURLOPT_POSTFIELDS, t578_testdata);
     79 
     80   /* we want to use our own progress function */
     81   test_setopt(curl, CURLOPT_NOPROGRESS, 0L);
     82   test_setopt(curl, CURLOPT_PROGRESSFUNCTION, t578_progress_callback);
     83 
     84   /* get verbose debug output please */
     85   test_setopt(curl, CURLOPT_VERBOSE, 1L);
     86 
     87   /* include headers in the output */
     88   test_setopt(curl, CURLOPT_HEADER, 1L);
     89 
     90   /* Perform the request, res will get the return code */
     91   res = curl_easy_perform(curl);
     92 
     93 test_cleanup:
     94 
     95   /* always cleanup */
     96   curl_easy_cleanup(curl);
     97   curl_global_cleanup();
     98 
     99   return res;
    100 }