Git init
[external/curl.git] / tests / libtest / lib569.c
1 /*****************************************************************************
2  *                                  _   _ ____  _
3  *  Project                     ___| | | |  _ \| |
4  *                             / __| | | | |_) | |
5  *                            | (__| |_| |  _ <| |___
6  *                             \___|\___/|_| \_\_____|
7  *
8  */
9
10 #include "test.h"
11
12 #include <curl/mprintf.h>
13
14 #include "memdebug.h"
15
16 /* build request url */
17 static char *suburl(const char *base, int i)
18 {
19   return curl_maprintf("%s%.4d", base, i);
20 }
21
22 /*
23  * Test Session ID capture
24  */
25 int test(char *URL)
26 {
27   int res;
28   CURL *curl;
29   char *stream_uri = NULL;
30   char *rtsp_session_id;
31   int request=1;
32   int i;
33   FILE *idfile = NULL;
34
35   idfile = fopen(libtest_arg2, "wb");
36   if(idfile == NULL) {
37     fprintf(stderr, "couldn't open the Session ID File\n");
38     return TEST_ERR_MAJOR_BAD;
39   }
40
41   if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
42     fprintf(stderr, "curl_global_init() failed\n");
43     fclose(idfile);
44     return TEST_ERR_MAJOR_BAD;
45   }
46
47   if ((curl = curl_easy_init()) == NULL) {
48     fprintf(stderr, "curl_easy_init() failed\n");
49     curl_global_cleanup();
50     fclose(idfile);
51     return TEST_ERR_MAJOR_BAD;
52   }
53
54   test_setopt(curl, CURLOPT_HEADERDATA, stdout);
55   test_setopt(curl, CURLOPT_WRITEDATA, stdout);
56   test_setopt(curl, CURLOPT_VERBOSE, 1L);
57
58   test_setopt(curl, CURLOPT_URL, URL);
59
60   test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_SETUP);
61   res = curl_easy_perform(curl);
62   if(res != (int)CURLE_BAD_FUNCTION_ARGUMENT) {
63     fprintf(stderr, "This should have failed. "
64             "Cannot setup without a Transport: header");
65     res = TEST_ERR_MAJOR_BAD;
66     goto test_cleanup;
67   }
68
69   /* Go through the various Session IDs */
70   for(i = 0; i < 3; i++) {
71     if((stream_uri = suburl(URL, request++)) == NULL) {
72       res = TEST_ERR_MAJOR_BAD;
73       goto test_cleanup;
74     }
75     test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
76     free(stream_uri);
77     stream_uri = NULL;
78
79     test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_SETUP);
80     test_setopt(curl, CURLOPT_RTSP_TRANSPORT, "Fake/NotReal/JustATest;foo=baz");
81     res = curl_easy_perform(curl);
82     if(res)
83       goto test_cleanup;
84
85     curl_easy_getinfo(curl, CURLINFO_RTSP_SESSION_ID, &rtsp_session_id);
86     fprintf(idfile, "Got Session ID: [%s]\n", rtsp_session_id);
87     rtsp_session_id = NULL;
88
89     if((stream_uri = suburl(URL, request++)) == NULL) {
90       res = TEST_ERR_MAJOR_BAD;
91       goto test_cleanup;
92     }
93     test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
94     free(stream_uri);
95     stream_uri = NULL;
96
97     test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_TEARDOWN);
98     res = curl_easy_perform(curl);
99
100     /* Clear for the next go-round */
101     test_setopt(curl, CURLOPT_RTSP_SESSION_ID, NULL);
102   }
103
104 test_cleanup:
105
106   if(idfile)
107     fclose(idfile);
108
109   if(stream_uri)
110     free(stream_uri);
111
112   curl_easy_cleanup(curl);
113   curl_global_cleanup();
114
115   return res;
116 }
117