libs: Documentation fixes
[platform/upstream/gstreamer.git] / libs / gst / check / gstcheck.h
1 /* GStreamer
2  *
3  * Common code for GStreamer unittests
4  *
5  * Copyright (C) <2004> Thomas Vander Stichele <thomas at apestaart dot org>
6  * Copyright (C) <2008> Thijs Vermeir <thijsvermeir@gmail.com>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the
20  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
21  * Boston, MA 02110-1301, USA.
22  */
23
24 #ifndef __GST_CHECK_H__
25 #define __GST_CHECK_H__
26
27 #include <signal.h>
28 #include <string.h>
29 #include <stdlib.h>
30 #include <math.h>
31
32 #include <gst/gst.h>
33 #include <gst/check/check-prelude.h>
34
35 #define CK_DLL_EXP GST_CHECK_API
36 #include <gst/check/internal-check.h>
37
38 G_BEGIN_DECLS
39
40 GST_CHECK_API GstDebugCategory *check_debug;
41 #define GST_CAT_DEFAULT check_debug
42
43 /* logging function for tests
44  * a test uses g_message() to log a debug line
45  * a gst unit test can be run with GST_TEST_DEBUG env var set to see the
46  * messages
47  */
48 GST_CHECK_API gboolean _gst_check_threads_running;
49 GST_CHECK_API gboolean _gst_check_raised_critical;
50 GST_CHECK_API gboolean _gst_check_raised_warning;
51 GST_CHECK_API gboolean _gst_check_expecting_log;
52 GST_CHECK_API gboolean _gst_check_list_tests;
53
54 /* global variables used in test methods */
55 GST_CHECK_API GList * buffers;
56
57 GST_CHECK_API GMutex check_mutex;
58 GST_CHECK_API GCond check_cond;
59
60 typedef struct
61 {
62   const char *name;
63   int size;
64   int abi_size;
65 }
66 GstCheckABIStruct;
67
68 typedef struct _GstCheckLogFilter GstCheckLogFilter;
69
70 /**
71  * GstCheckLogFilterFunc:
72  * @log_domain: the log domain of the message
73  * @log_level: the log level of the message
74  * @message: the message that has occured
75  * @user_data: user data
76  *
77  * A function that is called for messages matching the filter added by
78  * @gst_check_add_log_filter.
79  *
80  * Returns: %TRUE if message should be discarded by GstCheck.
81  *
82  * Since: 1.12
83  */
84 typedef gboolean (*GstCheckLogFilterFunc) (const gchar * log_domain,
85     GLogLevelFlags log_level, const gchar * message, gpointer user_data);
86
87 GST_CHECK_API
88 void gst_check_init (int *argc, char **argv[]);
89
90 GST_CHECK_API
91 GstCheckLogFilter * gst_check_add_log_filter (const gchar * log_domain,
92     GLogLevelFlags log_level, GRegex * regex, GstCheckLogFilterFunc func,
93     gpointer user_data, GDestroyNotify destroy_data);
94
95 GST_CHECK_API
96 void gst_check_remove_log_filter (GstCheckLogFilter * filter);
97
98 GST_CHECK_API
99 void gst_check_clear_log_filter (void);
100
101 GST_CHECK_API
102 GstFlowReturn gst_check_chain_func (GstPad * pad, GstObject * parent, GstBuffer * buffer);
103
104 GST_CHECK_API
105 void gst_check_message_error (GstMessage * message, GstMessageType type,
106     GQuark domain, gint code);
107
108 GST_CHECK_API
109 GstElement *gst_check_setup_element (const gchar * factory);
110
111 GST_CHECK_API
112 void gst_check_teardown_element (GstElement * element);
113
114 GST_CHECK_API
115 GstPad *gst_check_setup_src_pad (GstElement * element,
116     GstStaticPadTemplate * tmpl);
117
118 GST_CHECK_API
119 GstPad *gst_check_setup_src_pad_from_template (GstElement * element,
120     GstPadTemplate * tmpl);
121
122 GST_CHECK_API
123 GstPad * gst_check_setup_src_pad_by_name (GstElement * element,
124           GstStaticPadTemplate * tmpl, const gchar *name);
125
126 GST_CHECK_API
127 GstPad * gst_check_setup_src_pad_by_name_from_template (GstElement * element,
128           GstPadTemplate * tmpl, const gchar *name);
129
130 GST_CHECK_API
131 GstPad *gst_check_setup_sink_pad (GstElement * element,
132     GstStaticPadTemplate * tmpl);
133
134 GST_CHECK_API
135 GstPad *gst_check_setup_sink_pad_from_template (GstElement * element,
136     GstPadTemplate * tmpl);
137
138 GST_CHECK_API
139 GstPad * gst_check_setup_sink_pad_by_name (GstElement * element,
140           GstStaticPadTemplate * tmpl, const gchar *name);
141
142 GST_CHECK_API
143 GstPad * gst_check_setup_sink_pad_by_name_from_template (GstElement * element,
144           GstPadTemplate * tmpl, const gchar *name);
145
146 GST_CHECK_API
147 void gst_check_teardown_pad_by_name (GstElement * element, const gchar *name);
148
149 GST_CHECK_API
150 void gst_check_teardown_src_pad (GstElement * element);
151
152 GST_CHECK_API
153 void gst_check_drop_buffers (void);
154
155 GST_CHECK_API
156 void gst_check_caps_equal (GstCaps * caps1, GstCaps * caps2);
157
158 GST_CHECK_API
159 void gst_check_buffer_data (GstBuffer * buffer, gconstpointer data, gsize size);
160
161 GST_CHECK_API
162 void gst_check_element_push_buffer_list (const gchar * element_name,
163     GList * buffer_in, GstCaps * caps_in, GList * buffer_out,
164     GstCaps * caps_out, GstFlowReturn last_flow_return);
165
166 GST_CHECK_API
167 void gst_check_element_push_buffer (const gchar * element_name,
168     GstBuffer * buffer_in, GstCaps * caps_in, GstBuffer * buffer_out,
169     GstCaps *caps_out);
170
171 GST_CHECK_API
172 void gst_check_teardown_sink_pad (GstElement * element);
173
174 GST_CHECK_API
175 void gst_check_abi_list (GstCheckABIStruct list[], gboolean have_abi_sizes);
176
177 GST_CHECK_API
178 gint gst_check_run_suite (Suite * suite, const gchar * name,
179     const gchar * fname);
180
181 GST_CHECK_API
182 void gst_check_setup_events (GstPad * srcpad, GstElement * element,
183     GstCaps * caps, GstFormat format);
184
185 GST_CHECK_API
186 void gst_check_setup_events_with_stream_id (GstPad * srcpad,
187     GstElement * element, GstCaps * caps, GstFormat format,
188     const gchar * stream_id);
189
190 GST_CHECK_API
191 void gst_check_objects_destroyed_on_unref (gpointer object_to_unref, gpointer first_object, ...)
192   G_GNUC_NULL_TERMINATED;
193
194 GST_CHECK_API
195 void gst_check_object_destroyed_on_unref (gpointer object_to_unref);
196
197 #define fail_unless_message_error(msg, domain, code)            \
198 gst_check_message_error (msg, GST_MESSAGE_ERROR,                \
199   GST_ ## domain ## _ERROR, GST_ ## domain ## _ERROR_ ## code)
200 #define assert_message_error(m, d, c) fail_unless_message_error(m, d, c)
201
202 #ifdef GST_CHECK_TEST_ENVIRONMENT_BEACON
203 #define GST_DO_CHECK_TEST_ENVIRONMENT \
204 G_STMT_START {                        \
205   if (g_getenv (GST_CHECK_TEST_ENVIRONMENT_BEACON) == NULL) \
206     fail ("Test environment not set up correctly! Expected environment " \
207        "variable '%s' to be set.", GST_CHECK_TEST_ENVIRONMENT_BEACON); \
208 } G_STMT_END
209
210 #else
211 #define GST_DO_CHECK_TEST_ENVIRONMENT /* nothing to check */
212 #endif
213
214 /**
215  * GST_START_TEST:
216  * @__testname: test function name
217  *
218  * wrapper for checks START_TEST
219  */
220 /**
221  * GST_END_TEST:
222  *
223  * wrapper for checks END_TEST
224  */
225 #define GST_START_TEST(__testname) \
226 static void __testname (int G_GNUC_UNUSED __i__) \
227 {\
228   GST_DEBUG ("test start"); \
229   GST_DO_CHECK_TEST_ENVIRONMENT; \
230   tcase_fn_start (""# __testname, __FILE__, __LINE__);
231
232 #define GST_END_TEST GST_LOG ("cleaning up tasks"); \
233                      gst_task_cleanup_all (); \
234                      END_TEST
235
236 /* additional fail macros */
237 /**
238  * fail_unless_equals_int:
239  * @a: a #gint value or expression
240  * @b: a #gint value or expression
241  *
242  * This macro checks that @a and @b are equal and aborts if this is not the
243  * case, printing both expressions and the values they evaluated to. This
244  * macro is for use in unit tests.
245  */
246 #define fail_unless_equals_int(a, b)                                    \
247 G_STMT_START {                                                          \
248   int first = a;                                                        \
249   int second = b;                                                       \
250   fail_unless(first == second,                                          \
251     "'" #a "' (%d) is not equal to '" #b"' (%d)", first, second);       \
252 } G_STMT_END;
253 /**
254  * assert_equals_int:
255  * @a: a #gint value or expression
256  * @b: a #gint value or expression
257  *
258  * This macro checks that @a and @b are equal and aborts if this is not the
259  * case, printing both expressions and the values they evaluated to. This
260  * macro is for use in unit tests.
261  */
262 #define assert_equals_int(a, b) fail_unless_equals_int(a, b)
263
264 /**
265  * fail_unless_equals_int_hex:
266  * @a: a #gint value or expression
267  * @b: a #gint value or expression
268  *
269  * This macro checks that @a and @b are equal and aborts if this is not the
270  * case, printing both expressions and the values they evaluated to in
271  * hexadecimal format. This macro is for use in unit tests.
272  *
273  * Since: 1.2
274  */
275 #define fail_unless_equals_int_hex(a, b)                                \
276 G_STMT_START {                                                          \
277   int first = a;                                                        \
278   int second = b;                                                       \
279   fail_unless(first == second,                                          \
280     "'" #a "' (0x%08x) is not equal to '" #b"' (0x%08x)", first, second);\
281 } G_STMT_END;
282
283 /**
284  * assert_equals_int_hex:
285  * @a: a #gint value or expression
286  * @b: a #gint value or expression
287  *
288  * This macro checks that @a and @b are equal and aborts if this is not the
289  * case, printing both expressions and the values they evaluated to in
290  * hexadecimal format. This macro is for use in unit tests.
291  *
292  * Since: 1.2
293  */
294 #define assert_equals_int_hex(a, b) fail_unless_equals_int_hex(a, b)
295
296 /**
297  * fail_unless_equals_int64:
298  * @a: a #gint64 value or expression
299  * @b: a #gint64 value or expression
300  *
301  * This macro checks that @a and @b are equal and aborts if this is not the
302  * case, printing both expressions and the values they evaluated to. This
303  * macro is for use in unit tests.
304  */
305 #define fail_unless_equals_int64(a, b)                                  \
306 G_STMT_START {                                                          \
307   gint64 first = a;                                                     \
308   gint64 second = b;                                                    \
309   fail_unless(first == second,                                          \
310     "'" #a "' (%" G_GINT64_FORMAT") is not equal to '" #b"' (%"         \
311     G_GINT64_FORMAT")", first, second);                                 \
312 } G_STMT_END;
313 /**
314  * assert_equals_int64:
315  * @a: a #gint64 value or expression
316  * @b: a #gint64 value or expression
317  *
318  * This macro checks that @a and @b are equal and aborts if this is not the
319  * case, printing both expressions and the values they evaluated to. This
320  * macro is for use in unit tests.
321  */
322 #define assert_equals_int64(a, b) fail_unless_equals_int64(a, b)
323
324 /**
325  * fail_unless_equals_int64_hex:
326  * @a: a #gint64 value or expression
327  * @b: a #gint64 value or expression
328  *
329  * This macro checks that @a and @b are equal and aborts if this is not the
330  * case, printing both expressions and the values they evaluated to in
331  * hexadecimal format. This macro is for use in unit tests.
332  *
333  * Since: 1.2
334  */
335 #define fail_unless_equals_int64_hex(a, b)                              \
336 G_STMT_START {                                                          \
337   gint64 first = a;                                                     \
338   gint64 second = b;                                                    \
339   fail_unless(first == second,                                          \
340     "'" #a "' (0x%016x) is not equal to '" #b"' (0x%016x)", first, second);\
341 } G_STMT_END;
342 /**
343  * assert_equals_int64_hex:
344  * @a: a #gint64 value or expression
345  * @b: a #gint64 value or expression
346  *
347  * This macro checks that @a and @b are equal and aborts if this is not the
348  * case, printing both expressions and the values they evaluated to in
349  * hexadecimal format. This macro is for use in unit tests.
350  *
351  * Since: 1.2
352  */
353 #define assert_equals_int64_hex(a,b) fail_unless_equals_int64_hex(a,b)
354
355 /**
356  * fail_unless_equals_uint64:
357  * @a: a #guint64 value or expression
358  * @b: a #guint64 value or expression
359  *
360  * This macro checks that @a and @b are equal and aborts if this is not the
361  * case, printing both expressions and the values they evaluated to. This
362  * macro is for use in unit tests.
363  */
364 #define fail_unless_equals_uint64(a, b)                                 \
365 G_STMT_START {                                                          \
366   guint64 first = a;                                                    \
367   guint64 second = b;                                                   \
368   fail_unless(first == second,                                          \
369     "'" #a "' (%" G_GUINT64_FORMAT ") is not equal to '" #b"' (%"       \
370     G_GUINT64_FORMAT ")", first, second);                               \
371 } G_STMT_END;
372 /**
373  * assert_equals_uint64:
374  * @a: a #guint64 value or expression
375  * @b: a #guint64 value or expression
376  *
377  * This macro checks that @a and @b are equal and aborts if this is not the
378  * case, printing both expressions and the values they evaluated to. This
379  * macro is for use in unit tests.
380  */
381 #define assert_equals_uint64(a, b) fail_unless_equals_uint64(a, b)
382
383 /**
384  * fail_unless_equals_uint64_hex:
385  * @a: a #gint64 value or expression
386  * @b: a #gint64 value or expression
387  *
388  * This macro checks that @a and @b are equal and aborts if this is not the
389  * case, printing both expressions and the values they evaluated to in
390  * hexadecimal format. This macro is for use in unit tests.
391  *
392  * Since: 1.2
393  */
394 #define fail_unless_equals_uint64_hex(a, b)                             \
395 G_STMT_START {                                                          \
396   guint64 first = a;                                                    \
397   guint64 second = b;                                                   \
398   fail_unless(first == second,                                          \
399     "'" #a "' (0x%016x) is not equal to '" #b"' (0x%016x)", first, second);\
400 } G_STMT_END;
401 /**
402  * assert_equals_uint64_hex:
403  * @a: a #guint64 value or expression
404  * @b: a #guint64 value or expression
405  *
406  * This macro checks that @a and @b are equal and aborts if this is not the
407  * case, printing both expressions and the values they evaluated to in
408  * hexadecimal format. This macro is for use in unit tests.
409  *
410  * Since: 1.2
411  */
412 #define assert_equals_uint64_hex(a,b) fail_unless_equals_uint64_hex(a,b)
413
414 /**
415  * fail_unless_equals_string:
416  * @a: a string literal or expression
417  * @b: a string literal or expression
418  *
419  * This macro checks that @a and @b are equal (as per strcmp) and aborts if
420  * this is not the case, printing both expressions and the values they
421  * evaluated to. This macro is for use in unit tests.
422  */
423 #define fail_unless_equals_string(a, b)                             \
424 G_STMT_START {                                                      \
425   const gchar * first = a;                                          \
426   const gchar * second = b;                                         \
427   fail_unless(g_strcmp0 (first, second) == 0,                          \
428     "'" #a "' (%s) is not equal to '" #b"' (%s)", first, second);   \
429 } G_STMT_END;
430 /**
431  * assert_equals_string:
432  * @a: a string literal or expression
433  * @b: a string literal or expression
434  *
435  * This macro checks that @a and @b are equal (as per strcmp) and aborts if
436  * this is not the case, printing both expressions and the values they
437  * evaluated to. This macro is for use in unit tests.
438  */
439 #define assert_equals_string(a, b) fail_unless_equals_string(a, b)
440
441 /**
442  * fail_unless_equals_float:
443  * @a: a #gdouble or #gfloat value or expression
444  * @b: a #gdouble or #gfloat value or expression
445  *
446  * This macro checks that @a and @b are (almost) equal and aborts if this
447  * is not the case, printing both expressions and the values they evaluated
448  * to. This macro is for use in unit tests.
449  */
450 #define fail_unless_equals_float(a, b)                            \
451 G_STMT_START {                                                    \
452   double first = a;                                               \
453   double second = b;                                              \
454   /* This will only work for 'normal' values and values around 0, \
455    * which should be good enough for our purposes here */         \
456   fail_unless(fabs (first - second) < 0.0000001,                  \
457     "'" #a "' (%g) is not equal to '" #b "' (%g)", first, second);\
458 } G_STMT_END;
459
460 /**
461  * assert_equals_float:
462  * @a: a #gdouble or #gfloat value or expression
463  * @b: a #gdouble or #gfloat value or expression
464  *
465  * This macro checks that @a and @b are (almost) equal and aborts if this
466  * is not the case, printing both expressions and the values they evaluated
467  * to. This macro is for use in unit tests.
468  */
469 #define assert_equals_float(a, b) fail_unless_equals_float(a, b)
470
471 /**
472  * fail_unless_equals_pointer:
473  * @a: a pointer value or expression
474  * @b: a pointer value or expression
475  *
476  * This macro checks that @a and @b are equal and aborts if this
477  * is not the case, printing both expressions and the values they
478  * evaluated to. This macro is for use in unit tests.
479  *
480  * Since: 1.2
481  */
482 #define fail_unless_equals_pointer(a, b)                          \
483 G_STMT_START {                                                    \
484   gpointer first = a;                                             \
485   gpointer second = b;                                            \
486   fail_unless(first == second,                                    \
487     "'" #a "' (%p) is not equal to '" #b "' (%p)", first, second);\
488 } G_STMT_END;
489
490 /**
491  * assert_equals_pointer:
492  * @a: a pointer value or expression
493  * @b: a pointer value or expression
494  *
495  * This macro checks that @a and @b are equal and aborts if this
496  * is not the case, printing both expressions and the values they
497  * evaluated to. This macro is for use in unit tests.
498  *
499  * Since: 1.2
500  */
501 #define assert_equals_pointer(a, b) fail_unless_equals_pointer(a, b)
502
503 /***
504  * thread test macros and variables
505  */
506 GST_CHECK_API GList *thread_list;
507 GST_CHECK_API GMutex mutex;
508 GST_CHECK_API GCond start_cond;       /* used to notify main thread of thread startups */
509 GST_CHECK_API GCond sync_cond;        /* used to synchronize all threads and main thread */
510
511 #define MAIN_START_THREADS(count, function, data)               \
512 MAIN_INIT();                                                    \
513 MAIN_START_THREAD_FUNCTIONS(count, function, data);             \
514 MAIN_SYNCHRONIZE();
515
516 #define MAIN_INIT()                     \
517 G_STMT_START {                          \
518   g_mutex_init (&mutex);                \
519   g_cond_init (&start_cond);            \
520   g_cond_init (&sync_cond);             \
521   _gst_check_threads_running = TRUE;    \
522 } G_STMT_END;
523
524 #define MAIN_START_THREAD_FUNCTIONS(count, function, data)      \
525 G_STMT_START {                                                  \
526   int i;                                                        \
527   for (i = 0; i < count; ++i) {                                 \
528     MAIN_START_THREAD_FUNCTION (i, function, data);             \
529   }                                                             \
530 } G_STMT_END;
531
532 #define MAIN_START_THREAD_FUNCTION(i, function, data)           \
533 G_STMT_START {                                                  \
534     GThread *thread = NULL;                                     \
535     GST_DEBUG ("MAIN: creating thread %d", i);                  \
536     g_mutex_lock (&mutex);                                      \
537     thread = g_thread_try_new ("gst-check",                     \
538         (GThreadFunc) function, data, NULL);                    \
539     /* wait for thread to signal us that it's ready */          \
540     GST_DEBUG ("MAIN: waiting for thread %d", i);               \
541     g_cond_wait (&start_cond, &mutex);                          \
542     g_mutex_unlock (&mutex);                                    \
543                                                                 \
544     thread_list = g_list_append (thread_list, thread);          \
545 } G_STMT_END;
546
547
548 #define MAIN_SYNCHRONIZE()              \
549 G_STMT_START {                          \
550   GST_DEBUG ("MAIN: synchronizing");    \
551   g_cond_broadcast (&sync_cond);        \
552   GST_DEBUG ("MAIN: synchronized");     \
553 } G_STMT_END;
554
555 #define MAIN_STOP_THREADS()                                     \
556 G_STMT_START {                                                  \
557   _gst_check_threads_running = FALSE;                           \
558                                                                 \
559   /* join all threads */                                        \
560   GST_DEBUG ("MAIN: joining");                                  \
561   g_list_foreach (thread_list, (GFunc) g_thread_join, NULL);    \
562   g_list_free (thread_list);                                    \
563   thread_list = NULL;                                           \
564   g_mutex_clear (&mutex);                                       \
565   g_cond_clear (&start_cond);                                   \
566   g_cond_clear (&sync_cond);                                    \
567   GST_DEBUG ("MAIN: joined");                                   \
568 } G_STMT_END;
569
570 #define THREAD_START()                                          \
571 THREAD_STARTED();                                               \
572 THREAD_SYNCHRONIZE();
573
574 #define THREAD_STARTED()                                        \
575 G_STMT_START {                                                  \
576   /* signal main thread that we started */                      \
577   GST_DEBUG ("THREAD %p: started", g_thread_self ());           \
578   g_mutex_lock (&mutex);                                        \
579   g_cond_signal (&start_cond);                                  \
580 } G_STMT_END;
581
582 #define THREAD_SYNCHRONIZE()                                    \
583 G_STMT_START {                                                  \
584   /* synchronize everyone */                                    \
585   GST_DEBUG ("THREAD %p: syncing", g_thread_self ());           \
586   fail_if (g_mutex_trylock (&mutex),                            \
587       "bug in unit test, mutex should be locked at this point");\
588   g_cond_wait (&sync_cond, &mutex);                             \
589   GST_DEBUG ("THREAD %p: synced", g_thread_self ());            \
590   g_mutex_unlock (&mutex);                                      \
591 } G_STMT_END;
592
593 #define THREAD_SWITCH()                                         \
594 G_STMT_START {                                                  \
595   /* a minimal sleep is a context switch */                     \
596   g_usleep (1);                                                 \
597 } G_STMT_END;
598
599 #define THREAD_TEST_RUNNING()   (!!_gst_check_threads_running)
600
601 /* additional assertions */
602 #define ASSERT_CRITICAL(code)                                   \
603 G_STMT_START {                                                  \
604   _gst_check_expecting_log = TRUE;                              \
605   _gst_check_raised_critical = FALSE;                           \
606   code;                                                         \
607   if (!_gst_check_raised_critical)                              \
608     _ck_assert_failed (__FILE__, __LINE__,                      \
609         "Expected g_critical, got nothing", NULL);              \
610   _gst_check_expecting_log = FALSE;                             \
611 } G_STMT_END
612
613 #define ASSERT_WARNING(code)                                    \
614 G_STMT_START {                                                  \
615   _gst_check_expecting_log = TRUE;                              \
616   _gst_check_raised_warning = FALSE;                            \
617   code;                                                         \
618   if (!_gst_check_raised_warning)                               \
619     _ck_assert_failed (__FILE__, __LINE__,                      \
620         "Expected g_warning, got nothing", NULL);               \
621   _gst_check_expecting_log = FALSE;                             \
622 } G_STMT_END
623
624
625 #define ASSERT_OBJECT_REFCOUNT(object, name, value)             \
626 G_STMT_START {                                                  \
627   int rc;                                                       \
628   rc = GST_OBJECT_REFCOUNT_VALUE (object);                      \
629   fail_unless (rc == value,                                     \
630       "%s (%p) refcount is %d instead of %d",                   \
631       name, object, rc, value);                                 \
632 } G_STMT_END
633
634 #define ASSERT_OBJECT_REFCOUNT_BETWEEN(object, name, lower, upper)      \
635 G_STMT_START {                                                          \
636   int rc = GST_OBJECT_REFCOUNT_VALUE (object);                          \
637   int lo = lower;                                                       \
638   int hi = upper;                                                       \
639                                                                         \
640   fail_unless (rc >= lo,                                                \
641       "%s (%p) refcount %d is smaller than %d",                         \
642       name, object, rc, lo);                                            \
643   fail_unless (rc <= hi,                                                \
644       "%s (%p) refcount %d is bigger than %d",                          \
645       name, object, rc, hi);                                            \
646 } G_STMT_END
647
648
649 #define ASSERT_CAPS_REFCOUNT(caps, name, value)                 \
650         ASSERT_MINI_OBJECT_REFCOUNT(caps, name, value)
651
652 #define ASSERT_BUFFER_REFCOUNT(buffer, name, value)             \
653         ASSERT_MINI_OBJECT_REFCOUNT(buffer, name, value)
654
655 #define ASSERT_MINI_OBJECT_REFCOUNT(miniobj, name, value)       \
656 G_STMT_START {                                                  \
657   int rc;                                                       \
658   rc = GST_MINI_OBJECT_REFCOUNT_VALUE (miniobj);                \
659   fail_unless (rc == value,                                     \
660                name " (%p) refcount is %d instead of %d", miniobj, rc, value); \
661 } G_STMT_END
662
663 #define ASSERT_SET_STATE(element, state, ret)                   \
664 fail_unless (gst_element_set_state (GST_ELEMENT(element),       \
665   state) == ret,                                                \
666   "could not change state to " #state);
667
668 #define GST_CHECK_MAIN(name)                                    \
669 int main (int argc, char **argv)                                \
670 {                                                               \
671   Suite *s;                                                     \
672   gst_check_init (&argc, &argv);                                \
673   s = name ## _suite ();                                        \
674   return gst_check_run_suite (s, # name, __FILE__);             \
675 }
676
677 /* Hack to allow run-time selection of unit tests to run via the
678  * GST_CHECKS environment variable (test function names globs, comma
679  * separated), or GST_CHECKS_IGNORE with the same semantics */
680
681 GST_CHECK_API
682 gboolean _gst_check_run_test_func (const gchar * func_name);
683
684 static inline void
685 __gst_tcase_add_test (TCase * tc, TFun tf, const char * fname, int signal,
686     int allowed_exit_value, int start, int end)
687 {
688     if (_gst_check_list_tests) {
689         g_print ("Test: %s\n", fname);
690         return;
691     }
692
693     if (_gst_check_run_test_func (fname)) {
694         _tcase_add_test (tc, tf, fname, signal, allowed_exit_value, start, end);
695     }
696 }
697
698 #define _tcase_add_test __gst_tcase_add_test
699
700 /* A special variant to add broken tests. These are normally skipped, but can be
701  * forced to run via GST_CHECKS */
702 #define tcase_skip_broken_test(chain,test_func) \
703 G_STMT_START {                                                  \
704   const char *env = g_getenv ("GST_CHECKS");                    \
705                                                                 \
706   if (env != NULL && g_pattern_match_simple (env, G_STRINGIFY (test_func))) {   \
707     tcase_add_test(chain,test_func);                            \
708   } else {                                                      \
709     g_printerr ("FIXME: skipping test %s because it's broken\n", G_STRINGIFY (test_func)); \
710   } \
711 } G_STMT_END
712
713 #define tcase_skip_broken_loop_test(chain,test_func,a,b)        \
714   tcase_skip_broken_test (chain, test_func)
715
716 G_END_DECLS
717
718 #endif /* __GST_CHECK_H__ */