2dc57b7612ba5ee160b259d2ec7e143821e38c63
[platform/upstream/curl.git] / tests / libtest / lib570.c
1 /***************************************************************************
2  *                                  _   _ ____  _
3  *  Project                     ___| | | |  _ \| |
4  *                             / __| | | | |_) | |
5  *                            | (__| |_| |  _ <| |___
6  *                             \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) 1998 - 2016, 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 "test.h"
23 #include "memdebug.h"
24
25 /* build request url */
26 static char *suburl(const char *base, int i)
27 {
28   return curl_maprintf("%s%.4d", base, i);
29 }
30
31 int test(char *URL)
32 {
33   int res;
34   CURL *curl;
35   int request=1;
36   char *stream_uri = NULL;
37
38   if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
39     fprintf(stderr, "curl_global_init() failed\n");
40     return TEST_ERR_MAJOR_BAD;
41   }
42
43   if((curl = curl_easy_init()) == NULL) {
44     fprintf(stderr, "curl_easy_init() failed\n");
45     curl_global_cleanup();
46     return TEST_ERR_MAJOR_BAD;
47   }
48
49   test_setopt(curl, CURLOPT_HEADERDATA, stdout);
50   test_setopt(curl, CURLOPT_WRITEDATA, stdout);
51   test_setopt(curl, CURLOPT_VERBOSE, 1L);
52
53   test_setopt(curl, CURLOPT_URL, URL);
54
55   test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_OPTIONS);
56
57   if((stream_uri = suburl(URL, request++)) == NULL) {
58     res = TEST_ERR_MAJOR_BAD;
59     goto test_cleanup;
60   }
61   test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
62   free(stream_uri);
63   stream_uri = NULL;
64
65   res = curl_easy_perform(curl);
66   if(res != (int)CURLE_RTSP_CSEQ_ERROR) {
67     fprintf(stderr, "Failed to detect CSeq mismatch");
68     res = TEST_ERR_MAJOR_BAD;
69     goto test_cleanup;
70   }
71
72   test_setopt(curl, CURLOPT_RTSP_CLIENT_CSEQ, 999L);
73   test_setopt(curl, CURLOPT_RTSP_TRANSPORT,
74                     "RAW/RAW/UDP;unicast;client_port=3056-3057");
75   test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_SETUP);
76
77   if((stream_uri = suburl(URL, request++)) == NULL) {
78     res = TEST_ERR_MAJOR_BAD;
79     goto test_cleanup;
80   }
81   test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
82   free(stream_uri);
83   stream_uri = NULL;
84
85   res = curl_easy_perform(curl);
86   if(res)
87     goto test_cleanup;
88
89   test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_PLAY);
90
91   if((stream_uri = suburl(URL, request++)) == NULL) {
92     res = TEST_ERR_MAJOR_BAD;
93     goto test_cleanup;
94   }
95   test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
96   free(stream_uri);
97   stream_uri = NULL;
98
99   res = curl_easy_perform(curl);
100   if(res != CURLE_RTSP_SESSION_ERROR) {
101     fprintf(stderr, "Failed to detect a Session ID mismatch");
102   }
103
104 test_cleanup:
105   free(stream_uri);
106
107   curl_easy_cleanup(curl);
108   curl_global_cleanup();
109
110   return res;
111 }
112