From 1cb66a0e6d96961e1e7cd2ed88d757f211e7f7aa Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Sun, 23 Mar 2014 21:26:00 +0100 Subject: [PATCH] tests: Improve code coverage for rtsp-session-media Fixes https://bugzilla.gnome.org/show_bug.cgi?id=726940 --- tests/check/gst/sessionmedia.c | 288 ++++++++++++++++++++++++++++++++- 1 file changed, 284 insertions(+), 4 deletions(-) diff --git a/tests/check/gst/sessionmedia.c b/tests/check/gst/sessionmedia.c index c749a566c5..6bd9d26c45 100644 --- a/tests/check/gst/sessionmedia.c +++ b/tests/check/gst/sessionmedia.c @@ -23,7 +23,8 @@ #include #define TEST_PATH "rtsp://localhost:8554/test" -#define SETUP_URL TEST_PATH "/stream=0" +#define SETUP_URL1 TEST_PATH "/stream=0" +#define SETUP_URL2 TEST_PATH "/stream=1" GST_START_TEST (test_setup_url) { @@ -52,7 +53,7 @@ GST_START_TEST (test_setup_url) fail_unless (gst_rtsp_media_n_streams (media) == 1); stream = gst_rtsp_media_get_stream (media, 0); - fail_unless (stream != NULL); + fail_unless (GST_IS_RTSP_STREAM (stream)); pool = gst_rtsp_thread_pool_new (); thread = gst_rtsp_thread_pool_get_thread (pool, @@ -64,19 +65,21 @@ GST_START_TEST (test_setup_url) * note that gst_rtsp_session_media_new takes ownership of the media * thus no need to unref it at the bottom of function */ sm = gst_rtsp_session_media_new (TEST_PATH, media); - fail_unless (sm != NULL); + fail_unless (GST_IS_RTSP_SESSION_MEDIA (sm)); fail_unless (gst_rtsp_session_media_matches (sm, TEST_PATH, &match_len)); fail_unless (match_len == strlen (TEST_PATH)); + fail_unless (gst_rtsp_session_media_get_media (sm) == media); /* make a transport for the stream */ gst_rtsp_transport_new (&ct); trans = gst_rtsp_session_media_set_transport (sm, stream, ct); + fail_unless (gst_rtsp_session_media_get_transport (sm, 0) == trans); /* make sure there's no setup url stored initially */ fail_unless (gst_rtsp_stream_transport_get_url (trans) == NULL); /* now store a setup url and make sure it can be retrieved and that it's correct */ - fail_unless (gst_rtsp_url_parse (SETUP_URL, &setup_url) == GST_RTSP_OK); + fail_unless (gst_rtsp_url_parse (SETUP_URL1, &setup_url) == GST_RTSP_OK); gst_rtsp_stream_transport_set_url (trans, setup_url); url_str = gst_rtsp_url_get_request_uri (setup_url); @@ -102,6 +105,279 @@ GST_START_TEST (test_setup_url) GST_END_TEST; +GST_START_TEST (test_rtsp_state) +{ + GstRTSPMediaFactory *factory; + GstRTSPMedia *media; + GstRTSPUrl *url; + GstRTSPStream *stream; + GstRTSPThreadPool *pool; + GstRTSPThread *thread; + GstRTSPSessionMedia *sm; + + factory = gst_rtsp_media_factory_new (); + fail_if (gst_rtsp_media_factory_is_shared (factory)); + fail_unless (gst_rtsp_url_parse (TEST_PATH, &url) == GST_RTSP_OK); + + gst_rtsp_media_factory_set_launch (factory, + "( videotestsrc ! rtpvrawpay pt=96 name=pay0 )"); + + media = gst_rtsp_media_factory_construct (factory, url); + fail_unless (GST_IS_RTSP_MEDIA (media)); + + fail_unless (gst_rtsp_media_n_streams (media) == 1); + + stream = gst_rtsp_media_get_stream (media, 0); + fail_unless (GST_IS_RTSP_STREAM (stream)); + + pool = gst_rtsp_thread_pool_new (); + thread = gst_rtsp_thread_pool_get_thread (pool, + GST_RTSP_THREAD_TYPE_MEDIA, NULL); + + fail_unless (gst_rtsp_media_prepare (media, thread)); + + sm = gst_rtsp_session_media_new (TEST_PATH, media); + fail_unless (GST_IS_RTSP_SESSION_MEDIA (sm)); + fail_unless_equals_int (gst_rtsp_session_media_get_rtsp_state (sm), + GST_RTSP_STATE_INIT); + + gst_rtsp_session_media_set_rtsp_state (sm, GST_RTSP_STATE_READY); + fail_unless_equals_int (gst_rtsp_session_media_get_rtsp_state (sm), + GST_RTSP_STATE_READY); + + gst_rtsp_session_media_set_rtsp_state (sm, GST_RTSP_STATE_SEEKING); + fail_unless_equals_int (gst_rtsp_session_media_get_rtsp_state (sm), + GST_RTSP_STATE_SEEKING); + + gst_rtsp_session_media_set_rtsp_state (sm, GST_RTSP_STATE_PLAYING); + fail_unless_equals_int (gst_rtsp_session_media_get_rtsp_state (sm), + GST_RTSP_STATE_PLAYING); + + gst_rtsp_session_media_set_rtsp_state (sm, GST_RTSP_STATE_RECORDING); + fail_unless_equals_int (gst_rtsp_session_media_get_rtsp_state (sm), + GST_RTSP_STATE_RECORDING); + + fail_unless (gst_rtsp_media_unprepare (media)); + + gst_rtsp_url_free (url); + + g_object_unref (sm); + + g_object_unref (factory); + g_object_unref (pool); +} + +GST_END_TEST; + +GST_START_TEST (test_transports) +{ + GstRTSPMediaFactory *factory; + GstRTSPMedia *media; + GstRTSPUrl *url; + GstRTSPStream *stream1, *stream2; + GstRTSPThreadPool *pool; + GstRTSPThread *thread; + GstRTSPSessionMedia *sm; + GstRTSPStreamTransport *trans; + GstRTSPTransport *ct1, *ct2, *ct3, *ct4; + gint match_len; + + factory = gst_rtsp_media_factory_new (); + fail_if (gst_rtsp_media_factory_is_shared (factory)); + fail_unless (gst_rtsp_url_parse (TEST_PATH, &url) == GST_RTSP_OK); + + gst_rtsp_media_factory_set_launch (factory, + "( videotestsrc ! rtpvrawpay pt=96 name=pay0 audiotestsrc ! rtpgstpay pt=97 name=pay1 )"); + + media = gst_rtsp_media_factory_construct (factory, url); + fail_unless (GST_IS_RTSP_MEDIA (media)); + + fail_unless (gst_rtsp_media_n_streams (media) == 2); + + stream1 = gst_rtsp_media_get_stream (media, 0); + fail_unless (GST_IS_RTSP_STREAM (stream1)); + + stream2 = gst_rtsp_media_get_stream (media, 1); + fail_unless (GST_IS_RTSP_STREAM (stream2)); + + pool = gst_rtsp_thread_pool_new (); + thread = gst_rtsp_thread_pool_get_thread (pool, + GST_RTSP_THREAD_TYPE_MEDIA, NULL); + + fail_unless (gst_rtsp_media_prepare (media, thread)); + + sm = gst_rtsp_session_media_new (TEST_PATH, media); + fail_unless (GST_IS_RTSP_SESSION_MEDIA (sm)); + fail_unless (gst_rtsp_session_media_matches (sm, TEST_PATH, &match_len)); + fail_unless (match_len == strlen (TEST_PATH)); + + gst_rtsp_transport_new (&ct1); + trans = gst_rtsp_session_media_set_transport (sm, stream1, ct1); + fail_unless (gst_rtsp_session_media_get_transport (sm, 0) == trans); + + gst_rtsp_transport_new (&ct2); + trans = gst_rtsp_session_media_set_transport (sm, stream1, ct2); + fail_unless (gst_rtsp_session_media_get_transport (sm, 0) == trans); + + gst_rtsp_transport_new (&ct3); + trans = gst_rtsp_session_media_set_transport (sm, stream2, ct3); + fail_unless (gst_rtsp_session_media_get_transport (sm, 1) == trans); + + gst_rtsp_transport_new (&ct4); + trans = gst_rtsp_session_media_set_transport (sm, stream2, ct4); + fail_unless (gst_rtsp_session_media_get_transport (sm, 1) == trans); + + fail_unless (gst_rtsp_media_unprepare (media)); + + gst_rtsp_url_free (url); + + g_object_unref (sm); + + g_object_unref (factory); + g_object_unref (pool); +} + +GST_END_TEST; + +GST_START_TEST (test_time_and_rtpinfo) +{ + GstRTSPMediaFactory *factory; + GstRTSPMedia *media; + GstRTSPUrl *url; + GstRTSPStream *stream1, *stream2; + GstRTSPThreadPool *pool; + GstRTSPThread *thread; + GstRTSPSessionMedia *sm; + GstClockTime base_time; + gchar *rtpinfo; + GstRTSPTransport *ct1; + GstRTSPStreamTransport *trans; + GstRTSPUrl *setup_url; + gchar **streaminfo; + + factory = gst_rtsp_media_factory_new (); + fail_if (gst_rtsp_media_factory_is_shared (factory)); + fail_unless (gst_rtsp_url_parse (TEST_PATH, &url) == GST_RTSP_OK); + + gst_rtsp_media_factory_set_launch (factory, + "( videotestsrc do-timestamp=true timestamp-offset=0 ! rtpvrawpay pt=96 name=pay0 " + "audiotestsrc do-timestamp=true timestamp-offset=1000000000 ! rtpgstpay pt=97 name=pay1 )"); + + media = gst_rtsp_media_factory_construct (factory, url); + fail_unless (GST_IS_RTSP_MEDIA (media)); + + fail_unless (gst_rtsp_media_n_streams (media) == 2); + + stream1 = gst_rtsp_media_get_stream (media, 0); + fail_unless (GST_IS_RTSP_STREAM (stream1)); + + stream2 = gst_rtsp_media_get_stream (media, 1); + fail_unless (GST_IS_RTSP_STREAM (stream2)); + + pool = gst_rtsp_thread_pool_new (); + thread = gst_rtsp_thread_pool_get_thread (pool, + GST_RTSP_THREAD_TYPE_MEDIA, NULL); + + fail_unless (gst_rtsp_media_prepare (media, thread)); + + sm = gst_rtsp_session_media_new (TEST_PATH, media); + fail_unless (GST_IS_RTSP_SESSION_MEDIA (sm)); + + base_time = gst_rtsp_session_media_get_base_time (sm); + fail_unless_equals_int64 (base_time, 0); + + rtpinfo = gst_rtsp_session_media_get_rtpinfo (sm); + fail_unless (rtpinfo == NULL); + + gst_rtsp_transport_new (&ct1); + trans = gst_rtsp_session_media_set_transport (sm, stream1, ct1); + fail_unless (gst_rtsp_session_media_get_transport (sm, 0) == trans); + fail_unless (gst_rtsp_url_parse (SETUP_URL1, &setup_url) == GST_RTSP_OK); + gst_rtsp_stream_transport_set_url (trans, setup_url); + + base_time = gst_rtsp_session_media_get_base_time (sm); + fail_unless_equals_int64 (base_time, 0); + + rtpinfo = gst_rtsp_session_media_get_rtpinfo (sm); + streaminfo = g_strsplit (rtpinfo, ",", 1); + g_free (rtpinfo); + + fail_unless (g_strstr_len (streaminfo[0], -1, "url=") != NULL); + fail_unless (g_strstr_len (streaminfo[0], -1, "seq=") != NULL); + fail_unless (g_strstr_len (streaminfo[0], -1, "rtptime=") != NULL); + fail_unless (g_strstr_len (streaminfo[0], -1, SETUP_URL1) != NULL); + + g_strfreev (streaminfo); + + fail_unless (gst_rtsp_media_unprepare (media)); + + rtpinfo = gst_rtsp_session_media_get_rtpinfo (sm); + fail_unless (rtpinfo == NULL); + + gst_rtsp_url_free (url); + + g_object_unref (sm); + + g_object_unref (factory); + g_object_unref (pool); +} + +GST_END_TEST; + +GST_START_TEST (test_allocate_channels) +{ + GstRTSPMediaFactory *factory; + GstRTSPMedia *media; + GstRTSPUrl *url; + GstRTSPStream *stream; + GstRTSPThreadPool *pool; + GstRTSPThread *thread; + GstRTSPSessionMedia *sm; + GstRTSPRange range; + + factory = gst_rtsp_media_factory_new (); + fail_if (gst_rtsp_media_factory_is_shared (factory)); + fail_unless (gst_rtsp_url_parse (TEST_PATH, &url) == GST_RTSP_OK); + + gst_rtsp_media_factory_set_launch (factory, + "( videotestsrc ! rtpvrawpay pt=96 name=pay0 )"); + + media = gst_rtsp_media_factory_construct (factory, url); + fail_unless (GST_IS_RTSP_MEDIA (media)); + + fail_unless (gst_rtsp_media_n_streams (media) == 1); + + stream = gst_rtsp_media_get_stream (media, 0); + fail_unless (GST_IS_RTSP_STREAM (stream)); + + pool = gst_rtsp_thread_pool_new (); + thread = gst_rtsp_thread_pool_get_thread (pool, + GST_RTSP_THREAD_TYPE_MEDIA, NULL); + + fail_unless (gst_rtsp_media_prepare (media, thread)); + + sm = gst_rtsp_session_media_new (TEST_PATH, media); + fail_unless (GST_IS_RTSP_SESSION_MEDIA (sm)); + + fail_unless (gst_rtsp_session_media_alloc_channels (sm, &range)); + fail_unless_equals_int (range.min, 0); + fail_unless_equals_int (range.max, 1); + + fail_unless (gst_rtsp_session_media_alloc_channels (sm, &range)); + fail_unless_equals_int (range.min, 2); + fail_unless_equals_int (range.max, 3); + + fail_unless (gst_rtsp_media_unprepare (media)); + + gst_rtsp_url_free (url); + + g_object_unref (sm); + + g_object_unref (factory); + g_object_unref (pool); +} + +GST_END_TEST; static Suite * rtspsessionmedia_suite (void) { @@ -111,6 +387,10 @@ rtspsessionmedia_suite (void) suite_add_tcase (s, tc); tcase_set_timeout (tc, 20); tcase_add_test (tc, test_setup_url); + tcase_add_test (tc, test_rtsp_state); + tcase_add_test (tc, test_transports); + tcase_add_test (tc, test_time_and_rtpinfo); + tcase_add_test (tc, test_allocate_channels); return s; }