Debian Codegraph @

libs/gst/check/gstcheck.h

raw
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 <[email protected]>
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 gint gst_check_run_suite_nofork (Suite * suite, const gchar * name,
195 const gchar * fname);
196
197 GST_CHECK_API
198 void gst_check_setup_events (GstPad * srcpad, GstElement * element,
199 GstCaps * caps, GstFormat format);
200
201 GST_CHECK_API
202 void gst_check_setup_events_with_stream_id (GstPad * srcpad,
203 GstElement * element, GstCaps * caps, GstFormat format,
204 const gchar * stream_id);
205
206 GST_CHECK_API
207 void gst_check_objects_destroyed_on_unref (gpointer object_to_unref, gpointer first_object, ...)
208 G_GNUC_NULL_TERMINATED;
209
210 GST_CHECK_API
211 void gst_check_object_destroyed_on_unref (gpointer object_to_unref);
212
213 #ifndef __GI_SCANNER__
214
215 #define fail_unless_message_error(msg, domain, code) \
216 gst_check_message_error (msg, GST_MESSAGE_ERROR, \
217 GST_ ## domain ## _ERROR, GST_ ## domain ## _ERROR_ ## code)
218 #define assert_message_error(m, d, c) fail_unless_message_error(m, d, c)
219
220 #ifdef GST_CHECK_TEST_ENVIRONMENT_BEACON
221 #define GST_DO_CHECK_TEST_ENVIRONMENT \
222 G_STMT_START { \
223 if (g_getenv (GST_CHECK_TEST_ENVIRONMENT_BEACON) == NULL) \
224 fail ("Test environment not set up correctly! Expected environment " \
225 "variable '%s' to be set.", GST_CHECK_TEST_ENVIRONMENT_BEACON); \
226 } G_STMT_END
227
228 #else
229 #define GST_DO_CHECK_TEST_ENVIRONMENT /* nothing to check */
230 #endif
231
232 /**
233 * GST_START_TEST:
234 * @__testname: test function name
235 *
236 * wrapper for checks START_TEST
237 */
238 /**
239 * GST_END_TEST:
240 *
241 * wrapper for checks END_TEST
242 */
243 #define GST_START_TEST(__testname) \
244 static void __testname (int G_GNUC_UNUSED __i__) \
245 {\
246 GST_DEBUG ("test start"); \
247 GST_DO_CHECK_TEST_ENVIRONMENT; \
248 tcase_fn_start (""# __testname, __FILE__, __LINE__);
249
250 #define GST_END_TEST GST_LOG ("cleaning up tasks"); \
251 gst_task_cleanup_all (); \
252 END_TEST
253
254 /* additional fail macros */
255 /**
256 * fail_unless_equals_int:
257 * @a: a #gint value or expression
258 * @b: a #gint value or expression
259 *
260 * This macro checks that @a and @b are equal and aborts if this is not the
261 * case, printing both expressions and the values they evaluated to. This
262 * macro is for use in unit tests.
263 */
264 #define fail_unless_equals_int(a, b) \
265 G_STMT_START { \
266 int first = a; \
267 int second = b; \
268 fail_unless(first == second, \
269 "'" #a "' (%d) is not equal to '" #b"' (%d)", first, second); \
270 } G_STMT_END;
271 /**
272 * assert_equals_int:
273 * @a: a #gint value or expression
274 * @b: a #gint value or expression
275 *
276 * This macro checks that @a and @b are equal and aborts if this is not the
277 * case, printing both expressions and the values they evaluated to. This
278 * macro is for use in unit tests.
279 */
280 #define assert_equals_int(a, b) fail_unless_equals_int(a, b)
281
282 /**
283 * fail_unless_equals_int_hex:
284 * @a: a #gint value or expression
285 * @b: a #gint value or expression
286 *
287 * This macro checks that @a and @b are equal and aborts if this is not the
288 * case, printing both expressions and the values they evaluated to in
289 * hexadecimal format. This macro is for use in unit tests.
290 *
291 * Since: 1.2
292 */
293 #define fail_unless_equals_int_hex(a, b) \
294 G_STMT_START { \
295 int first = a; \
296 int second = b; \
297 fail_unless(first == second, \
298 "'" #a "' (0x%08x) is not equal to '" #b"' (0x%08x)", first, second);\
299 } G_STMT_END;
300
301 /**
302 * assert_equals_int_hex:
303 * @a: a #gint value or expression
304 * @b: a #gint value or expression
305 *
306 * This macro checks that @a and @b are equal and aborts if this is not the
307 * case, printing both expressions and the values they evaluated to in
308 * hexadecimal format. This macro is for use in unit tests.
309 *
310 * Since: 1.2
311 */
312 #define assert_equals_int_hex(a, b) fail_unless_equals_int_hex(a, b)
313
314 /**
315 * fail_unless_equals_int64:
316 * @a: a #gint64 value or expression
317 * @b: a #gint64 value or expression
318 *
319 * This macro checks that @a and @b are equal and aborts if this is not the
320 * case, printing both expressions and the values they evaluated to. This
321 * macro is for use in unit tests.
322 */
323 #define fail_unless_equals_int64(a, b) \
324 G_STMT_START { \
325 gint64 first = a; \
326 gint64 second = b; \
327 fail_unless(first == second, \
328 "'" #a "' (%" G_GINT64_FORMAT") is not equal to '" #b"' (%" \
329 G_GINT64_FORMAT")", first, second); \
330 } G_STMT_END;
331 /**
332 * assert_equals_int64:
333 * @a: a #gint64 value or expression
334 * @b: a #gint64 value or expression
335 *
336 * This macro checks that @a and @b are equal and aborts if this is not the
337 * case, printing both expressions and the values they evaluated to. This
338 * macro is for use in unit tests.
339 */
340 #define assert_equals_int64(a, b) fail_unless_equals_int64(a, b)
341
342 /**
343 * fail_unless_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 fail_unless_equals_int64_hex(a, b) \
354 G_STMT_START { \
355 gint64 first = a; \
356 gint64 second = b; \
357 fail_unless(first == second, \
358 "'" #a "' (0x%016x) is not equal to '" #b"' (0x%016x)", first, second);\
359 } G_STMT_END;
360 /**
361 * assert_equals_int64_hex:
362 * @a: a #gint64 value or expression
363 * @b: a #gint64 value or expression
364 *
365 * This macro checks that @a and @b are equal and aborts if this is not the
366 * case, printing both expressions and the values they evaluated to in
367 * hexadecimal format. This macro is for use in unit tests.
368 *
369 * Since: 1.2
370 */
371 #define assert_equals_int64_hex(a,b) fail_unless_equals_int64_hex(a,b)
372
373 /**
374 * fail_unless_equals_uint64:
375 * @a: a #guint64 value or expression
376 * @b: a #guint64 value or expression
377 *
378 * This macro checks that @a and @b are equal and aborts if this is not the
379 * case, printing both expressions and the values they evaluated to. This
380 * macro is for use in unit tests.
381 */
382 #define fail_unless_equals_uint64(a, b) \
383 G_STMT_START { \
384 guint64 first = a; \
385 guint64 second = b; \
386 fail_unless(first == second, \
387 "'" #a "' (%" G_GUINT64_FORMAT ") is not equal to '" #b"' (%" \
388 G_GUINT64_FORMAT ")", first, second); \
389 } G_STMT_END;
390 /**
391 * assert_equals_uint64:
392 * @a: a #guint64 value or expression
393 * @b: a #guint64 value or expression
394 *
395 * This macro checks that @a and @b are equal and aborts if this is not the
396 * case, printing both expressions and the values they evaluated to. This
397 * macro is for use in unit tests.
398 */
399 #define assert_equals_uint64(a, b) fail_unless_equals_uint64(a, b)
400
401 /**
402 * fail_unless_equals_uint64_hex:
403 * @a: a #gint64 value or expression
404 * @b: a #gint64 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 fail_unless_equals_uint64_hex(a, b) \
413 G_STMT_START { \
414 guint64 first = a; \
415 guint64 second = b; \
416 fail_unless(first == second, \
417 "'" #a "' (0x%016x) is not equal to '" #b"' (0x%016x)", first, second);\
418 } G_STMT_END;
419 /**
420 * assert_equals_uint64_hex:
421 * @a: a #guint64 value or expression
422 * @b: a #guint64 value or expression
423 *
424 * This macro checks that @a and @b are equal and aborts if this is not the
425 * case, printing both expressions and the values they evaluated to in
426 * hexadecimal format. This macro is for use in unit tests.
427 *
428 * Since: 1.2
429 */
430 #define assert_equals_uint64_hex(a,b) fail_unless_equals_uint64_hex(a,b)
431
432 /**
433 * fail_unless_equals_string:
434 * @a: a string literal or expression
435 * @b: a string literal or expression
436 *
437 * This macro checks that @a and @b are equal (as per g_strcmp0()) and aborts if
438 * this is not the case, printing both expressions and the values they
439 * evaluated to. This macro is for use in unit tests.
440 */
441 #define fail_unless_equals_string(a, b) \
442 G_STMT_START { \
443 const gchar * first = a; \
444 const gchar * second = b; \
445 fail_unless(g_strcmp0 (first, second) == 0, \
446 "'" #a "' (%s) is not equal to '" #b"' (%s)", first, second); \
447 } G_STMT_END;
448 /**
449 * assert_equals_string:
450 * @a: a string literal or expression
451 * @b: a string literal or expression
452 *
453 * This macro checks that @a and @b are equal (as per g_strcmp0()) and aborts if
454 * this is not the case, printing both expressions and the values they
455 * evaluated to. This macro is for use in unit tests.
456 */
457 #define assert_equals_string(a, b) fail_unless_equals_string(a, b)
458
459 /**
460 * fail_unless_matches_string:
461 * @a: a string literal or expression
462 * @b: a regular expression pattern string literal or expression
463 *
464 * This macro checks that @a matches the regular expression in @b aborts if
465 * this is not the case, printing both expressions and the values they
466 * evaluated to. This macro is for use in unit tests.
467 *
468 * Since: 1.26
469 */
470 #define fail_unless_matches_string(a, b) \
471 G_STMT_START { \
472 const gchar * first = a; \
473 const gchar * second = b; \
474 fail_unless(g_regex_match_simple (second, first, 0, 0), \
475 "'" #a "' (%s) does not match pattern '" #b"' (%s)", first, second); \
476 } G_STMT_END;
477 /**
478 * assert_matches_string:
479 * @a: a string literal or expression
480 * @b: a regular expression pattern string literal or expression
481 *
482 * This macro checks that @a matches the regular expression in @b aborts if
483 * this is not the case, printing both expressions and the values they
484 * evaluated to. This macro is for use in unit tests.
485 *
486 * Since: 1.26
487 */
488 #define assert_matches_string(a, b) fail_unless_matches_string(a, b)
489
490 /**
491 * fail_unless_equals_float:
492 * @a: a #gdouble or #gfloat value or expression
493 * @b: a #gdouble or #gfloat value or expression
494 *
495 * This macro checks that @a and @b are (almost) equal and aborts if this
496 * is not the case, printing both expressions and the values they evaluated
497 * to. This macro is for use in unit tests.
498 */
499 #define fail_unless_equals_float(a, b) \
500 G_STMT_START { \
501 double first = a; \
502 double second = b; \
503 /* This will only work for 'normal' values and values around 0, \
504 * which should be good enough for our purposes here */ \
505 fail_unless(fabs (first - second) < 0.0000001, \
506 "'" #a "' (%g) is not equal to '" #b "' (%g)", first, second);\
507 } G_STMT_END;
508
509 /**
510 * assert_equals_float:
511 * @a: a #gdouble or #gfloat value or expression
512 * @b: a #gdouble or #gfloat value or expression
513 *
514 * This macro checks that @a and @b are (almost) equal and aborts if this
515 * is not the case, printing both expressions and the values they evaluated
516 * to. This macro is for use in unit tests.
517 */
518 #define assert_equals_float(a, b) fail_unless_equals_float(a, b)
519
520 /**
521 * fail_unless_equals_pointer:
522 * @a: a pointer value or expression
523 * @b: a pointer value or expression
524 *
525 * This macro checks that @a and @b are equal and aborts if this
526 * is not the case, printing both expressions and the values they
527 * evaluated to. This macro is for use in unit tests.
528 *
529 * Since: 1.2
530 */
531 #define fail_unless_equals_pointer(a, b) \
532 G_STMT_START { \
533 gpointer first = a; \
534 gpointer second = b; \
535 fail_unless(first == second, \
536 "'" #a "' (%p) is not equal to '" #b "' (%p)", first, second);\
537 } G_STMT_END;
538
539 /**
540 * assert_equals_pointer:
541 * @a: a pointer value or expression
542 * @b: a pointer value or expression
543 *
544 * This macro checks that @a and @b are equal and aborts if this
545 * is not the case, printing both expressions and the values they
546 * evaluated to. This macro is for use in unit tests.
547 *
548 * Since: 1.2
549 */
550 #define assert_equals_pointer(a, b) fail_unless_equals_pointer(a, b)
551
552 /**
553 * fail_unless_equals_clocktime:
554 * @a: a #GstClockTime value or expression
555 * @b: a #GstClockTime value or expression
556 *
557 * This macro checks that @a and @b are equal and aborts if this is not the
558 * case, printing both expressions and the values they evaluated to. This
559 * macro is for use in unit tests.
560 */
561 #define fail_unless_equals_clocktime(a, b) \
562 G_STMT_START { \
563 GstClockTime first = a; \
564 GstClockTime second = b; \
565 fail_unless(first == second, \
566 "'" #a "' (%" GST_TIME_FORMAT") is not equal to '" #b"' (%" GST_TIME_FORMAT")", \
567 GST_TIME_ARGS (first), GST_TIME_ARGS (second)); \
568 } G_STMT_END;
569
570 /***
571 * thread test macros and variables
572 */
573 GST_CHECK_API GList *thread_list;
574 GST_CHECK_API GMutex mutex;
575 GST_CHECK_API GCond start_cond; /* used to notify main thread of thread startups */
576 GST_CHECK_API GCond sync_cond; /* used to synchronize all threads and main thread */
577
578 #define MAIN_START_THREADS(count, function, data) \
579 MAIN_INIT(); \
580 MAIN_START_THREAD_FUNCTIONS(count, function, data); \
581 MAIN_SYNCHRONIZE();
582
583 #define MAIN_INIT() \
584 G_STMT_START { \
585 g_mutex_init (&mutex); \
586 g_cond_init (&start_cond); \
587 g_cond_init (&sync_cond); \
588 _gst_check_threads_running = TRUE; \
589 } G_STMT_END;
590
591 #define MAIN_START_THREAD_FUNCTIONS(count, function, data) \
592 G_STMT_START { \
593 int i; \
594 for (i = 0; i < count; ++i) { \
595 MAIN_START_THREAD_FUNCTION (i, function, data); \
596 } \
597 } G_STMT_END;
598
599 #define MAIN_START_THREAD_FUNCTION(i, function, data) \
600 G_STMT_START { \
601 GThread *thread = NULL; \
602 GST_DEBUG ("MAIN: creating thread %d", i); \
603 g_mutex_lock (&mutex); \
604 thread = g_thread_try_new ("gst-check", \
605 (GThreadFunc) function, data, NULL); \
606 /* wait for thread to signal us that it's ready */ \
607 GST_DEBUG ("MAIN: waiting for thread %d", i); \
608 g_cond_wait (&start_cond, &mutex); \
609 g_mutex_unlock (&mutex); \
610 \
611 thread_list = g_list_append (thread_list, thread); \
612 } G_STMT_END;
613
614
615 #define MAIN_SYNCHRONIZE() \
616 G_STMT_START { \
617 GST_DEBUG ("MAIN: synchronizing"); \
618 g_cond_broadcast (&sync_cond); \
619 GST_DEBUG ("MAIN: synchronized"); \
620 } G_STMT_END;
621
622 #define MAIN_STOP_THREADS() \
623 G_STMT_START { \
624 _gst_check_threads_running = FALSE; \
625 \
626 /* join all threads */ \
627 GST_DEBUG ("MAIN: joining"); \
628 g_list_foreach (thread_list, (GFunc) g_thread_join, NULL); \
629 g_list_free (thread_list); \
630 thread_list = NULL; \
631 g_mutex_clear (&mutex); \
632 g_cond_clear (&start_cond); \
633 g_cond_clear (&sync_cond); \
634 GST_DEBUG ("MAIN: joined"); \
635 } G_STMT_END;
636
637 #define THREAD_START() \
638 THREAD_STARTED(); \
639 THREAD_SYNCHRONIZE();
640
641 #define THREAD_STARTED() \
642 G_STMT_START { \
643 /* signal main thread that we started */ \
644 GST_DEBUG ("THREAD %p: started", g_thread_self ()); \
645 g_mutex_lock (&mutex); \
646 g_cond_signal (&start_cond); \
647 } G_STMT_END;
648
649 #define THREAD_SYNCHRONIZE() \
650 G_STMT_START { \
651 /* synchronize everyone */ \
652 GST_DEBUG ("THREAD %p: syncing", g_thread_self ()); \
653 fail_if (g_mutex_trylock (&mutex), \
654 "bug in unit test, mutex should be locked at this point");\
655 g_cond_wait (&sync_cond, &mutex); \
656 GST_DEBUG ("THREAD %p: synced", g_thread_self ()); \
657 g_mutex_unlock (&mutex); \
658 } G_STMT_END;
659
660 #define THREAD_SWITCH() \
661 G_STMT_START { \
662 g_thread_yield (); \
663 } G_STMT_END;
664
665 #define THREAD_TEST_RUNNING() (!!_gst_check_threads_running)
666
667 /* additional assertions */
668
669 #if GST_DISABLE_GLIB_CHECKS
670 #define ASSERT_CRITICAL(code)
671 #else
672 #define ASSERT_CRITICAL(code) \
673 G_STMT_START { \
674 _gst_check_expecting_log = TRUE; \
675 _gst_check_raised_critical = FALSE; \
676 code; \
677 if (!_gst_check_raised_critical) \
678 _ck_assert_failed (__FILE__, __LINE__, \
679 "Expected g_critical, got nothing", NULL); \
680 _gst_check_expecting_log = FALSE; \
681 } G_STMT_END
682 #endif /* GST_DISABLE_GLIB_CHECKS */
683
684 #define ASSERT_WARNING(code) \
685 G_STMT_START { \
686 _gst_check_expecting_log = TRUE; \
687 _gst_check_raised_warning = FALSE; \
688 code; \
689 if (!_gst_check_raised_warning) \
690 _ck_assert_failed (__FILE__, __LINE__, \
691 "Expected g_warning, got nothing", NULL); \
692 _gst_check_expecting_log = FALSE; \
693 } G_STMT_END
694
695
696 #define ASSERT_OBJECT_REFCOUNT(object, name, value) \
697 G_STMT_START { \
698 int rc; \
699 rc = GST_OBJECT_REFCOUNT_VALUE (object); \
700 fail_unless (rc == value, \
701 "%s (%p) refcount is %d instead of %d", \
702 name, object, rc, value); \
703 } G_STMT_END
704
705 #define ASSERT_OBJECT_REFCOUNT_BETWEEN(object, name, lower, upper) \
706 G_STMT_START { \
707 int rc = GST_OBJECT_REFCOUNT_VALUE (object); \
708 int lo = lower; \
709 int hi = upper; \
710 \
711 fail_unless (rc >= lo, \
712 "%s (%p) refcount %d is smaller than %d", \
713 name, object, rc, lo); \
714 fail_unless (rc <= hi, \
715 "%s (%p) refcount %d is bigger than %d", \
716 name, object, rc, hi); \
717 } G_STMT_END
718
719
720 #define ASSERT_CAPS_REFCOUNT(caps, name, value) \
721 ASSERT_MINI_OBJECT_REFCOUNT(caps, name, value)
722
723 #define ASSERT_BUFFER_REFCOUNT(buffer, name, value) \
724 ASSERT_MINI_OBJECT_REFCOUNT(buffer, name, value)
725
726 #define ASSERT_MINI_OBJECT_REFCOUNT(miniobj, name, value) \
727 G_STMT_START { \
728 int rc; \
729 rc = GST_MINI_OBJECT_REFCOUNT_VALUE (miniobj); \
730 fail_unless (rc == value, \
731 name " (%p) refcount is %d instead of %d", miniobj, rc, value); \
732 } G_STMT_END
733
734 #define ASSERT_SET_STATE(element, state, ret) \
735 fail_unless (gst_element_set_state (GST_ELEMENT(element), \
736 state) == ret, \
737 "could not change state to " #state);
738
739 #define GST_CHECK_MAIN(name) \
740 int main (int argc, char **argv) \
741 { \
742 Suite *s; \
743 gst_check_init (&argc, &argv); \
744 s = name ## _suite (); \
745 return gst_check_run_suite (s, # name, __FILE__); \
746 }
747
748 /**
749 * GST_CHECK_MAIN_NOFORK:
750 *
751 * Runs a given test suite with fork usage explicitly disabled.
752 *
753 * Since: 1.30
754 */
755 #define GST_CHECK_MAIN_NOFORK(name) \
756 int main (int argc, char **argv) \
757 { \
758 Suite *s; \
759 gst_check_init (&argc, &argv); \
760 s = name ## _suite (); \
761 return gst_check_run_suite_nofork (s, # name, __FILE__); \
762 }
763
764 /* Hack to allow run-time selection of unit tests to run via the
765 * GST_CHECKS environment variable (test function names globs, comma
766 * separated), or GST_CHECKS_IGNORE with the same semantics */
767
768 GST_CHECK_API
769 gboolean _gst_check_run_test_func (const gchar * func_name);
770
771 static inline void
772 __gst_tcase_add_test (TCase * tc, TFun tf, const char * fname, int signal,
773 int allowed_exit_value, int start, int end)
774 {
775 if (_gst_check_list_tests) {
776 g_print ("Test: %s\n", fname);
777 return;
778 }
779
780 if (_gst_check_run_test_func (fname)) {
781 _tcase_add_test (tc, tf, fname, signal, allowed_exit_value, start, end);
782 }
783 }
784
785 #define _tcase_add_test __gst_tcase_add_test
786
787 /* A special variant to add broken tests. These are normally skipped, but can be
788 * forced to run via GST_CHECKS */
789 #define tcase_skip_broken_test(chain,test_func) \
790 G_STMT_START { \
791 const char *env = g_getenv ("GST_CHECKS"); \
792 \
793 if (env != NULL && g_pattern_match_simple (env, G_STRINGIFY (test_func))) { \
794 tcase_add_test(chain,test_func); \
795 } else { \
796 g_printerr ("FIXME: skipping test %s because it's broken\n", G_STRINGIFY (test_func)); \
797 } \
798 } G_STMT_END
799
800 #define tcase_skip_broken_loop_test(chain,test_func,a,b) \
801 tcase_skip_broken_test (chain, test_func)
802
803 #endif /* !__GI_SCANNER__ */
804
805 G_END_DECLS
806
807 #endif /* __GST_CHECK_H__ */