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