2 * Copyright (C) 2012 Wim Taymans <wim.taymans@gmail.com>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
20 #include <gst/check/gstcheck.h>
22 #include <rtsp-client.h>
27 test_option_response_200 (GstRTSPClient * client, GstRTSPMessage * response,
28 gboolean close, gpointer user_data)
30 GstRTSPStatusCode code;
32 GstRTSPVersion version;
34 GstRTSPMethod methods;
36 fail_unless (gst_rtsp_message_get_type (response) ==
37 GST_RTSP_MESSAGE_RESPONSE);
39 gst_rtsp_message_dump (response);
40 fail_unless (gst_rtsp_message_parse_response (response, &code, &reason,
43 fail_unless (code == GST_RTSP_STS_OK);
44 fail_unless (g_str_equal (reason, "OK"));
45 fail_unless (version == GST_RTSP_VERSION_1_0);
47 fail_unless (gst_rtsp_message_get_header (response, GST_RTSP_HDR_CSEQ, &str,
49 fail_unless (atoi (str) == cseq++);
51 fail_unless (gst_rtsp_message_get_header (response, GST_RTSP_HDR_PUBLIC, &str,
54 methods = gst_rtsp_options_from_text (str);
55 fail_if (methods == 0);
56 fail_unless (methods == (GST_RTSP_DESCRIBE |
61 GST_RTSP_GET_PARAMETER | GST_RTSP_SET_PARAMETER | GST_RTSP_TEARDOWN));
67 test_option_response_454 (GstRTSPClient * client, GstRTSPMessage * response,
68 gboolean close, gpointer user_data)
70 GstRTSPStatusCode code;
72 GstRTSPVersion version;
74 fail_unless (gst_rtsp_message_get_type (response) ==
75 GST_RTSP_MESSAGE_RESPONSE);
76 gst_rtsp_message_dump (response);
78 fail_unless (gst_rtsp_message_parse_response (response, &code, &reason,
81 fail_unless (code == GST_RTSP_STS_SESSION_NOT_FOUND);
82 fail_unless (g_str_equal (reason, "Session Not Found"));
83 fail_unless (version == GST_RTSP_VERSION_1_0);
88 GST_START_TEST (test_options)
90 GstRTSPClient *client;
91 GstRTSPMessage request = { 0, };
94 client = gst_rtsp_client_new ();
97 fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_OPTIONS,
98 "rtsp://localhost/test") == GST_RTSP_OK);
99 str = g_strdup_printf ("%d", cseq);
100 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_CSEQ, str);
103 gst_rtsp_client_set_send_func (client, test_option_response_200, NULL, NULL);
104 gst_rtsp_message_dump (&request);
105 fail_unless (gst_rtsp_client_handle_message (client,
106 &request) == GST_RTSP_OK);
107 gst_rtsp_message_unset (&request);
109 /* OPTIONS with unknown session id */
110 fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_OPTIONS,
111 "rtsp://localhost/test") == GST_RTSP_OK);
112 str = g_strdup_printf ("%d", cseq);
113 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_CSEQ, str);
115 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_SESSION, "foobar");
117 gst_rtsp_client_set_send_func (client, test_option_response_454, NULL, NULL);
118 gst_rtsp_message_dump (&request);
119 fail_unless (gst_rtsp_client_handle_message (client,
120 &request) == GST_RTSP_OK);
122 gst_rtsp_message_unset (&request);
124 g_object_unref (client);
130 rtspclient_suite (void)
132 Suite *s = suite_create ("rtspclient");
133 TCase *tc = tcase_create ("general");
135 suite_add_tcase (s, tc);
136 tcase_set_timeout (tc, 20);
137 tcase_add_test (tc, test_options);
142 GST_CHECK_MAIN (rtspclient);