2 * unit tests for GstRTSPThreadPool
3 * Copyright (C) 2013 Axis Communications <dev-gstreamer at axis dot com>
4 * @author Ognyan Tonchev <ognyan at axis dot com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
22 #include <gst/check/gstcheck.h>
24 #include <rtsp-thread-pool.h>
26 GST_START_TEST (test_pool_get_thread)
28 GstRTSPThreadPool *pool;
29 GstRTSPThread *thread;
31 pool = gst_rtsp_thread_pool_new ();
32 fail_unless (GST_IS_RTSP_THREAD_POOL (pool));
34 thread = gst_rtsp_thread_pool_get_thread (pool, GST_RTSP_THREAD_TYPE_CLIENT,
36 fail_unless (GST_IS_RTSP_THREAD (thread));
37 /* one ref is hold by the pool */
38 fail_unless_equals_int (GST_MINI_OBJECT_REFCOUNT (thread), 2);
40 gst_rtsp_thread_stop (thread);
41 g_object_unref (pool);
42 gst_rtsp_thread_pool_cleanup ();
47 GST_START_TEST (test_pool_get_media_thread)
49 GstRTSPThreadPool *pool;
50 GstRTSPThread *thread;
52 pool = gst_rtsp_thread_pool_new ();
53 fail_unless (GST_IS_RTSP_THREAD_POOL (pool));
55 thread = gst_rtsp_thread_pool_get_thread (pool, GST_RTSP_THREAD_TYPE_MEDIA,
57 fail_unless (GST_IS_RTSP_THREAD (thread));
58 /* one ref is hold by the pool */
59 fail_unless_equals_int (GST_MINI_OBJECT_REFCOUNT (thread), 2);
61 gst_rtsp_thread_stop (thread);
62 g_object_unref (pool);
63 gst_rtsp_thread_pool_cleanup ();
68 GST_START_TEST (test_pool_get_thread_reuse)
70 GstRTSPThreadPool *pool;
71 GstRTSPThread *thread1;
72 GstRTSPThread *thread2;
74 pool = gst_rtsp_thread_pool_new ();
75 fail_unless (GST_IS_RTSP_THREAD_POOL (pool));
77 gst_rtsp_thread_pool_set_max_threads (pool, 1);
79 thread1 = gst_rtsp_thread_pool_get_thread (pool, GST_RTSP_THREAD_TYPE_CLIENT,
81 fail_unless (GST_IS_RTSP_THREAD (thread1));
83 thread2 = gst_rtsp_thread_pool_get_thread (pool, GST_RTSP_THREAD_TYPE_CLIENT,
85 fail_unless (GST_IS_RTSP_THREAD (thread2));
87 fail_unless (thread2 == thread1);
88 /* one ref is hold by the pool */
89 fail_unless_equals_int (GST_MINI_OBJECT_REFCOUNT (thread1), 3);
91 gst_rtsp_thread_stop (thread1);
92 gst_rtsp_thread_stop (thread2);
93 g_object_unref (pool);
95 gst_rtsp_thread_pool_cleanup ();
101 do_test_pool_max_thread (gboolean use_property)
103 GstRTSPThreadPool *pool;
104 GstRTSPThread *thread1;
105 GstRTSPThread *thread2;
106 GstRTSPThread *thread3;
109 pool = gst_rtsp_thread_pool_new ();
110 fail_unless (GST_IS_RTSP_THREAD_POOL (pool));
113 g_object_get (pool, "max-threads", &max_threads, NULL);
114 fail_unless_equals_int (max_threads, 1);
116 fail_unless_equals_int (gst_rtsp_thread_pool_get_max_threads (pool), 1);
119 thread1 = gst_rtsp_thread_pool_get_thread (pool, GST_RTSP_THREAD_TYPE_CLIENT,
121 fail_unless (GST_IS_RTSP_THREAD (thread1));
123 thread2 = gst_rtsp_thread_pool_get_thread (pool, GST_RTSP_THREAD_TYPE_CLIENT,
125 fail_unless (GST_IS_RTSP_THREAD (thread2));
127 fail_unless (thread1 == thread2);
129 gst_rtsp_thread_stop (thread1);
130 gst_rtsp_thread_stop (thread2);
133 g_object_set (pool, "max-threads", 2, NULL);
134 g_object_get (pool, "max-threads", &max_threads, NULL);
135 fail_unless_equals_int (max_threads, 2);
137 gst_rtsp_thread_pool_set_max_threads (pool, 2);
138 fail_unless_equals_int (gst_rtsp_thread_pool_get_max_threads (pool), 2);
141 thread1 = gst_rtsp_thread_pool_get_thread (pool, GST_RTSP_THREAD_TYPE_CLIENT,
143 fail_unless (GST_IS_RTSP_THREAD (thread1));
145 thread2 = gst_rtsp_thread_pool_get_thread (pool, GST_RTSP_THREAD_TYPE_CLIENT,
147 fail_unless (GST_IS_RTSP_THREAD (thread2));
149 thread3 = gst_rtsp_thread_pool_get_thread (pool, GST_RTSP_THREAD_TYPE_CLIENT,
151 fail_unless (GST_IS_RTSP_THREAD (thread3));
153 fail_unless (thread2 != thread1);
154 fail_unless (thread3 == thread2 || thread3 == thread1);
156 gst_rtsp_thread_stop (thread1);
157 gst_rtsp_thread_stop (thread2);
158 gst_rtsp_thread_stop (thread3);
161 g_object_set (pool, "max-threads", 0, NULL);
162 g_object_get (pool, "max-threads", &max_threads, NULL);
163 fail_unless_equals_int (max_threads, 0);
165 gst_rtsp_thread_pool_set_max_threads (pool, 0);
166 fail_unless_equals_int (gst_rtsp_thread_pool_get_max_threads (pool), 0);
169 thread1 = gst_rtsp_thread_pool_get_thread (pool, GST_RTSP_THREAD_TYPE_CLIENT,
171 fail_if (GST_IS_RTSP_THREAD (thread1));
173 g_object_unref (pool);
175 gst_rtsp_thread_pool_cleanup ();
178 GST_START_TEST (test_pool_max_threads)
180 do_test_pool_max_thread (FALSE);
185 GST_START_TEST (test_pool_max_threads_property)
187 do_test_pool_max_thread (TRUE);
192 GST_START_TEST (test_pool_thread_copy)
194 GstRTSPThreadPool *pool;
195 GstRTSPThread *thread1;
196 GstRTSPThread *thread2;
198 pool = gst_rtsp_thread_pool_new ();
199 fail_unless (GST_IS_RTSP_THREAD_POOL (pool));
201 thread1 = gst_rtsp_thread_pool_get_thread (pool, GST_RTSP_THREAD_TYPE_CLIENT,
203 fail_unless (GST_IS_RTSP_THREAD (thread1));
204 fail_unless (GST_IS_MINI_OBJECT_TYPE (thread1, GST_TYPE_RTSP_THREAD));
206 thread2 = GST_RTSP_THREAD (gst_mini_object_copy (GST_MINI_OBJECT (thread1)));
207 fail_unless (GST_IS_RTSP_THREAD (thread2));
208 fail_unless (GST_IS_MINI_OBJECT_TYPE (thread2, GST_TYPE_RTSP_THREAD));
210 gst_rtsp_thread_stop (thread1);
211 gst_rtsp_thread_stop (thread2);
212 g_object_unref (pool);
213 gst_rtsp_thread_pool_cleanup ();
219 rtspthreadpool_suite (void)
221 Suite *s = suite_create ("rtspthreadpool");
222 TCase *tc = tcase_create ("general");
224 suite_add_tcase (s, tc);
225 tcase_set_timeout (tc, 20);
226 tcase_add_test (tc, test_pool_get_thread);
227 tcase_add_test (tc, test_pool_get_media_thread);
228 tcase_add_test (tc, test_pool_get_thread_reuse);
229 tcase_add_test (tc, test_pool_max_threads);
230 tcase_add_test (tc, test_pool_max_threads_property);
231 tcase_add_test (tc, test_pool_thread_copy);
236 GST_CHECK_MAIN (rtspthreadpool);