quickjs-tart

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

lib569.c (3648B)


      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 "testutil.h"
     27 #include "memdebug.h"
     28 
     29 /*
     30  * Test Session ID capture
     31  */
     32 static CURLcode test_lib569(char *URL)
     33 {
     34   CURLcode res;
     35   CURL *curl;
     36   char *stream_uri = NULL;
     37   char *rtsp_session_id;
     38   int request = 1;
     39   int i;
     40 
     41   FILE *idfile = fopen(libtest_arg2, "wb");
     42   if(!idfile) {
     43     curl_mfprintf(stderr, "couldn't open the Session ID File\n");
     44     return TEST_ERR_MAJOR_BAD;
     45   }
     46 
     47   if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
     48     curl_mfprintf(stderr, "curl_global_init() failed\n");
     49     fclose(idfile);
     50     return TEST_ERR_MAJOR_BAD;
     51   }
     52 
     53   curl = curl_easy_init();
     54   if(!curl) {
     55     curl_mfprintf(stderr, "curl_easy_init() failed\n");
     56     curl_global_cleanup();
     57     fclose(idfile);
     58     return TEST_ERR_MAJOR_BAD;
     59   }
     60 
     61   test_setopt(curl, CURLOPT_HEADERDATA, stdout);
     62   test_setopt(curl, CURLOPT_WRITEDATA, stdout);
     63   test_setopt(curl, CURLOPT_VERBOSE, 1L);
     64 
     65   test_setopt(curl, CURLOPT_URL, URL);
     66 
     67   test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_SETUP);
     68   res = curl_easy_perform(curl);
     69   if(res != (int)CURLE_BAD_FUNCTION_ARGUMENT) {
     70     curl_mfprintf(stderr, "This should have failed. "
     71                   "Cannot setup without a Transport: header");
     72     res = TEST_ERR_MAJOR_BAD;
     73     goto test_cleanup;
     74   }
     75 
     76   /* Go through the various Session IDs */
     77   for(i = 0; i < 3; i++) {
     78     stream_uri = tutil_suburl(URL, request++);
     79     if(!stream_uri) {
     80       res = TEST_ERR_MAJOR_BAD;
     81       goto test_cleanup;
     82     }
     83     test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
     84     curl_free(stream_uri);
     85     stream_uri = NULL;
     86 
     87     test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_SETUP);
     88     test_setopt(curl, CURLOPT_RTSP_TRANSPORT,
     89                 "Fake/NotReal/JustATest;foo=baz");
     90     res = curl_easy_perform(curl);
     91     if(res)
     92       goto test_cleanup;
     93 
     94     curl_easy_getinfo(curl, CURLINFO_RTSP_SESSION_ID, &rtsp_session_id);
     95     curl_mfprintf(idfile, "Got Session ID: [%s]\n", rtsp_session_id);
     96     rtsp_session_id = NULL;
     97 
     98     stream_uri = tutil_suburl(URL, request++);
     99     if(!stream_uri) {
    100       res = TEST_ERR_MAJOR_BAD;
    101       goto test_cleanup;
    102     }
    103     test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
    104     curl_free(stream_uri);
    105     stream_uri = NULL;
    106 
    107     test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_TEARDOWN);
    108     res = curl_easy_perform(curl);
    109     if(res)
    110       goto test_cleanup;
    111 
    112     /* Clear for the next go-round */
    113     test_setopt(curl, CURLOPT_RTSP_SESSION_ID, NULL);
    114   }
    115 
    116 test_cleanup:
    117 
    118   if(idfile)
    119     fclose(idfile);
    120 
    121   curl_free(stream_uri);
    122   curl_easy_cleanup(curl);
    123   curl_global_cleanup();
    124 
    125   return res;
    126 }