From: Sebastian Rasmussen Date: Sat, 22 Mar 2014 12:24:27 +0000 (+0100) Subject: tests: Improve code coverage of rtsp-threadpool tests X-Git-Tag: 1.19.3~495^2~840 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d9cfa3677bb2b4103be2e9439eced577893eda82;p=platform%2Fupstream%2Fgstreamer.git tests: Improve code coverage of rtsp-threadpool tests Fixes https://bugzilla.gnome.org/show_bug.cgi?id=726873 --- diff --git a/tests/check/gst/threadpool.c b/tests/check/gst/threadpool.c index 4c6ca79..c92e64f 100644 --- a/tests/check/gst/threadpool.c +++ b/tests/check/gst/threadpool.c @@ -29,13 +29,13 @@ GST_START_TEST (test_pool_get_thread) GstRTSPThread *thread; pool = gst_rtsp_thread_pool_new (); - fail_unless (pool != NULL); + fail_unless (GST_IS_RTSP_THREAD_POOL (pool)); thread = gst_rtsp_thread_pool_get_thread (pool, GST_RTSP_THREAD_TYPE_CLIENT, NULL); - fail_unless (thread != NULL); + fail_unless (GST_IS_RTSP_THREAD (thread)); /* one ref is hold by the pool */ - fail_unless (GST_MINI_OBJECT_REFCOUNT (thread) == 2); + fail_unless_equals_int (GST_MINI_OBJECT_REFCOUNT (thread), 2); gst_rtsp_thread_stop (thread); g_object_unref (pool); @@ -44,38 +44,176 @@ GST_START_TEST (test_pool_get_thread) GST_END_TEST; -GST_START_TEST (test_pool_get_thread_reuse) +GST_START_TEST (test_pool_get_media_thread) { GstRTSPThreadPool *pool; GstRTSPThread *thread; + + pool = gst_rtsp_thread_pool_new (); + fail_unless (GST_IS_RTSP_THREAD_POOL (pool)); + + thread = gst_rtsp_thread_pool_get_thread (pool, GST_RTSP_THREAD_TYPE_MEDIA, + NULL); + fail_unless (GST_IS_RTSP_THREAD (thread)); + /* one ref is hold by the pool */ + fail_unless_equals_int (GST_MINI_OBJECT_REFCOUNT (thread), 2); + + gst_rtsp_thread_stop (thread); + g_object_unref (pool); + gst_rtsp_thread_pool_cleanup (); +} + +GST_END_TEST; + +GST_START_TEST (test_pool_get_thread_reuse) +{ + GstRTSPThreadPool *pool; + GstRTSPThread *thread1; GstRTSPThread *thread2; pool = gst_rtsp_thread_pool_new (); - fail_unless (pool != NULL); + fail_unless (GST_IS_RTSP_THREAD_POOL (pool)); gst_rtsp_thread_pool_set_max_threads (pool, 1); - thread = gst_rtsp_thread_pool_get_thread (pool, GST_RTSP_THREAD_TYPE_CLIENT, + thread1 = gst_rtsp_thread_pool_get_thread (pool, GST_RTSP_THREAD_TYPE_CLIENT, NULL); - fail_unless (thread != NULL); + fail_unless (GST_IS_RTSP_THREAD (thread1)); thread2 = gst_rtsp_thread_pool_get_thread (pool, GST_RTSP_THREAD_TYPE_CLIENT, NULL); - fail_unless (thread2 != NULL); + fail_unless (GST_IS_RTSP_THREAD (thread2)); - fail_unless (thread == thread2); + fail_unless (thread2 == thread1); /* one ref is hold by the pool */ - fail_unless (GST_MINI_OBJECT_REFCOUNT (thread) == 3); + fail_unless_equals_int (GST_MINI_OBJECT_REFCOUNT (thread1), 3); - gst_rtsp_thread_stop (thread); + gst_rtsp_thread_stop (thread1); + gst_rtsp_thread_stop (thread2); + g_object_unref (pool); + + gst_rtsp_thread_pool_cleanup (); +} + +GST_END_TEST; + +static void +do_test_pool_max_thread (gboolean use_property) +{ + GstRTSPThreadPool *pool; + GstRTSPThread *thread1; + GstRTSPThread *thread2; + GstRTSPThread *thread3; + gint max_threads; + + pool = gst_rtsp_thread_pool_new (); + fail_unless (GST_IS_RTSP_THREAD_POOL (pool)); + + if (use_property) { + g_object_get (pool, "max-threads", &max_threads, NULL); + fail_unless_equals_int (max_threads, 1); + } else { + fail_unless_equals_int (gst_rtsp_thread_pool_get_max_threads (pool), 1); + } + + thread1 = gst_rtsp_thread_pool_get_thread (pool, GST_RTSP_THREAD_TYPE_CLIENT, + NULL); + fail_unless (GST_IS_RTSP_THREAD (thread1)); + + thread2 = gst_rtsp_thread_pool_get_thread (pool, GST_RTSP_THREAD_TYPE_CLIENT, + NULL); + fail_unless (GST_IS_RTSP_THREAD (thread2)); + + fail_unless (thread1 == thread2); + + gst_rtsp_thread_stop (thread1); gst_rtsp_thread_stop (thread2); + + if (use_property) { + g_object_set (pool, "max-threads", 2, NULL); + g_object_get (pool, "max-threads", &max_threads, NULL); + fail_unless_equals_int (max_threads, 2); + } else { + gst_rtsp_thread_pool_set_max_threads (pool, 2); + fail_unless_equals_int (gst_rtsp_thread_pool_get_max_threads (pool), 2); + } + + thread1 = gst_rtsp_thread_pool_get_thread (pool, GST_RTSP_THREAD_TYPE_CLIENT, + NULL); + fail_unless (GST_IS_RTSP_THREAD (thread1)); + + thread2 = gst_rtsp_thread_pool_get_thread (pool, GST_RTSP_THREAD_TYPE_CLIENT, + NULL); + fail_unless (GST_IS_RTSP_THREAD (thread2)); + + thread3 = gst_rtsp_thread_pool_get_thread (pool, GST_RTSP_THREAD_TYPE_CLIENT, + NULL); + fail_unless (GST_IS_RTSP_THREAD (thread3)); + + fail_unless (thread2 != thread1); + fail_unless (thread3 == thread2 || thread3 == thread1); + + gst_rtsp_thread_stop (thread1); + gst_rtsp_thread_stop (thread2); + gst_rtsp_thread_stop (thread3); + + if (use_property) { + g_object_set (pool, "max-threads", 0, NULL); + g_object_get (pool, "max-threads", &max_threads, NULL); + fail_unless_equals_int (max_threads, 0); + } else { + gst_rtsp_thread_pool_set_max_threads (pool, 0); + fail_unless_equals_int (gst_rtsp_thread_pool_get_max_threads (pool), 0); + } + + thread1 = gst_rtsp_thread_pool_get_thread (pool, GST_RTSP_THREAD_TYPE_CLIENT, + NULL); + fail_if (GST_IS_RTSP_THREAD (thread1)); + g_object_unref (pool); gst_rtsp_thread_pool_cleanup (); } +GST_START_TEST (test_pool_max_threads) +{ + do_test_pool_max_thread (FALSE); +} + +GST_END_TEST; + +GST_START_TEST (test_pool_max_threads_property) +{ + do_test_pool_max_thread (TRUE); +} + GST_END_TEST; +GST_START_TEST (test_pool_thread_copy) +{ + GstRTSPThreadPool *pool; + GstRTSPThread *thread1; + GstRTSPThread *thread2; + + pool = gst_rtsp_thread_pool_new (); + fail_unless (GST_IS_RTSP_THREAD_POOL (pool)); + + thread1 = gst_rtsp_thread_pool_get_thread (pool, GST_RTSP_THREAD_TYPE_CLIENT, + NULL); + fail_unless (GST_IS_RTSP_THREAD (thread1)); + fail_unless (GST_IS_MINI_OBJECT_TYPE (thread1, GST_TYPE_RTSP_THREAD)); + + thread2 = GST_RTSP_THREAD (gst_mini_object_copy (GST_MINI_OBJECT (thread1))); + fail_unless (GST_IS_RTSP_THREAD (thread2)); + fail_unless (GST_IS_MINI_OBJECT_TYPE (thread2, GST_TYPE_RTSP_THREAD)); + + gst_rtsp_thread_stop (thread1); + gst_rtsp_thread_stop (thread2); + g_object_unref (pool); + gst_rtsp_thread_pool_cleanup (); +} + +GST_END_TEST; static Suite * rtspthreadpool_suite (void) @@ -86,7 +224,11 @@ rtspthreadpool_suite (void) suite_add_tcase (s, tc); tcase_set_timeout (tc, 20); tcase_add_test (tc, test_pool_get_thread); + tcase_add_test (tc, test_pool_get_media_thread); tcase_add_test (tc, test_pool_get_thread_reuse); + tcase_add_test (tc, test_pool_max_threads); + tcase_add_test (tc, test_pool_max_threads_property); + tcase_add_test (tc, test_pool_thread_copy); return s; }