summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Rasmussen <sebras@hotmail.com>2014-03-22 13:24:27 +0100
committerTim-Philipp Müller <tim@centricular.com>2014-03-24 00:44:55 +0000
commitd9cfa3677bb2b4103be2e9439eced577893eda82 (patch)
treee7f73cd56059efe17d41b5cc0e1cc5b7cd87fb7b
parent1cb66a0e6d96961e1e7cd2ed88d757f211e7f7aa (diff)
tests: Improve code coverage of rtsp-threadpool tests
Fixes https://bugzilla.gnome.org/show_bug.cgi?id=726873
-rw-r--r--tests/check/gst/threadpool.c164
1 files changed, 153 insertions, 11 deletions
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;
}