thread-pool: Add unit test for the thread pools
authorOgnyan Tonchev <ognyan@axis.com>
Wed, 9 Oct 2013 13:19:12 +0000 (15:19 +0200)
committerSebastian Dröge <sebastian@centricular.com>
Wed, 30 Oct 2013 18:02:24 +0000 (19:02 +0100)
https://bugzilla.gnome.org/show_bug.cgi?id=710228

tests/check/Makefile.am
tests/check/gst/threadpool.c [new file with mode: 0644]

index ff17bbf..54aa0df 100644 (file)
@@ -31,7 +31,8 @@ check_PROGRAMS = \
        gst/mountpoints \
        gst/mediafactory \
        gst/media \
-       gst/addresspool
+       gst/addresspool \
+       gst/threadpool
 
 # these tests don't even pass
 noinst_PROGRAMS =
diff --git a/tests/check/gst/threadpool.c b/tests/check/gst/threadpool.c
new file mode 100644 (file)
index 0000000..735584a
--- /dev/null
@@ -0,0 +1,90 @@
+/* GStreamer
+ * unit tests for GstRTSPThreadPool
+ * Copyright (C) 2013 Axis Communications <dev-gstreamer at axis dot com>
+ * @author Ognyan Tonchev <ognyan at axis dot com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include <gst/check/gstcheck.h>
+
+#include <rtsp-thread-pool.h>
+
+GST_START_TEST (test_pool_get_thread)
+{
+  GstRTSPThreadPool *pool;
+  GstRTSPThread *thread;
+
+  pool = gst_rtsp_thread_pool_new ();
+  fail_unless (pool != NULL);
+
+  thread = gst_rtsp_thread_pool_get_thread (pool, GST_RTSP_THREAD_TYPE_CLIENT,
+      NULL);
+  fail_unless (thread != NULL);
+
+  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 *thread;
+  GstRTSPThread *thread2;
+
+  pool = gst_rtsp_thread_pool_new ();
+  fail_unless (pool != NULL);
+
+  gst_rtsp_thread_pool_set_max_threads (pool, 1);
+
+  thread = gst_rtsp_thread_pool_get_thread (pool, GST_RTSP_THREAD_TYPE_CLIENT,
+      NULL);
+  fail_unless (thread != NULL);
+
+  thread2 = gst_rtsp_thread_pool_get_thread (pool, GST_RTSP_THREAD_TYPE_CLIENT,
+      NULL);
+  fail_unless (thread2 != NULL);
+
+  fail_unless (thread == thread2);
+
+  gst_rtsp_thread_stop (thread);
+  gst_rtsp_thread_stop (thread2);
+  g_object_unref (pool);
+
+  gst_rtsp_thread_pool_cleanup ();
+}
+
+GST_END_TEST;
+
+
+static Suite *
+rtspthreadpool_suite (void)
+{
+  Suite *s = suite_create ("rtspthreadpool");
+  TCase *tc = tcase_create ("general");
+
+  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_thread_reuse);
+
+  return s;
+}
+
+GST_CHECK_MAIN (rtspthreadpool);