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> #include <rtsp-client.h>
static gint cseq; static gint cseq;
static guint expected_session_timeout = 60;
static gboolean static gboolean
test_response_200 (GstRTSPClient * client, GstRTSPMessage * response, test_response_200 (GstRTSPClient * client, GstRTSPMessage * response,
@ -273,7 +274,7 @@ GST_START_TEST (test_describe)
/* simple DESCRIBE for an existing url */ /* simple DESCRIBE for an existing url */
client = setup_client (NULL); client = setup_client (NULL);
fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_DESCRIBE, fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_DESCRIBE,
"rtsp://localhost/test") == GST_RTSP_OK); "rtsp://localhost/test") == GST_RTSP_OK);
str = g_strdup_printf ("%d", cseq); str = g_strdup_printf ("%d", cseq);
gst_rtsp_message_add_header (&request, GST_RTSP_HDR_CSEQ, str); gst_rtsp_message_add_header (&request, GST_RTSP_HDR_CSEQ, str);
g_free (str); g_free (str);
@ -307,6 +308,7 @@ test_setup_response_200_multicast (GstRTSPClient * client,
gchar *str; gchar *str;
GstRTSPSessionPool *session_pool; GstRTSPSessionPool *session_pool;
GstRTSPSession *session; GstRTSPSession *session;
gchar **session_hdr_params;
fail_unless (expected_transport != NULL); 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, fail_unless (gst_rtsp_message_get_header (response, GST_RTSP_HDR_SESSION,
&str, 0) == GST_RTSP_OK); &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); session_pool = gst_rtsp_client_get_session_pool (client);
fail_unless (session_pool != NULL); fail_unless (session_pool != NULL);
fail_unless (gst_rtsp_session_pool_get_n_sessions (session_pool) == 1); 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); fail_unless (session != NULL);
g_object_unref (session); g_object_unref (session);
@ -404,6 +423,13 @@ GST_START_TEST (test_client_multicast_transport_404)
GST_END_TEST; 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) GST_START_TEST (test_client_multicast_transport)
{ {
GstRTSPClient *client; GstRTSPClient *client;
@ -412,6 +438,10 @@ GST_START_TEST (test_client_multicast_transport)
client = setup_multicast_client (); 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 */ /* simple SETUP with a valid URI and multicast */
fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_SETUP, fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_SETUP,
"rtsp://localhost/test/stream=0") == GST_RTSP_OK); "rtsp://localhost/test/stream=0") == GST_RTSP_OK);
@ -428,7 +458,7 @@ GST_START_TEST (test_client_multicast_transport)
&request) == GST_RTSP_OK); &request) == GST_RTSP_OK);
gst_rtsp_message_unset (&request); gst_rtsp_message_unset (&request);
expected_transport = NULL; expected_transport = NULL;
expected_session_timeout = 60;
g_object_unref (client); g_object_unref (client);
} }
@ -655,13 +685,13 @@ test_response_sdp (GstRTSPClient * client, GstRTSPMessage * response,
/* media bandwidth */ /* media bandwidth */
if (bandwidth_val) { if (bandwidth_val) {
fail_unless (gst_sdp_media_bandwidths_len (sdp_media) == 1); fail_unless (gst_sdp_media_bandwidths_len (sdp_media) == 1);
bw = gst_sdp_media_get_bandwidth (sdp_media, 0); bw = gst_sdp_media_get_bandwidth (sdp_media, 0);
fail_unless (bw != NULL); fail_unless (bw != NULL);
fail_unless (g_strcmp0 (bw->bwtype, "AS") == 0); fail_unless (g_strcmp0 (bw->bwtype, "AS") == 0);
fail_unless (bw->bandwidth == bandwidth_val); fail_unless (bw->bandwidth == bandwidth_val);
} else { } else {
fail_unless (gst_sdp_media_bandwidths_len (sdp_media) == 0); fail_unless (gst_sdp_media_bandwidths_len (sdp_media) == 0);
} }
gst_sdp_message_free (sdp_msg); gst_sdp_message_free (sdp_msg);
@ -679,12 +709,13 @@ test_client_sdp (const gchar * launch_line, guint * bandwidth_val)
/* simple DESCRIBE for an existing url */ /* simple DESCRIBE for an existing url */
client = setup_client (launch_line); client = setup_client (launch_line);
fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_DESCRIBE, fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_DESCRIBE,
"rtsp://localhost/test") == GST_RTSP_OK); "rtsp://localhost/test") == GST_RTSP_OK);
str = g_strdup_printf ("%d", cseq); str = g_strdup_printf ("%d", cseq);
gst_rtsp_message_add_header (&request, GST_RTSP_HDR_CSEQ, str); gst_rtsp_message_add_header (&request, GST_RTSP_HDR_CSEQ, str);
g_free (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, fail_unless (gst_rtsp_client_handle_message (client,
&request) == GST_RTSP_OK); &request) == GST_RTSP_OK);
gst_rtsp_message_unset (&request); gst_rtsp_message_unset (&request);
@ -697,13 +728,15 @@ GST_START_TEST (test_client_sdp_with_max_bitrate_tag)
{ {
test_client_sdp ("videotestsrc " test_client_sdp ("videotestsrc "
"! taginject tags=\"maximum-bitrate=(uint)50000000\" " "! 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 */ /* max-bitrate=0: no bandwidth line */
test_client_sdp ("videotestsrc " test_client_sdp ("videotestsrc "
"! taginject tags=\"maximum-bitrate=(uint)0\" " "! 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; GST_END_TEST;
@ -712,12 +745,14 @@ GST_START_TEST (test_client_sdp_with_bitrate_tag)
{ {
test_client_sdp ("videotestsrc " test_client_sdp ("videotestsrc "
"! taginject tags=\"bitrate=(uint)7000000\" " "! 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 */ /* bitrate=0: no bandwdith line */
test_client_sdp ("videotestsrc " test_client_sdp ("videotestsrc "
"! taginject tags=\"bitrate=(uint)0\" " "! 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; GST_END_TEST;
@ -726,17 +761,20 @@ GST_START_TEST (test_client_sdp_with_max_bitrate_and_bitrate_tags)
{ {
test_client_sdp ("videotestsrc " test_client_sdp ("videotestsrc "
"! taginject tags=\"bitrate=(uint)7000000,maximum-bitrate=(uint)50000000\" " "! 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 */ /* max-bitrate is zero: fallback to bitrate */
test_client_sdp ("videotestsrc " test_client_sdp ("videotestsrc "
"! taginject tags=\"bitrate=(uint)7000000,maximum-bitrate=(uint)0\" " "! 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 */ /* max-bitrate=bitrate=0o: no bandwidth line */
test_client_sdp ("videotestsrc " test_client_sdp ("videotestsrc "
"! taginject tags=\"bitrate=(uint)0,maximum-bitrate=(uint)0\" " "! 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; GST_END_TEST;