tests: add unit test for new-session

See https://bugzilla.gnome.org/show_bug.cgi?id=701587
This commit is contained in:
Patricia Muscalu 2013-06-20 12:18:23 +02:00 committed by Wim Taymans
parent 949f11c643
commit a8a051f780

View file

@ -22,6 +22,7 @@
#include <rtsp-client.h>
static gint cseq;
static guint expected_session_timeout = 60;
static gboolean
test_response_200 (GstRTSPClient * client, GstRTSPMessage * response,
@ -307,6 +308,7 @@ test_setup_response_200_multicast (GstRTSPClient * client,
gchar *str;
GstRTSPSessionPool *session_pool;
GstRTSPSession *session;
gchar **session_hdr_params;
fail_unless (expected_transport != NULL);
@ -331,12 +333,29 @@ test_setup_response_200_multicast (GstRTSPClient * client,
fail_unless (gst_rtsp_message_get_header (response, GST_RTSP_HDR_SESSION,
&str, 0) == GST_RTSP_OK);
session_hdr_params = g_strsplit (str, ";", -1);
/* session-id value */
fail_unless (session_hdr_params[0] != NULL);
if (expected_session_timeout != 60) {
/* session timeout param */
gchar *timeout_str = g_strdup_printf ("timeout=%u",
expected_session_timeout);
fail_unless (session_hdr_params[1] != NULL);
g_strstrip (session_hdr_params[1]);
fail_unless (g_strcmp0 (session_hdr_params[1], timeout_str) == 0);
g_free (timeout_str);
}
session_pool = gst_rtsp_client_get_session_pool (client);
fail_unless (session_pool != NULL);
fail_unless (gst_rtsp_session_pool_get_n_sessions (session_pool) == 1);
session = gst_rtsp_session_pool_find (session_pool, str);
session = gst_rtsp_session_pool_find (session_pool, session_hdr_params[0]);
g_strfreev (session_hdr_params);
fail_unless (session != NULL);
g_object_unref (session);
@ -404,6 +423,13 @@ GST_START_TEST (test_client_multicast_transport_404)
GST_END_TEST;
static void
new_session_cb (GObject * client, GstRTSPSession * session, gpointer user_data)
{
GST_DEBUG ("%p: new session %p", client, session);
gst_rtsp_session_set_timeout (session, expected_session_timeout);
}
GST_START_TEST (test_client_multicast_transport)
{
GstRTSPClient *client;
@ -412,6 +438,10 @@ GST_START_TEST (test_client_multicast_transport)
client = setup_multicast_client ();
expected_session_timeout = 20;
g_signal_connect (G_OBJECT (client), "new-session",
G_CALLBACK (new_session_cb), NULL);
/* simple SETUP with a valid URI and multicast */
fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_SETUP,
"rtsp://localhost/test/stream=0") == GST_RTSP_OK);
@ -428,7 +458,7 @@ GST_START_TEST (test_client_multicast_transport)
&request) == GST_RTSP_OK);
gst_rtsp_message_unset (&request);
expected_transport = NULL;
expected_session_timeout = 60;
g_object_unref (client);
}
@ -684,7 +714,8 @@ test_client_sdp (const gchar * launch_line, guint * bandwidth_val)
gst_rtsp_message_add_header (&request, GST_RTSP_HDR_CSEQ, str);
g_free (str);
gst_rtsp_client_set_send_func (client, test_response_sdp, (gpointer) bandwidth_val, NULL);
gst_rtsp_client_set_send_func (client, test_response_sdp,
(gpointer) bandwidth_val, NULL);
fail_unless (gst_rtsp_client_handle_message (client,
&request) == GST_RTSP_OK);
gst_rtsp_message_unset (&request);
@ -697,13 +728,15 @@ GST_START_TEST (test_client_sdp_with_max_bitrate_tag)
{
test_client_sdp ("videotestsrc "
"! taginject tags=\"maximum-bitrate=(uint)50000000\" "
"! video/x-raw,width=352,height=288 ! rtpgstpay name=pay0 pt=96", GUINT_TO_POINTER (50000));
"! video/x-raw,width=352,height=288 ! rtpgstpay name=pay0 pt=96",
GUINT_TO_POINTER (50000));
/* max-bitrate=0: no bandwidth line */
test_client_sdp ("videotestsrc "
"! taginject tags=\"maximum-bitrate=(uint)0\" "
"! video/x-raw,width=352,height=288 ! rtpgstpay name=pay0 pt=96", GUINT_TO_POINTER (0));
"! video/x-raw,width=352,height=288 ! rtpgstpay name=pay0 pt=96",
GUINT_TO_POINTER (0));
}
GST_END_TEST;
@ -712,12 +745,14 @@ GST_START_TEST (test_client_sdp_with_bitrate_tag)
{
test_client_sdp ("videotestsrc "
"! taginject tags=\"bitrate=(uint)7000000\" "
"! video/x-raw,width=352,height=288 ! rtpgstpay name=pay0 pt=96", GUINT_TO_POINTER (7000));
"! video/x-raw,width=352,height=288 ! rtpgstpay name=pay0 pt=96",
GUINT_TO_POINTER (7000));
/* bitrate=0: no bandwdith line */
test_client_sdp ("videotestsrc "
"! taginject tags=\"bitrate=(uint)0\" "
"! video/x-raw,width=352,height=288 ! rtpgstpay name=pay0 pt=96", GUINT_TO_POINTER (0));
"! video/x-raw,width=352,height=288 ! rtpgstpay name=pay0 pt=96",
GUINT_TO_POINTER (0));
}
GST_END_TEST;
@ -726,17 +761,20 @@ GST_START_TEST (test_client_sdp_with_max_bitrate_and_bitrate_tags)
{
test_client_sdp ("videotestsrc "
"! taginject tags=\"bitrate=(uint)7000000,maximum-bitrate=(uint)50000000\" "
"! video/x-raw,width=352,height=288 ! rtpgstpay name=pay0 pt=96", GUINT_TO_POINTER (50000));
"! video/x-raw,width=352,height=288 ! rtpgstpay name=pay0 pt=96",
GUINT_TO_POINTER (50000));
/* max-bitrate is zero: fallback to bitrate */
test_client_sdp ("videotestsrc "
"! taginject tags=\"bitrate=(uint)7000000,maximum-bitrate=(uint)0\" "
"! video/x-raw,width=352,height=288 ! rtpgstpay name=pay0 pt=96", GUINT_TO_POINTER (7000));
"! video/x-raw,width=352,height=288 ! rtpgstpay name=pay0 pt=96",
GUINT_TO_POINTER (7000));
/* max-bitrate=bitrate=0o: no bandwidth line */
test_client_sdp ("videotestsrc "
"! taginject tags=\"bitrate=(uint)0,maximum-bitrate=(uint)0\" "
"! video/x-raw,width=352,height=288 ! rtpgstpay name=pay0 pt=96", GUINT_TO_POINTER (0));
"! video/x-raw,width=352,height=288 ! rtpgstpay name=pay0 pt=96",
GUINT_TO_POINTER (0));
}
GST_END_TEST;