From 8f8da12228f010751fcdf0724a30b73420fae506 Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Tue, 21 Dec 2004 14:50:57 +0000 Subject: [PATCH] move common code to a lib Original commit message from CVS: move common code to a lib --- ChangeLog | 10 +++ check/Makefile.am | 8 ++- check/gst-libs/gdp.c | 40 +---------- check/gst/gstobject.c | 130 +---------------------------------- check/gstcheck.c | 51 ++++++++++++++ check/gstcheck.h | 131 ++++++++++++++++++++++++++++++++++++ gst/gstelement.c | 13 ++-- tests/check/Makefile.am | 8 ++- tests/check/gst/gstobject.c | 130 +---------------------------------- tests/check/gstcheck.c | 51 ++++++++++++++ tests/check/gstcheck.h | 131 ++++++++++++++++++++++++++++++++++++ tests/check/libs/gdp.c | 40 +---------- 12 files changed, 405 insertions(+), 338 deletions(-) create mode 100644 check/gstcheck.c create mode 100644 check/gstcheck.h create mode 100644 tests/check/gstcheck.c create mode 100644 tests/check/gstcheck.h diff --git a/ChangeLog b/ChangeLog index 03d578c023..32eede7c6a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2004-12-21 Thomas Vander Stichele + + * check/Makefile.am: + * check/gst-libs/gdp.c: + * check/gst/gstobject.c: + * check/gstcheck.c: + * check/gstcheck.h: + * gst/gstelement.c: + move common code to a lib + 2004-12-21 Thomas Vander Stichele * check/Makefile.am: diff --git a/check/Makefile.am b/check/Makefile.am index 1f5f29a4ff..b9f66269e8 100644 --- a/check/Makefile.am +++ b/check/Makefile.am @@ -2,8 +2,14 @@ TESTS = gst/gstobject gst-libs/gdp check_PROGRAMS = $(TESTS) +noinst_LTLIBRARIES = libgstcheck.la + +libgstcheck_la_SOURCES = gstcheck.c +libgstcheck_la_LIBADD = $(GST_OBJ_LIBS) +noinst_HEADERS = gstcheck.h + AM_CFLAGS = $(GST_OBJ_CFLAGS) $(CHECK_CFLAGS) -LDADD = $(GST_OBJ_LIBS) $(CHECK_LIBS) +LDADD = $(GST_OBJ_LIBS) $(CHECK_LIBS) libgstcheck.la gst_libs_gdp_SOURCES = \ gst-libs/gdp.c \ diff --git a/check/gst-libs/gdp.c b/check/gst-libs/gdp.c index dbcbb620a8..2aefdee4aa 100644 --- a/check/gst-libs/gdp.c +++ b/check/gst-libs/gdp.c @@ -20,47 +20,11 @@ * Boston, MA 02111-1307, USA. */ -#include /* memcmp */ +#include "../gstcheck.h" -#include - -#include #include - #include "libs/gst/dataprotocol/dp-private.h" /* private header */ - -/* FIXME: externalize */ -/* logging function for tests - * a test uses g_message() to log a debug line - * a gst unit test can be run with GST_TEST_DEBUG env var set to see the - * messages - */ -gboolean _gst_test_debug = FALSE; - -gboolean _gst_test_threads_running = FALSE; - -void gst_test_log_func - (const gchar * log_domain, GLogLevelFlags log_level, - const gchar * message, gpointer user_data) -{ - // g_print ("HANDLER CALLED\n"); - if (_gst_test_debug) { - g_print (message); - } -} - -/* initialize GStreamer testing */ -void -gst_test_init (void) -{ - if (g_getenv ("GST_TEST_DEBUG")) - _gst_test_debug = TRUE; - - g_log_set_handler (NULL, G_LOG_LEVEL_MESSAGE, gst_test_log_func, NULL); -} - - /* test our method of reading and writing headers using TO/FROM_BE */ START_TEST (test_conversion) { @@ -302,8 +266,8 @@ main (int argc, char **argv) SRunner *sr = srunner_create (s); gst_init (&argc, &argv); - gst_test_init (); gst_dp_init (); + gst_check_init (); srunner_run_all (sr, CK_NORMAL); nf = srunner_ntests_failed (sr); diff --git a/check/gst/gstobject.c b/check/gst/gstobject.c index d0bfcaecdf..5e0f30f0d7 100644 --- a/check/gst/gstobject.c +++ b/check/gst/gstobject.c @@ -20,44 +20,7 @@ * Boston, MA 02111-1307, USA. */ -#include -#include -#include - -#include - -#include - - -/* FIXME: externalize */ -/* logging function for tests - * a test uses g_message() to log a debug line - * a gst unit test can be run with GST_TEST_DEBUG env var set to see the - * messages - */ -gboolean _gst_test_debug = FALSE; - -gboolean _gst_test_threads_running = FALSE; - -void gst_test_log_func - (const gchar * log_domain, GLogLevelFlags log_level, - const gchar * message, gpointer user_data) -{ - // g_print ("HANDLER CALLED\n"); - if (_gst_test_debug) { - g_print (message); - } -} - -/* initialize GStreamer testing */ -void -gst_test_init (void) -{ - if (g_getenv ("GST_TEST_DEBUG")) - _gst_test_debug = TRUE; - - g_log_set_handler (NULL, G_LOG_LEVEL_MESSAGE, gst_test_log_func, NULL); -} +#include "../gstcheck.h" /* Create a fake subclass @@ -162,95 +125,8 @@ START_TEST (test_fake_object_name) } END_TEST -/*** - * thread test macros and variables - */ - GList * thread_list = NULL; -GMutex *mutex; -GCond *start_cond; /* used to notify main thread of thread startups */ -GCond *sync_cond; /* used to synchronize all threads and main thread */ - -#define MAIN_START_THREADS(count, function, data) \ -MAIN_INIT(); \ -MAIN_START_THREAD_FUNCTIONS(count, function, data); \ -MAIN_SYNCHRONIZE(); - -#define MAIN_INIT() \ -G_STMT_START { \ - _gst_test_threads_running = TRUE; \ - \ - mutex = g_mutex_new (); \ - start_cond = g_cond_new (); \ - sync_cond = g_cond_new (); \ -} G_STMT_END; - -#define MAIN_START_THREAD_FUNCTIONS(count, function, data) \ -G_STMT_START { \ - int i; \ - for (i = 0; i < count; ++i) { \ - MAIN_START_THREAD_FUNCTION (i, function, data); \ - } \ -} G_STMT_END; - -#define MAIN_START_THREAD_FUNCTION(i, function, data) \ -G_STMT_START { \ - GThread *thread = NULL; \ - g_message ("MAIN: creating thread %d\n", i); \ - g_mutex_lock (mutex); \ - thread = g_thread_create ((GThreadFunc) function, data, \ - TRUE, NULL); \ - /* wait for thread to signal us that it's ready */ \ - g_message ("MAIN: waiting for thread %d\n", i); \ - g_cond_wait (start_cond, mutex); \ - g_mutex_unlock (mutex); \ - \ - thread_list = g_list_append (thread_list, thread); \ -} G_STMT_END; - - -#define MAIN_SYNCHRONIZE() \ -G_STMT_START { \ - g_message ("MAIN: synchronizing\n"); \ - g_cond_broadcast (sync_cond); \ - g_message ("MAIN: synchronized\n"); \ -} G_STMT_END; - -#define MAIN_STOP_THREADS() \ -G_STMT_START { \ - _gst_test_threads_running = FALSE; \ - \ - /* join all threads */ \ - g_message ("MAIN: joining\n"); \ - g_list_foreach (thread_list, (GFunc) g_thread_join, NULL); \ - g_message ("MAIN: joined\n"); \ -} G_STMT_END; - -#define THREAD_START() \ -THREAD_STARTED(); \ -THREAD_SYNCHRONIZE(); - -#define THREAD_STARTED() \ -G_STMT_START { \ - /* signal main thread that we started */ \ - g_message ("THREAD %p: started\n", g_thread_self ()); \ - g_mutex_lock (mutex); \ - g_cond_signal (start_cond); \ -} G_STMT_END; - -#define THREAD_SYNCHRONIZE() \ -G_STMT_START { \ - /* synchronize everyone */ \ - g_message ("THREAD %p: syncing\n", g_thread_self ()); \ - g_cond_wait (sync_cond, mutex); \ - g_message ("THREAD %p: synced\n", g_thread_self ()); \ - g_mutex_unlock (mutex); \ -} G_STMT_END; - -#define THREAD_TEST_RUNNING() (_gst_test_threads_running == TRUE) - /* thread function for threaded name change test */ -gpointer -thread_name_object (GstObject * object) + gpointer thread_name_object (GstObject * object) { gchar *thread_id = g_strdup_printf ("%p", g_thread_self ()); @@ -479,7 +355,7 @@ main (int argc, char **argv) SRunner *sr = srunner_create (s); gst_init (&argc, &argv); - gst_test_init (); + gst_check_init (); srunner_run_all (sr, CK_NORMAL); nf = srunner_ntests_failed (sr); diff --git a/check/gstcheck.c b/check/gstcheck.c new file mode 100644 index 0000000000..8212878ed3 --- /dev/null +++ b/check/gstcheck.c @@ -0,0 +1,51 @@ +/* GStreamer + * + * Common code for GStreamer unittests + * + * Copyright (C) <2004> Thomas Vander Stichele + * + * 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., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include + +/* logging function for tests + * a test uses g_message() to log a debug line + * a gst unit test can be run with GST_TEST_DEBUG env var set to see the + * messages + */ + +gboolean _gst_check_debug = FALSE; + +void gst_check_log_func + (const gchar * log_domain, GLogLevelFlags log_level, + const gchar * message, gpointer user_data) +{ + // g_print ("HANDLER CALLED\n"); + if (_gst_check_debug) { + g_print (message); + } +} + +/* initialize GStreamer testing */ +void +gst_check_init (void) +{ + if (g_getenv ("GST_TEST_DEBUG")) + _gst_check_debug = TRUE; + + g_log_set_handler (NULL, G_LOG_LEVEL_MESSAGE, gst_check_log_func, NULL); +} diff --git a/check/gstcheck.h b/check/gstcheck.h new file mode 100644 index 0000000000..6f9f3e7ac0 --- /dev/null +++ b/check/gstcheck.h @@ -0,0 +1,131 @@ +/* GStreamer + * + * Common code for GStreamer unittests + * + * Copyright (C) <2004> Thomas Vander Stichele + * + * 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., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef __GST_CHECK_H__ +#define __GST_CHECK_H__ + +#include +#include +#include + +#include + +#include + + +/* logging function for tests + * a test uses g_message() to log a debug line + * a gst unit test can be run with GST_TEST_DEBUG env var set to see the + * messages + */ +gboolean _gst_check_threads_running = FALSE; + +void gst_check_init (void); + +/*** + * thread test macros and variables + */ +GList *thread_list = NULL; +GMutex *mutex; +GCond *start_cond; /* used to notify main thread of thread startups */ +GCond *sync_cond; /* used to synchronize all threads and main thread */ + +#define MAIN_START_THREADS(count, function, data) \ +MAIN_INIT(); \ +MAIN_START_THREAD_FUNCTIONS(count, function, data); \ +MAIN_SYNCHRONIZE(); + +#define MAIN_INIT() \ +G_STMT_START { \ + _gst_check_threads_running = TRUE; \ + \ + mutex = g_mutex_new (); \ + start_cond = g_cond_new (); \ + sync_cond = g_cond_new (); \ +} G_STMT_END; + +#define MAIN_START_THREAD_FUNCTIONS(count, function, data) \ +G_STMT_START { \ + int i; \ + for (i = 0; i < count; ++i) { \ + MAIN_START_THREAD_FUNCTION (i, function, data); \ + } \ +} G_STMT_END; + +#define MAIN_START_THREAD_FUNCTION(i, function, data) \ +G_STMT_START { \ + GThread *thread = NULL; \ + g_message ("MAIN: creating thread %d\n", i); \ + g_mutex_lock (mutex); \ + thread = g_thread_create ((GThreadFunc) function, data, \ + TRUE, NULL); \ + /* wait for thread to signal us that it's ready */ \ + g_message ("MAIN: waiting for thread %d\n", i); \ + g_cond_wait (start_cond, mutex); \ + g_mutex_unlock (mutex); \ + \ + thread_list = g_list_append (thread_list, thread); \ +} G_STMT_END; + + +#define MAIN_SYNCHRONIZE() \ +G_STMT_START { \ + g_message ("MAIN: synchronizing\n"); \ + g_cond_broadcast (sync_cond); \ + g_message ("MAIN: synchronized\n"); \ +} G_STMT_END; + +#define MAIN_STOP_THREADS() \ +G_STMT_START { \ + _gst_check_threads_running = FALSE; \ + \ + /* join all threads */ \ + g_message ("MAIN: joining\n"); \ + g_list_foreach (thread_list, (GFunc) g_thread_join, NULL); \ + g_message ("MAIN: joined\n"); \ +} G_STMT_END; + +#define THREAD_START() \ +THREAD_STARTED(); \ +THREAD_SYNCHRONIZE(); + +#define THREAD_STARTED() \ +G_STMT_START { \ + /* signal main thread that we started */ \ + g_message ("THREAD %p: started\n", g_thread_self ()); \ + g_mutex_lock (mutex); \ + g_cond_signal (start_cond); \ +} G_STMT_END; + +#define THREAD_SYNCHRONIZE() \ +G_STMT_START { \ + /* synchronize everyone */ \ + g_message ("THREAD %p: syncing\n", g_thread_self ()); \ + g_cond_wait (sync_cond, mutex); \ + g_message ("THREAD %p: synced\n", g_thread_self ()); \ + g_mutex_unlock (mutex); \ +} G_STMT_END; + +#define THREAD_TEST_RUNNING() (_gst_check_threads_running == TRUE) + +#endif /* __GST_CHECK_H__ */ + diff --git a/gst/gstelement.c b/gst/gstelement.c index 17eb08c4b7..2284d5ab38 100644 --- a/gst/gstelement.c +++ b/gst/gstelement.c @@ -26,15 +26,16 @@ #include #include "gstelement.h" -#include "gstbin.h" + #include "gstmarshal.h" #include "gsterror.h" #include "gstevent.h" #include "gstutils.h" #include "gstinfo.h" #include "gst-i18n-lib.h" + #include "gstscheduler.h" -#include "gstpipeline.h" +#include "gstbus.h" /* Element signals and args */ enum @@ -191,7 +192,7 @@ gst_element_init (GstElement * element) element->state_cond = g_cond_new (); } -/** +/** * gst_element_default_error: * @object: a #GObject that signalled the error. * @orig: the #GstObject that initiated the error. @@ -246,7 +247,7 @@ gst_element_release_request_pad (GstElement * element, GstPad * pad) * gst_element_requires_clock: * @element: a #GstElement to query * - * Query if the element requiresd a clock + * Query if the element requires a clock. * * Returns: TRUE if the element requires a clock * @@ -369,7 +370,7 @@ gst_element_is_indexable (GstElement * element) * @element: a #GstElement. * @index: a #GstIndex. * - * Set the specified GstIndex on the element. + * Set the specified GstIndex on the element. * * MT safe. */ @@ -420,7 +421,7 @@ gst_element_get_index (GstElement * element) * @pad: the #GstPad to add to the element. * * Adds a pad (link point) to @element. @pad's parent will be set to @element; - * see gst_object_set_parent() for refcounting information. + * see gst_object_set_parent() for refcounting information. * * Pads are automatically activated when the element is in state PLAYING. * diff --git a/tests/check/Makefile.am b/tests/check/Makefile.am index 1f5f29a4ff..b9f66269e8 100644 --- a/tests/check/Makefile.am +++ b/tests/check/Makefile.am @@ -2,8 +2,14 @@ TESTS = gst/gstobject gst-libs/gdp check_PROGRAMS = $(TESTS) +noinst_LTLIBRARIES = libgstcheck.la + +libgstcheck_la_SOURCES = gstcheck.c +libgstcheck_la_LIBADD = $(GST_OBJ_LIBS) +noinst_HEADERS = gstcheck.h + AM_CFLAGS = $(GST_OBJ_CFLAGS) $(CHECK_CFLAGS) -LDADD = $(GST_OBJ_LIBS) $(CHECK_LIBS) +LDADD = $(GST_OBJ_LIBS) $(CHECK_LIBS) libgstcheck.la gst_libs_gdp_SOURCES = \ gst-libs/gdp.c \ diff --git a/tests/check/gst/gstobject.c b/tests/check/gst/gstobject.c index d0bfcaecdf..5e0f30f0d7 100644 --- a/tests/check/gst/gstobject.c +++ b/tests/check/gst/gstobject.c @@ -20,44 +20,7 @@ * Boston, MA 02111-1307, USA. */ -#include -#include -#include - -#include - -#include - - -/* FIXME: externalize */ -/* logging function for tests - * a test uses g_message() to log a debug line - * a gst unit test can be run with GST_TEST_DEBUG env var set to see the - * messages - */ -gboolean _gst_test_debug = FALSE; - -gboolean _gst_test_threads_running = FALSE; - -void gst_test_log_func - (const gchar * log_domain, GLogLevelFlags log_level, - const gchar * message, gpointer user_data) -{ - // g_print ("HANDLER CALLED\n"); - if (_gst_test_debug) { - g_print (message); - } -} - -/* initialize GStreamer testing */ -void -gst_test_init (void) -{ - if (g_getenv ("GST_TEST_DEBUG")) - _gst_test_debug = TRUE; - - g_log_set_handler (NULL, G_LOG_LEVEL_MESSAGE, gst_test_log_func, NULL); -} +#include "../gstcheck.h" /* Create a fake subclass @@ -162,95 +125,8 @@ START_TEST (test_fake_object_name) } END_TEST -/*** - * thread test macros and variables - */ - GList * thread_list = NULL; -GMutex *mutex; -GCond *start_cond; /* used to notify main thread of thread startups */ -GCond *sync_cond; /* used to synchronize all threads and main thread */ - -#define MAIN_START_THREADS(count, function, data) \ -MAIN_INIT(); \ -MAIN_START_THREAD_FUNCTIONS(count, function, data); \ -MAIN_SYNCHRONIZE(); - -#define MAIN_INIT() \ -G_STMT_START { \ - _gst_test_threads_running = TRUE; \ - \ - mutex = g_mutex_new (); \ - start_cond = g_cond_new (); \ - sync_cond = g_cond_new (); \ -} G_STMT_END; - -#define MAIN_START_THREAD_FUNCTIONS(count, function, data) \ -G_STMT_START { \ - int i; \ - for (i = 0; i < count; ++i) { \ - MAIN_START_THREAD_FUNCTION (i, function, data); \ - } \ -} G_STMT_END; - -#define MAIN_START_THREAD_FUNCTION(i, function, data) \ -G_STMT_START { \ - GThread *thread = NULL; \ - g_message ("MAIN: creating thread %d\n", i); \ - g_mutex_lock (mutex); \ - thread = g_thread_create ((GThreadFunc) function, data, \ - TRUE, NULL); \ - /* wait for thread to signal us that it's ready */ \ - g_message ("MAIN: waiting for thread %d\n", i); \ - g_cond_wait (start_cond, mutex); \ - g_mutex_unlock (mutex); \ - \ - thread_list = g_list_append (thread_list, thread); \ -} G_STMT_END; - - -#define MAIN_SYNCHRONIZE() \ -G_STMT_START { \ - g_message ("MAIN: synchronizing\n"); \ - g_cond_broadcast (sync_cond); \ - g_message ("MAIN: synchronized\n"); \ -} G_STMT_END; - -#define MAIN_STOP_THREADS() \ -G_STMT_START { \ - _gst_test_threads_running = FALSE; \ - \ - /* join all threads */ \ - g_message ("MAIN: joining\n"); \ - g_list_foreach (thread_list, (GFunc) g_thread_join, NULL); \ - g_message ("MAIN: joined\n"); \ -} G_STMT_END; - -#define THREAD_START() \ -THREAD_STARTED(); \ -THREAD_SYNCHRONIZE(); - -#define THREAD_STARTED() \ -G_STMT_START { \ - /* signal main thread that we started */ \ - g_message ("THREAD %p: started\n", g_thread_self ()); \ - g_mutex_lock (mutex); \ - g_cond_signal (start_cond); \ -} G_STMT_END; - -#define THREAD_SYNCHRONIZE() \ -G_STMT_START { \ - /* synchronize everyone */ \ - g_message ("THREAD %p: syncing\n", g_thread_self ()); \ - g_cond_wait (sync_cond, mutex); \ - g_message ("THREAD %p: synced\n", g_thread_self ()); \ - g_mutex_unlock (mutex); \ -} G_STMT_END; - -#define THREAD_TEST_RUNNING() (_gst_test_threads_running == TRUE) - /* thread function for threaded name change test */ -gpointer -thread_name_object (GstObject * object) + gpointer thread_name_object (GstObject * object) { gchar *thread_id = g_strdup_printf ("%p", g_thread_self ()); @@ -479,7 +355,7 @@ main (int argc, char **argv) SRunner *sr = srunner_create (s); gst_init (&argc, &argv); - gst_test_init (); + gst_check_init (); srunner_run_all (sr, CK_NORMAL); nf = srunner_ntests_failed (sr); diff --git a/tests/check/gstcheck.c b/tests/check/gstcheck.c new file mode 100644 index 0000000000..8212878ed3 --- /dev/null +++ b/tests/check/gstcheck.c @@ -0,0 +1,51 @@ +/* GStreamer + * + * Common code for GStreamer unittests + * + * Copyright (C) <2004> Thomas Vander Stichele + * + * 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., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include + +/* logging function for tests + * a test uses g_message() to log a debug line + * a gst unit test can be run with GST_TEST_DEBUG env var set to see the + * messages + */ + +gboolean _gst_check_debug = FALSE; + +void gst_check_log_func + (const gchar * log_domain, GLogLevelFlags log_level, + const gchar * message, gpointer user_data) +{ + // g_print ("HANDLER CALLED\n"); + if (_gst_check_debug) { + g_print (message); + } +} + +/* initialize GStreamer testing */ +void +gst_check_init (void) +{ + if (g_getenv ("GST_TEST_DEBUG")) + _gst_check_debug = TRUE; + + g_log_set_handler (NULL, G_LOG_LEVEL_MESSAGE, gst_check_log_func, NULL); +} diff --git a/tests/check/gstcheck.h b/tests/check/gstcheck.h new file mode 100644 index 0000000000..6f9f3e7ac0 --- /dev/null +++ b/tests/check/gstcheck.h @@ -0,0 +1,131 @@ +/* GStreamer + * + * Common code for GStreamer unittests + * + * Copyright (C) <2004> Thomas Vander Stichele + * + * 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., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef __GST_CHECK_H__ +#define __GST_CHECK_H__ + +#include +#include +#include + +#include + +#include + + +/* logging function for tests + * a test uses g_message() to log a debug line + * a gst unit test can be run with GST_TEST_DEBUG env var set to see the + * messages + */ +gboolean _gst_check_threads_running = FALSE; + +void gst_check_init (void); + +/*** + * thread test macros and variables + */ +GList *thread_list = NULL; +GMutex *mutex; +GCond *start_cond; /* used to notify main thread of thread startups */ +GCond *sync_cond; /* used to synchronize all threads and main thread */ + +#define MAIN_START_THREADS(count, function, data) \ +MAIN_INIT(); \ +MAIN_START_THREAD_FUNCTIONS(count, function, data); \ +MAIN_SYNCHRONIZE(); + +#define MAIN_INIT() \ +G_STMT_START { \ + _gst_check_threads_running = TRUE; \ + \ + mutex = g_mutex_new (); \ + start_cond = g_cond_new (); \ + sync_cond = g_cond_new (); \ +} G_STMT_END; + +#define MAIN_START_THREAD_FUNCTIONS(count, function, data) \ +G_STMT_START { \ + int i; \ + for (i = 0; i < count; ++i) { \ + MAIN_START_THREAD_FUNCTION (i, function, data); \ + } \ +} G_STMT_END; + +#define MAIN_START_THREAD_FUNCTION(i, function, data) \ +G_STMT_START { \ + GThread *thread = NULL; \ + g_message ("MAIN: creating thread %d\n", i); \ + g_mutex_lock (mutex); \ + thread = g_thread_create ((GThreadFunc) function, data, \ + TRUE, NULL); \ + /* wait for thread to signal us that it's ready */ \ + g_message ("MAIN: waiting for thread %d\n", i); \ + g_cond_wait (start_cond, mutex); \ + g_mutex_unlock (mutex); \ + \ + thread_list = g_list_append (thread_list, thread); \ +} G_STMT_END; + + +#define MAIN_SYNCHRONIZE() \ +G_STMT_START { \ + g_message ("MAIN: synchronizing\n"); \ + g_cond_broadcast (sync_cond); \ + g_message ("MAIN: synchronized\n"); \ +} G_STMT_END; + +#define MAIN_STOP_THREADS() \ +G_STMT_START { \ + _gst_check_threads_running = FALSE; \ + \ + /* join all threads */ \ + g_message ("MAIN: joining\n"); \ + g_list_foreach (thread_list, (GFunc) g_thread_join, NULL); \ + g_message ("MAIN: joined\n"); \ +} G_STMT_END; + +#define THREAD_START() \ +THREAD_STARTED(); \ +THREAD_SYNCHRONIZE(); + +#define THREAD_STARTED() \ +G_STMT_START { \ + /* signal main thread that we started */ \ + g_message ("THREAD %p: started\n", g_thread_self ()); \ + g_mutex_lock (mutex); \ + g_cond_signal (start_cond); \ +} G_STMT_END; + +#define THREAD_SYNCHRONIZE() \ +G_STMT_START { \ + /* synchronize everyone */ \ + g_message ("THREAD %p: syncing\n", g_thread_self ()); \ + g_cond_wait (sync_cond, mutex); \ + g_message ("THREAD %p: synced\n", g_thread_self ()); \ + g_mutex_unlock (mutex); \ +} G_STMT_END; + +#define THREAD_TEST_RUNNING() (_gst_check_threads_running == TRUE) + +#endif /* __GST_CHECK_H__ */ + diff --git a/tests/check/libs/gdp.c b/tests/check/libs/gdp.c index dbcbb620a8..2aefdee4aa 100644 --- a/tests/check/libs/gdp.c +++ b/tests/check/libs/gdp.c @@ -20,47 +20,11 @@ * Boston, MA 02111-1307, USA. */ -#include /* memcmp */ +#include "../gstcheck.h" -#include - -#include #include - #include "libs/gst/dataprotocol/dp-private.h" /* private header */ - -/* FIXME: externalize */ -/* logging function for tests - * a test uses g_message() to log a debug line - * a gst unit test can be run with GST_TEST_DEBUG env var set to see the - * messages - */ -gboolean _gst_test_debug = FALSE; - -gboolean _gst_test_threads_running = FALSE; - -void gst_test_log_func - (const gchar * log_domain, GLogLevelFlags log_level, - const gchar * message, gpointer user_data) -{ - // g_print ("HANDLER CALLED\n"); - if (_gst_test_debug) { - g_print (message); - } -} - -/* initialize GStreamer testing */ -void -gst_test_init (void) -{ - if (g_getenv ("GST_TEST_DEBUG")) - _gst_test_debug = TRUE; - - g_log_set_handler (NULL, G_LOG_LEVEL_MESSAGE, gst_test_log_func, NULL); -} - - /* test our method of reading and writing headers using TO/FROM_BE */ START_TEST (test_conversion) { @@ -302,8 +266,8 @@ main (int argc, char **argv) SRunner *sr = srunner_create (s); gst_init (&argc, &argv); - gst_test_init (); gst_dp_init (); + gst_check_init (); srunner_run_all (sr, CK_NORMAL); nf = srunner_ntests_failed (sr);