Debian Codegraph @

libs/gst/check/gstcheck.c

raw
1 /* GStreamer
2 *
3 * Common code for GStreamer unittests
4 *
5 * Copyright (C) 2004,2006 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 * SECTION:gstcheck
25 * @title: GstCheck
26 * @short_description: Common code for GStreamer unit tests
27 *
28 * These macros and functions are for internal use of the unit tests found
29 * inside the 'check' directories of various GStreamer packages.
30 *
31 * One notable feature is that one can use the environment variables GST_CHECKS
32 * and GST_CHECKS_IGNORE to select which tests to run or skip. Both variables
33 * can contain a comma separated list of test name globs (e.g. test_*).
34 */
35 #ifdef HAVE_CONFIG_H
36 #include "config.h"
37 #endif
38
39 #include "gstcheck.h"
40
41 GST_DEBUG_CATEGORY (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
49 gboolean _gst_check_threads_running = FALSE;
50 GList *thread_list = NULL;
51 GMutex mutex;
52 GCond start_cond; /* used to notify main thread of thread startups */
53 GCond sync_cond; /* used to synchronize all threads and main thread */
54
55 GList *buffers = NULL;
56 GMutex check_mutex;
57 GCond check_cond;
58
59 /* FIXME 2.0: shouldn't _gst_check_debug be static? Not used anywhere */
60 gboolean _gst_check_debug = FALSE;
61 gboolean _gst_check_raised_critical = FALSE;
62 gboolean _gst_check_raised_warning = FALSE;
63 gboolean _gst_check_expecting_log = FALSE;
64 gboolean _gst_check_list_tests = FALSE;
65 static GQueue _gst_check_log_filters = G_QUEUE_INIT;
66 static GMutex _gst_check_log_filters_mutex;
67
68 struct _GstCheckLogFilter
69 {
70 gchar *log_domain;
71 GLogLevelFlags log_level;
72 GRegex *regex;
73 GstCheckLogFilterFunc func;
74 gpointer user_data;
75 GDestroyNotify destroy;
76 };
77
78
79 static gboolean
80 gst_check_match_log_filter (const GstCheckLogFilter * filter,
81 const gchar * log_domain, GLogLevelFlags log_level, const gchar * message)
82 {
83 if (g_strcmp0 (log_domain, filter->log_domain) != 0)
84 return FALSE;
85
86 if ((log_level & filter->log_level) == 0)
87 return FALSE;
88
89 if (!g_regex_match (filter->regex, message, 0, NULL))
90 return FALSE;
91
92 return TRUE;
93 }
94
95 static GstCheckLogFilter *
96 gst_check_alloc_log_filter (const gchar * log_domain, GLogLevelFlags log_level,
97 GRegex * regex, GstCheckLogFilterFunc func, gpointer user_data,
98 GDestroyNotify destroy_data)
99 {
100 GstCheckLogFilter *filter;
101
102 filter = g_new (GstCheckLogFilter, 1);
103 filter->log_domain = g_strdup (log_domain);
104 filter->log_level = log_level;
105 filter->regex = regex;
106 filter->func = func;
107 filter->user_data = user_data;
108 filter->destroy = destroy_data;
109
110 return filter;
111 }
112
113 static void
114 gst_check_free_log_filter (GstCheckLogFilter * filter)
115 {
116 if (!filter)
117 return;
118
119 g_free (filter->log_domain);
120 g_regex_unref (filter->regex);
121 if (filter->destroy)
122 filter->destroy (filter->user_data);
123 g_free (filter);
124 }
125
126
127 /**
128 * gst_check_add_log_filter: (skip)
129 * @log_domain: the log domain of the message
130 * @log_level: the log level of the message
131 * @regex: (transfer full): a #GRegex to match the message
132 * @func: the function to call for matching messages
133 * @user_data: the user data to pass to @func
134 * @destroy_data: #GDestroyNotify for @user_data
135 *
136 * Add a callback @func to be called for all log messages that matches
137 * @log_domain, @log_level and @regex. If @func is NULL the
138 * matching logs will be silently discarded by GstCheck.
139 *
140 * MT safe.
141 *
142 * Returns: A filter that can be passed to @gst_check_remove_log_filter.
143 *
144 * Since: 1.12
145 **/
146 GstCheckLogFilter *
147 gst_check_add_log_filter (const gchar * log_domain, GLogLevelFlags log_level,
148 GRegex * regex, GstCheckLogFilterFunc func, gpointer user_data,
149 GDestroyNotify destroy_data)
150 {
151 GstCheckLogFilter *filter;
152
153 g_return_val_if_fail (regex != NULL, NULL);
154
155 filter = gst_check_alloc_log_filter (log_domain, log_level, regex,
156 func, user_data, destroy_data);
157 g_mutex_lock (&_gst_check_log_filters_mutex);
158 g_queue_push_tail (&_gst_check_log_filters, filter);
159 g_mutex_unlock (&_gst_check_log_filters_mutex);
160
161 return filter;
162 }
163
164 /**
165 * gst_check_remove_log_filter:
166 * @filter: Filter returned by @gst_check_add_log_filter
167 *
168 * Remove a filter that has been added by @gst_check_add_log_filter.
169 *
170 * MT safe.
171 *
172 * Since: 1.12
173 **/
174 void
175 gst_check_remove_log_filter (GstCheckLogFilter * filter)
176 {
177 g_mutex_lock (&_gst_check_log_filters_mutex);
178 g_queue_remove (&_gst_check_log_filters, filter);
179 gst_check_free_log_filter (filter);
180 g_mutex_unlock (&_gst_check_log_filters_mutex);
181 }
182
183 /**
184 * gst_check_clear_log_filter:
185 *
186 * Clear all filters added by @gst_check_add_log_filter.
187 *
188 * MT safe.
189 *
190 * Since: 1.12
191 **/
192 void
193 gst_check_clear_log_filter (void)
194 {
195 g_mutex_lock (&_gst_check_log_filters_mutex);
196 g_queue_foreach (&_gst_check_log_filters,
197 (GFunc) gst_check_free_log_filter, NULL);
198 g_queue_clear (&_gst_check_log_filters);
199 g_mutex_unlock (&_gst_check_log_filters_mutex);
200 }
201
202 typedef struct
203 {
204 const gchar *domain;
205 const gchar *message;
206 GLogLevelFlags level;
207 gboolean discard;
208 } LogFilterApplyData;
209
210 static void
211 gst_check_apply_log_filter (GstCheckLogFilter * filter,
212 LogFilterApplyData * data)
213 {
214 if (gst_check_match_log_filter (filter, data->domain, data->level,
215 data->message)) {
216 if (filter->func)
217 data->discard |= filter->func (data->domain, data->level,
218 data->message, filter->user_data);
219 else
220 data->discard = TRUE;
221 }
222 }
223
224 static gboolean
225 gst_check_filter_log_filter (const gchar * log_domain,
226 GLogLevelFlags log_level, const gchar * message)
227 {
228 LogFilterApplyData data;
229
230 data.domain = log_domain;
231 data.level = log_level;
232 data.message = message;
233 data.discard = FALSE;
234
235 g_mutex_lock (&_gst_check_log_filters_mutex);
236 g_queue_foreach (&_gst_check_log_filters, (GFunc) gst_check_apply_log_filter,
237 &data);
238 g_mutex_unlock (&_gst_check_log_filters_mutex);
239
240 if (data.discard)
241 GST_DEBUG ("Discarding message: %s", message);
242
243 return data.discard;
244 }
245
246 static gboolean
247 gst_check_log_fatal_func (const gchar * log_domain, GLogLevelFlags log_level,
248 const gchar * message, gpointer user_data)
249 {
250 if (gst_check_filter_log_filter (log_domain, log_level, message))
251 return FALSE;
252
253 return TRUE;
254 }
255
256
257 static void gst_check_log_message_func
258 (const gchar * log_domain, GLogLevelFlags log_level,
259 const gchar * message, gpointer user_data)
260 {
261 if (gst_check_filter_log_filter (log_domain, log_level, message))
262 return;
263
264 if (_gst_check_debug) {
265 g_print ("%s\n", message);
266 }
267 }
268
269 static void gst_check_log_critical_func
270 (const gchar * log_domain, GLogLevelFlags log_level,
271 const gchar * message, gpointer user_data)
272 {
273 if (gst_check_filter_log_filter (log_domain, log_level, message))
274 return;
275
276 if (!_gst_check_expecting_log) {
277 gchar *trace;
278
279 g_print ("\n\nUnexpected critical/warning: %s\n", message);
280
281 trace = gst_debug_get_stack_trace (GST_STACK_TRACE_SHOW_FULL);
282 if (trace) {
283 g_print ("\nStack trace:\n%s\n", trace);
284 g_free (trace);
285 }
286 fail ("Unexpected critical/warning: %s", message);
287 }
288
289 if (_gst_check_debug) {
290 g_print ("\nExpected critical/warning: %s\n", message);
291 }
292
293 if (log_level & G_LOG_LEVEL_CRITICAL)
294 _gst_check_raised_critical = TRUE;
295 if (log_level & G_LOG_LEVEL_WARNING)
296 _gst_check_raised_warning = TRUE;
297 }
298
299 static gint
300 sort_plugins (GstPlugin * a, GstPlugin * b)
301 {
302 int ret;
303
304 ret = strcmp (gst_plugin_get_source (a), gst_plugin_get_source (b));
305 if (ret == 0)
306 ret = strcmp (gst_plugin_get_name (a), gst_plugin_get_name (b));
307 return ret;
308 }
309
310 static void
311 print_plugins (void)
312 {
313 GList *plugins, *l;
314
315 plugins = gst_registry_get_plugin_list (gst_registry_get ());
316 plugins = g_list_sort (plugins, (GCompareFunc) sort_plugins);
317 for (l = plugins; l != NULL; l = l->next) {
318 GstPlugin *plugin = GST_PLUGIN (l->data);
319
320 if (strcmp (gst_plugin_get_source (plugin), "BLACKLIST") != 0) {
321 GST_LOG ("%20s@%s", gst_plugin_get_name (plugin),
322 GST_STR_NULL (gst_plugin_get_filename (plugin)));
323 }
324 }
325 gst_plugin_list_free (plugins);
326 }
327
328 static void
329 gst_check_deinit (void)
330 {
331 gst_deinit ();
332 gst_check_clear_log_filter ();
333 }
334
335 static const gchar *log_domains[] = {
336 "GLib-GObject",
337 "GLib-GIO",
338 "GLib",
339 "GStreamer-AdaptiveDemux",
340 "GStreamer-Allocators",
341 "GStreamer-App",
342 "GStreamer-Audio",
343 "GStreamer-AudioBad",
344 "GStreamer-Base",
345 "GStreamer-BaseCameraBinSrc",
346 "GStreamer-Check",
347 "GStreamer-CodecParsers",
348 "GStreamer-Codecs",
349 "GStreamer-Controller",
350 "GStreamer-D3D11",
351 "GStreamer",
352 "GStreamer-FFT",
353 "GStreamer-GL",
354 "GStreamer-InsertBin",
355 "GStreamer-ISOFF",
356 "GStreamer-MSE",
357 "GStreamer-MpegTS",
358 "GStreamer-Net",
359 "GStreamer-OpenCV",
360 "GStreamer-PBUtils",
361 "GStreamer-Photography",
362 "GStreamer-Play",
363 "GStreamer-Player",
364 "GStreamer-RIFF",
365 "GStreamer-RTP",
366 "GStreamer-RTSP",
367 "GStreamer-RTSP-Server",
368 "GStreamer-SCTP",
369 "GStreamer-SDP",
370 "GStreamer-Tag",
371 "GStreamer-Transcoder",
372 "GStreamer-UriDownloader",
373 "GStreamer-VA",
374 "GStreamer-Video",
375 "GStreamer-Vulkan",
376 "GStreamer-Vulkan",
377 "GStreamer-Wayland",
378 "GStreamer-WebRTC",
379 "GStreamer-WinRT",
380 };
381
382 /* gst_check_init:
383 * @argc: (inout) (allow-none): pointer to application's argc
384 * @argv: (inout) (array length=argc) (allow-none): pointer to application's argv
385 *
386 * Initialize GStreamer testing
387 *
388 * NOTE: Needs to be called before creating the testsuite
389 * so that the tests can be listed.
390 * */
391 void
392 gst_check_init (int *argc, char **argv[])
393 {
394 guint timeout_multiplier = 1;
395 GOptionContext *ctx;
396 GError *err = NULL;
397 GOptionEntry options[] = {
398 {"list-tests", 'l', 0, G_OPTION_ARG_NONE, &_gst_check_list_tests,
399 "List tests present in the testsuite", NULL},
400 {NULL}
401 };
402 guint i;
403
404 ctx = g_option_context_new ("gst-check");
405 g_option_context_add_main_entries (ctx, options, NULL);
406 g_option_context_add_group (ctx, gst_init_get_option_group ());
407
408 if (!g_option_context_parse (ctx, argc, argv, &err)) {
409 if (err)
410 g_printerr ("Error initializing: %s\n", GST_STR_NULL (err->message));
411 else
412 g_printerr ("Error initializing: Unknown error!\n");
413 g_clear_error (&err);
414 }
415 g_option_context_free (ctx);
416
417 GST_DEBUG_CATEGORY_INIT (check_debug, "check", 0, "check regression tests");
418
419 if (atexit (gst_check_deinit) != 0) {
420 GST_ERROR ("failed to set gst_check_deinit as exit function");
421 }
422
423 if (g_getenv ("GST_TEST_DEBUG"))
424 _gst_check_debug = TRUE;
425
426 g_log_set_handler (NULL, G_LOG_LEVEL_MESSAGE, gst_check_log_message_func,
427 NULL);
428 g_log_set_handler (NULL, G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING,
429 gst_check_log_critical_func, NULL);
430
431 for (i = 0; i < G_N_ELEMENTS (log_domains); ++i) {
432 g_log_set_handler (log_domains[i],
433 G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING,
434 gst_check_log_critical_func, NULL);
435 }
436
437 g_test_log_set_fatal_handler (gst_check_log_fatal_func, NULL);
438
439 print_plugins ();
440
441 #ifdef TARGET_CPU
442 GST_INFO ("target CPU: %s", TARGET_CPU);
443 #endif
444
445 #ifdef HAVE_CPU_ARM
446 timeout_multiplier = 10;
447 #endif
448
449 if (timeout_multiplier > 1) {
450 const gchar *tmult = g_getenv ("CK_TIMEOUT_MULTIPLIER");
451
452 if (tmult == NULL) {
453 gchar num_str[32];
454
455 g_snprintf (num_str, sizeof (num_str), "%d", timeout_multiplier);
456 GST_INFO ("slow CPU, setting CK_TIMEOUT_MULTIPLIER to %s", num_str);
457 g_setenv ("CK_TIMEOUT_MULTIPLIER", num_str, TRUE);
458 } else {
459 GST_INFO ("CK_TIMEOUT_MULTIPLIER already set to '%s'", tmult);
460 }
461 }
462 }
463
464 /* message checking */
465 void
466 gst_check_message_error (GstMessage * message, GstMessageType type,
467 GQuark domain, gint code)
468 {
469 GError *error;
470 gchar *debug;
471
472 fail_unless (GST_MESSAGE_TYPE (message) == type,
473 "message is of type %s instead of expected type %s",
474 gst_message_type_get_name (GST_MESSAGE_TYPE (message)),
475 gst_message_type_get_name (type));
476 gst_message_parse_error (message, &error, &debug);
477 fail_unless_equals_int (error->domain, domain);
478 fail_unless_equals_int (error->code, code);
479 g_error_free (error);
480 g_free (debug);
481 }
482
483 /* helper functions */
484 /**
485 * gst_check_chain_func:
486 *
487 * A fake chain function that appends the buffer to the internal list of
488 * buffers.
489 */
490 GstFlowReturn
491 gst_check_chain_func (GstPad * pad, GstObject * parent, GstBuffer * buffer)
492 {
493 GST_DEBUG_OBJECT (pad, "chain_func: received buffer %p", buffer);
494 buffers = g_list_append (buffers, buffer);
495
496 g_mutex_lock (&check_mutex);
497 g_cond_signal (&check_cond);
498 g_mutex_unlock (&check_mutex);
499
500 return GST_FLOW_OK;
501 }
502
503 /**
504 * gst_check_setup_element:
505 * @factory: factory
506 *
507 * setup an element for a filter test with mysrcpad and mysinkpad
508 *
509 * Returns: (transfer full): a new element
510 */
511 GstElement *
512 gst_check_setup_element (const gchar * factory)
513 {
514 GstElement *element;
515
516 GST_DEBUG ("setup_element");
517
518 element = gst_element_factory_make (factory, factory);
519 fail_if (element == NULL, "Could not create a '%s' element", factory);
520 ASSERT_OBJECT_REFCOUNT (element, factory, 1);
521 return element;
522 }
523
524 void
525 gst_check_teardown_element (GstElement * element)
526 {
527 GST_DEBUG ("teardown_element");
528
529 fail_unless (gst_element_set_state (element, GST_STATE_NULL) ==
530 GST_STATE_CHANGE_SUCCESS, "could not set to null");
531 ASSERT_OBJECT_REFCOUNT (element, "element", 1);
532 gst_object_unref (element);
533 }
534
535 /**
536 * gst_check_setup_src_pad:
537 * @element: element to setup pad on
538 * @tmpl: pad template
539 *
540 * Does the same as #gst_check_setup_src_pad_by_name with the <emphasis> name </emphasis> parameter equal to "sink".
541 *
542 * Returns: (transfer full): A new pad that can be used to inject data on @element
543 */
544 GstPad *
545 gst_check_setup_src_pad (GstElement * element, GstStaticPadTemplate * tmpl)
546 {
547 return gst_check_setup_src_pad_by_name (element, tmpl, "sink");
548 }
549
550 /**
551 * gst_check_setup_src_pad_by_name:
552 * @element: element to setup src pad on
553 * @tmpl: pad template
554 * @name: Name of the @element sink pad that will be linked to the src pad that will be setup
555 *
556 * Creates a new src pad (based on the given @tmpl) and links it to the given @element sink pad (the pad that matches the given @name).
557 * Before using the src pad to push data on @element you need to call #gst_check_setup_events on the created src pad.
558 *
559 * Example of how to push a buffer on @element:
560 *
561 * |[<!-- language="C" -->
562 * static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
563 * GST_PAD_SINK,
564 * GST_PAD_ALWAYS,
565 * GST_STATIC_CAPS (YOUR_CAPS_TEMPLATE_STRING)
566 * );
567 * static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
568 * GST_PAD_SRC,
569 * GST_PAD_ALWAYS,
570 * GST_STATIC_CAPS (YOUR_CAPS_TEMPLATE_STRING)
571 * );
572 *
573 * GstElement * element = gst_check_setup_element ("element");
574 * GstPad * mysrcpad = gst_check_setup_src_pad (element, &srctemplate);
575 * GstPad * mysinkpad = gst_check_setup_sink_pad (element, &sinktemplate);
576 *
577 * gst_pad_set_active (mysrcpad, TRUE);
578 * gst_pad_set_active (mysinkpad, TRUE);
579 * fail_unless (gst_element_set_state (element, GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, "could not set to playing");
580 *
581 * GstCaps * caps = gst_caps_from_string (YOUR_DESIRED_SINK_CAPS);
582 * gst_check_setup_events (mysrcpad, element, caps, GST_FORMAT_TIME);
583 * gst_caps_unref (caps);
584 *
585 * fail_unless (gst_pad_push (mysrcpad, gst_buffer_new_and_alloc(2)) == GST_FLOW_OK);
586 * ]|
587 *
588 * For very simple input/output test scenarios checkout #gst_check_element_push_buffer_list and #gst_check_element_push_buffer.
589 *
590 * Returns: (transfer full): A new pad that can be used to inject data on @element
591 */
592 GstPad *
593 gst_check_setup_src_pad_by_name (GstElement * element,
594 GstStaticPadTemplate * tmpl, const gchar * name)
595 {
596 GstPadTemplate *ptmpl = gst_static_pad_template_get (tmpl);
597 GstPad *srcpad;
598
599 srcpad = gst_check_setup_src_pad_by_name_from_template (element, ptmpl, name);
600
601 gst_object_unref (ptmpl);
602
603 return srcpad;
604 }
605
606 /**
607 * gst_check_setup_src_pad_from_template:
608 * @element: element to setup pad on
609 * @tmpl: pad template
610 *
611 * Returns: (transfer full): a new pad
612 *
613 * Since: 1.4
614 */
615 GstPad *
616 gst_check_setup_src_pad_from_template (GstElement * element,
617 GstPadTemplate * tmpl)
618 {
619 return gst_check_setup_src_pad_by_name_from_template (element, tmpl, "sink");
620 }
621
622 /**
623 * gst_check_setup_src_pad_by_name_from_template:
624 * @element: element to setup pad on
625 * @tmpl: pad template
626 * @name: name
627 *
628 * Returns: (transfer full): a new pad
629 *
630 * Since: 1.4
631 */
632 GstPad *
633 gst_check_setup_src_pad_by_name_from_template (GstElement * element,
634 GstPadTemplate * tmpl, const gchar * name)
635 {
636 GstPad *srcpad, *sinkpad;
637
638 /* sending pad */
639 srcpad = gst_pad_new_from_template (tmpl, "src");
640 GST_DEBUG_OBJECT (element, "setting up sending pad %p", srcpad);
641 fail_if (srcpad == NULL, "Could not create a srcpad");
642 ASSERT_OBJECT_REFCOUNT (srcpad, "srcpad", 1);
643
644 sinkpad = gst_element_get_static_pad (element, name);
645 if (sinkpad == NULL)
646 sinkpad = gst_element_request_pad_simple (element, name);
647 fail_if (sinkpad == NULL, "Could not get sink pad from %s",
648 GST_ELEMENT_NAME (element));
649 fail_unless (gst_pad_link (srcpad, sinkpad) == GST_PAD_LINK_OK,
650 "Could not link source and %s sink pads", GST_ELEMENT_NAME (element));
651 gst_object_unref (sinkpad); /* because we got it higher up */
652
653 return srcpad;
654 }
655
656 void
657 gst_check_teardown_pad_by_name (GstElement * element, const gchar * name)
658 {
659 GstPad *pad_peer, *pad_element;
660
661 /* clean up floating src pad */
662 pad_element = gst_element_get_static_pad (element, name);
663 /* We don't check the refcount here since there *might* be
664 * a pad cache holding an extra reference on pad_element.
665 * To get to a state where no pad cache will exist,
666 * we first unlink that pad. */
667 pad_peer = gst_pad_get_peer (pad_element);
668
669 if (pad_peer) {
670 if (gst_pad_get_direction (pad_element) == GST_PAD_SINK)
671 gst_pad_unlink (pad_peer, pad_element);
672 else
673 gst_pad_unlink (pad_element, pad_peer);
674 }
675
676 gst_object_unref (pad_element);
677
678 if (pad_peer) {
679 gst_object_unref (pad_peer);
680 gst_object_unref (pad_peer);
681 }
682 }
683
684 void
685 gst_check_teardown_src_pad (GstElement * element)
686 {
687 gst_check_teardown_pad_by_name (element, "sink");
688 }
689
690 /**
691 * gst_check_setup_sink_pad:
692 * @element: element to setup pad on
693 * @tmpl: pad template
694 *
695 * Does the same as #gst_check_setup_sink_pad_by_name with the <emphasis> name </emphasis> parameter equal to "src".
696 *
697 * Returns: (transfer full): a new pad that can be used to check the output of @element
698 */
699 GstPad *
700 gst_check_setup_sink_pad (GstElement * element, GstStaticPadTemplate * tmpl)
701 {
702 return gst_check_setup_sink_pad_by_name (element, tmpl, "src");
703 }
704
705 /**
706 * gst_check_setup_sink_pad_by_name:
707 * @element: element to setup pad on
708 * @tmpl: pad template
709 * @name: Name of the @element src pad that will be linked to the sink pad that will be setup
710 *
711 * Creates a new sink pad (based on the given @tmpl) and links it to the given @element src pad
712 * (the pad that matches the given @name).
713 * You can set event/chain/query functions on this pad to check the output of the @element.
714 *
715 * Returns: (transfer full): a new pad that can be used to check the output of @element
716 */
717 GstPad *
718 gst_check_setup_sink_pad_by_name (GstElement * element,
719 GstStaticPadTemplate * tmpl, const gchar * name)
720 {
721 GstPadTemplate *ptmpl = gst_static_pad_template_get (tmpl);
722 GstPad *sinkpad;
723
724 sinkpad =
725 gst_check_setup_sink_pad_by_name_from_template (element, ptmpl, name);
726
727 gst_object_unref (ptmpl);
728
729 return sinkpad;
730 }
731
732 /**
733 * gst_check_setup_sink_pad_from_template:
734 * @element: element to setup pad on
735 * @tmpl: pad template
736 *
737 * Returns: (transfer full): a new pad
738 *
739 * Since: 1.4
740 */
741 GstPad *
742 gst_check_setup_sink_pad_from_template (GstElement * element,
743 GstPadTemplate * tmpl)
744 {
745 return gst_check_setup_sink_pad_by_name_from_template (element, tmpl, "src");
746 }
747
748 /**
749 * gst_check_setup_sink_pad_by_name_from_template:
750 * @element: element to setup pad on
751 * @tmpl: pad template
752 * @name: name
753 *
754 * Returns: (transfer full): a new pad
755 *
756 * Since: 1.4
757 */
758 GstPad *
759 gst_check_setup_sink_pad_by_name_from_template (GstElement * element,
760 GstPadTemplate * tmpl, const gchar * name)
761 {
762 GstPad *srcpad, *sinkpad;
763
764 /* receiving pad */
765 sinkpad = gst_pad_new_from_template (tmpl, "sink");
766 GST_DEBUG_OBJECT (element, "setting up receiving pad %p", sinkpad);
767 fail_if (sinkpad == NULL, "Could not create a sinkpad");
768
769 srcpad = gst_element_get_static_pad (element, name);
770 if (srcpad == NULL)
771 srcpad = gst_element_request_pad_simple (element, name);
772 fail_if (srcpad == NULL, "Could not get source pad from %s",
773 GST_ELEMENT_NAME (element));
774 gst_pad_set_chain_function (sinkpad, gst_check_chain_func);
775
776 GST_DEBUG_OBJECT (element, "Linking element src pad and receiving sink pad");
777 fail_unless (gst_pad_link (srcpad, sinkpad) == GST_PAD_LINK_OK,
778 "Could not link %s source and sink pads", GST_ELEMENT_NAME (element));
779 gst_object_unref (srcpad); /* because we got it higher up */
780
781 GST_DEBUG_OBJECT (element, "set up srcpad");
782 return sinkpad;
783 }
784
785 void
786 gst_check_teardown_sink_pad (GstElement * element)
787 {
788 gst_check_teardown_pad_by_name (element, "src");
789 }
790
791 /**
792 * gst_check_drop_buffers:
793 *
794 * Unref and remove all buffers that are in the global @buffers GList,
795 * emptying the list.
796 */
797 void
798 gst_check_drop_buffers (void)
799 {
800 while (buffers != NULL) {
801 gst_buffer_unref (GST_BUFFER (buffers->data));
802 buffers = g_list_delete_link (buffers, buffers);
803 }
804 }
805
806 /**
807 * gst_check_caps_equal:
808 * @caps1: first caps to compare
809 * @caps2: second caps to compare
810 *
811 * Compare two caps with gst_caps_is_equal and fail unless they are
812 * equal.
813 */
814 void
815 gst_check_caps_equal (GstCaps * caps1, GstCaps * caps2)
816 {
817 gchar *name1 = gst_caps_to_string (caps1);
818 gchar *name2 = gst_caps_to_string (caps2);
819
820 fail_unless (gst_caps_is_equal (caps1, caps2),
821 "caps ('%s') is not equal to caps ('%s')", name1, name2);
822 g_free (name1);
823 g_free (name2);
824 }
825
826
827 /**
828 * gst_check_buffer_data:
829 * @buffer: buffer to compare
830 * @data: data to compare to
831 * @size: size of data to compare
832 *
833 * Compare the buffer contents with @data and @size.
834 */
835 void
836 gst_check_buffer_data (GstBuffer * buffer, gconstpointer data, gsize size)
837 {
838 GstMapInfo info;
839
840 fail_unless (gst_buffer_map (buffer, &info, GST_MAP_READ));
841 GST_MEMDUMP ("Converted data", info.data, info.size);
842 GST_MEMDUMP ("Expected data", data, size);
843 if (info.size != size) {
844 fail ("buffer sizes not equal: expected %" G_GSIZE_FORMAT " got %"
845 G_GSIZE_FORMAT, size, info.size);
846 }
847 if (memcmp (info.data, data, size) != 0) {
848 g_print ("\nConverted data:\n");
849 gst_util_dump_mem (info.data, info.size);
850 g_print ("\nExpected data:\n");
851 gst_util_dump_mem (data, size);
852 fail ("buffer contents not equal");
853 }
854 gst_buffer_unmap (buffer, &info);
855 }
856
857 static gboolean
858 buffer_event_function (GstPad * pad, GstObject * noparent, GstEvent * event)
859 {
860 if (GST_EVENT_TYPE (event) == GST_EVENT_CAPS) {
861 GstCaps *event_caps;
862 GstCaps *expected_caps = gst_pad_get_element_private (pad);
863
864 gst_event_parse_caps (event, &event_caps);
865 fail_unless (gst_caps_is_fixed (expected_caps));
866 fail_unless (gst_caps_is_fixed (event_caps));
867 fail_unless (gst_caps_is_equal_fixed (event_caps, expected_caps));
868 gst_event_unref (event);
869 return TRUE;
870 }
871
872 return gst_pad_event_default (pad, noparent, event);
873 }
874
875 /**
876 * gst_check_element_push_buffer_list:
877 * @element_name: name of the element that needs to be created
878 * @buffer_in: (element-type GstBuffer) (transfer full): a list of buffers that needs to be
879 * pushed to the element
880 * @caps_in: the #GstCaps expected of the sinkpad of the element
881 * @buffer_out: (element-type GstBuffer) (transfer full): a list of buffers that we expect from
882 * the element
883 * @caps_out: the #GstCaps expected of the srcpad of the element
884 * @last_flow_return: the last buffer push needs to give this GstFlowReturn
885 *
886 * Create an element using the factory providing the @element_name and push the
887 * buffers in @buffer_in to this element. The element should create the buffers
888 * equal to the buffers in @buffer_out. We only check the size and the data of
889 * the buffers. This function unrefs the buffers in the two lists.
890 * The last_flow_return parameter indicates the expected flow return value from
891 * pushing the final buffer in the list.
892 * This can be used to set up a test which pushes some buffers and then an
893 * invalid buffer, when the final buffer is expected to fail, for example.
894 */
895 /* FIXME 2.0: rename this function now that there's GstBufferList? */
896 void
897 gst_check_element_push_buffer_list (const gchar * element_name,
898 GList * buffer_in, GstCaps * caps_in, GList * buffer_out,
899 GstCaps * caps_out, GstFlowReturn last_flow_return)
900 {
901 GstElement *element;
902 GstPad *pad_peer;
903 GstPad *sink_pad = NULL;
904 GstPad *src_pad;
905 GstBuffer *buffer;
906
907 /* check that there are no buffers waiting */
908 gst_check_drop_buffers ();
909 /* create the element */
910 element = gst_check_setup_element (element_name);
911 fail_if (element == NULL, "failed to create the element '%s'", element_name);
912 fail_unless (GST_IS_ELEMENT (element), "the element is no element");
913 /* create the src pad */
914 buffer = GST_BUFFER (buffer_in->data);
915
916 fail_unless (GST_IS_BUFFER (buffer), "There should be a buffer in buffer_in");
917 src_pad = gst_pad_new ("src", GST_PAD_SRC);
918 if (caps_in) {
919 fail_unless (gst_caps_is_fixed (caps_in));
920 gst_pad_use_fixed_caps (src_pad);
921 }
922 /* activate the pad */
923 gst_pad_set_active (src_pad, TRUE);
924 GST_DEBUG ("src pad activated");
925 gst_check_setup_events (src_pad, element, caps_in, GST_FORMAT_BYTES);
926 pad_peer = gst_element_get_static_pad (element, "sink");
927 fail_if (pad_peer == NULL);
928 fail_unless (gst_pad_link (src_pad, pad_peer) == GST_PAD_LINK_OK,
929 "Could not link source and %s sink pads", GST_ELEMENT_NAME (element));
930 gst_object_unref (pad_peer);
931 /* don't create the sink_pad if there is no buffer_out list */
932 if (buffer_out != NULL) {
933
934 GST_DEBUG ("buffer out detected, creating the sink pad");
935 /* get the sink caps */
936 if (caps_out) {
937 gchar *temp;
938
939 fail_unless (gst_caps_is_fixed (caps_out));
940 temp = gst_caps_to_string (caps_out);
941
942 GST_DEBUG ("sink caps requested by buffer out: '%s'", temp);
943 g_free (temp);
944 }
945
946 /* get the sink pad */
947 sink_pad = gst_pad_new ("sink", GST_PAD_SINK);
948 fail_unless (GST_IS_PAD (sink_pad));
949 /* configure the sink pad */
950 gst_pad_set_chain_function (sink_pad, gst_check_chain_func);
951 gst_pad_set_active (sink_pad, TRUE);
952 if (caps_out) {
953 gst_pad_set_element_private (sink_pad, caps_out);
954 gst_pad_set_event_function (sink_pad, buffer_event_function);
955 }
956 /* get the peer pad */
957 pad_peer = gst_element_get_static_pad (element, "src");
958 fail_unless (gst_pad_link (pad_peer, sink_pad) == GST_PAD_LINK_OK,
959 "Could not link sink and %s source pads", GST_ELEMENT_NAME (element));
960 gst_object_unref (pad_peer);
961 }
962 fail_unless (gst_element_set_state (element,
963 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
964 "could not set to playing");
965 /* push all the buffers in the buffer_in list */
966 fail_unless (g_list_length (buffer_in) > 0, "the buffer_in list is empty");
967 while (buffer_in != NULL) {
968 GstBuffer *next_buffer = GST_BUFFER (buffer_in->data);
969
970 fail_unless (GST_IS_BUFFER (next_buffer),
971 "data in buffer_in should be a buffer");
972 /* remove the buffer from the list */
973 buffer_in = g_list_remove (buffer_in, next_buffer);
974 if (buffer_in == NULL) {
975 fail_unless (gst_pad_push (src_pad, next_buffer) == last_flow_return,
976 "we expect something else from the last buffer");
977 } else {
978 fail_unless (gst_pad_push (src_pad, next_buffer) == GST_FLOW_OK,
979 "Failed to push buffer in");
980 }
981 }
982 fail_unless (gst_element_set_state (element,
983 GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null");
984 /* check that there is a buffer out */
985 fail_unless_equals_int (g_list_length (buffers), g_list_length (buffer_out));
986 while (buffers != NULL) {
987 GstBuffer *new = GST_BUFFER (buffers->data);
988 GstBuffer *orig = GST_BUFFER (buffer_out->data);
989 GstMapInfo newinfo, originfo;
990
991 fail_unless (gst_buffer_map (new, &newinfo, GST_MAP_READ));
992 fail_unless (gst_buffer_map (orig, &originfo, GST_MAP_READ));
993
994 GST_LOG ("orig buffer: size %" G_GSIZE_FORMAT, originfo.size);
995 GST_LOG ("new buffer: size %" G_GSIZE_FORMAT, newinfo.size);
996 GST_MEMDUMP ("orig buffer", originfo.data, originfo.size);
997 GST_MEMDUMP ("new buffer", newinfo.data, newinfo.size);
998
999 /* remove the buffers */
1000 buffers = g_list_remove (buffers, new);
1001 buffer_out = g_list_remove (buffer_out, orig);
1002
1003 fail_unless (originfo.size == newinfo.size,
1004 "size of the buffers are not the same");
1005 fail_unless (memcmp (originfo.data, newinfo.data, newinfo.size) == 0,
1006 "data is not the same");
1007 #if 0
1008 gst_check_caps_equal (GST_BUFFER_CAPS (orig), GST_BUFFER_CAPS (new));
1009 #endif
1010
1011 gst_buffer_unmap (orig, &originfo);
1012 gst_buffer_unmap (new, &newinfo);
1013
1014 gst_buffer_unref (new);
1015 gst_buffer_unref (orig);
1016 }
1017 /* teardown the element and pads */
1018 gst_pad_set_active (src_pad, FALSE);
1019 gst_check_teardown_src_pad (element);
1020 gst_pad_set_active (sink_pad, FALSE);
1021 gst_check_teardown_sink_pad (element);
1022 gst_check_teardown_element (element);
1023 }
1024
1025 /**
1026 * gst_check_element_push_buffer:
1027 * @element_name: name of the element that needs to be created
1028 * @buffer_in: push this buffer to the element
1029 * @caps_in: the #GstCaps expected of the sinkpad of the element
1030 * @buffer_out: compare the result with this buffer
1031 * @caps_out: the #GstCaps expected of the srcpad of the element
1032 *
1033 * Create an element using the factory providing the @element_name and
1034 * push the @buffer_in to this element. The element should create one buffer
1035 * and this will be compared with @buffer_out. We only check the caps
1036 * and the data of the buffers. This function unrefs the buffers.
1037 */
1038 void
1039 gst_check_element_push_buffer (const gchar * element_name,
1040 GstBuffer * buffer_in, GstCaps * caps_in, GstBuffer * buffer_out,
1041 GstCaps * caps_out)
1042 {
1043 GList *in = NULL;
1044 GList *out = NULL;
1045
1046 in = g_list_append (in, buffer_in);
1047 out = g_list_append (out, buffer_out);
1048
1049 gst_check_element_push_buffer_list (element_name, in, caps_in, out, caps_out,
1050 GST_FLOW_OK);
1051 }
1052
1053 /**
1054 * gst_check_abi_list:
1055 * @list: A list of GstCheckABIStruct to be verified
1056 * @have_abi_sizes: Whether there is a reference ABI size already specified,
1057 * if it is %FALSE and the `GST_ABI` environment variable is set, usable code
1058 * for @list will be printed.
1059 *
1060 * Verifies that reference values and current values are equals in @list.
1061 */
1062 void
1063 gst_check_abi_list (GstCheckABIStruct list[], gboolean have_abi_sizes)
1064 {
1065 if (have_abi_sizes) {
1066 gboolean ok = TRUE;
1067 gint i;
1068
1069 for (i = 0; list[i].name; i++) {
1070 if (list[i].size != list[i].abi_size) {
1071 ok = FALSE;
1072 g_print ("sizeof(%s) is %d, expected %d\n",
1073 list[i].name, list[i].size, list[i].abi_size);
1074 }
1075 }
1076 fail_unless (ok, "failed ABI check");
1077 } else {
1078 const gchar *fn;
1079
1080 if ((fn = g_getenv ("GST_ABI"))) {
1081 GError *err = NULL;
1082 GString *s;
1083 gint i;
1084
1085 s = g_string_new ("\nGstCheckABIStruct list[] = {\n");
1086 for (i = 0; list[i].name; i++) {
1087 g_string_append_printf (s, " {\"%s\", sizeof (%s), %d},\n",
1088 list[i].name, list[i].name, list[i].size);
1089 }
1090 g_string_append (s, " {NULL, 0, 0}\n");
1091 g_string_append (s, "};\n");
1092 if (!g_file_set_contents (fn, s->str, s->len, &err)) {
1093 g_print ("%s", s->str);
1094 g_printerr ("\nFailed to write ABI information: %s\n", err->message);
1095 g_clear_error (&err);
1096 } else {
1097 g_print ("\nWrote ABI information to '%s'.\n", fn);
1098 }
1099 g_string_free (s, TRUE);
1100 } else {
1101 g_print ("No structure size list was generated for this architecture.\n");
1102 g_print ("Run with GST_ABI environment variable set to output header.\n");
1103 }
1104 }
1105 }
1106
1107 static gint
1108 gst_check_run_suite_full (Suite * suite, const gchar * name,
1109 const gchar * fname, gboolean fork_allowed)
1110 {
1111 SRunner *sr;
1112 gchar *xmlfilename = NULL;
1113 gint nf;
1114 GTimer *timer;
1115
1116 sr = srunner_create (suite);
1117 if (!fork_allowed)
1118 srunner_set_fork_status (sr, CK_NOFORK);
1119
1120 if (g_getenv ("GST_CHECK_XML")) {
1121 /* how lucky we are to have __FILE__ end in .c */
1122 xmlfilename = g_strdup_printf ("%sheck.xml", fname);
1123
1124 srunner_set_xml (sr, xmlfilename);
1125 }
1126
1127 timer = g_timer_new ();
1128 srunner_run_all (sr, CK_NORMAL);
1129 nf = srunner_ntests_failed (sr);
1130 g_print ("Check suite %s ran in %.3fs (tests failed: %d)\n",
1131 name, g_timer_elapsed (timer, NULL), nf);
1132 g_timer_destroy (timer);
1133 g_free (xmlfilename);
1134 srunner_free (sr);
1135 g_thread_pool_stop_unused_threads ();
1136 return nf;
1137 }
1138
1139 /**
1140 * gst_check_run_suite: (skip)
1141 * @suite: the check test suite
1142 * @name: name
1143 * @fname: file name
1144 *
1145 * Returns: number of failed tests
1146 */
1147 gint
1148 gst_check_run_suite (Suite * suite, const gchar * name, const gchar * fname)
1149 {
1150 return gst_check_run_suite_full (suite, name, fname, TRUE);
1151 }
1152
1153 /**
1154 * gst_check_run_suite_nofork: (skip)
1155 * @suite: the check test suite
1156 * @name: name
1157 * @fname: file name
1158 *
1159 * Runs a given test suite with fork usage explicitly disabled.
1160 *
1161 * Returns: number of failed tests
1162 *
1163 * Since: 1.28.3
1164 */
1165 gint
1166 gst_check_run_suite_nofork (Suite * suite, const gchar * name,
1167 const gchar * fname)
1168 {
1169 return gst_check_run_suite_full (suite, name, fname, FALSE);
1170 }
1171
1172 static gboolean
1173 gst_check_have_checks_list (const gchar * env_var_name)
1174 {
1175 const gchar *env_val;
1176
1177 env_val = g_getenv (env_var_name);
1178 return (env_val != NULL && *env_val != '\0');
1179 }
1180
1181 static gboolean
1182 gst_check_func_is_in_list (const gchar * env_var, const gchar * func_name)
1183 {
1184 const gchar *gst_checks;
1185 gboolean res = FALSE;
1186 gchar **funcs, **f;
1187
1188 gst_checks = g_getenv (env_var);
1189
1190 if (gst_checks == NULL || *gst_checks == '\0')
1191 return FALSE;
1192
1193 /* only run specified functions */
1194 funcs = g_strsplit (gst_checks, ",", -1);
1195 for (f = funcs; f != NULL && *f != NULL; ++f) {
1196 if (g_pattern_match_simple (*f, func_name)) {
1197 res = TRUE;
1198 break;
1199 }
1200 }
1201 g_strfreev (funcs);
1202 return res;
1203 }
1204
1205 gboolean
1206 _gst_check_run_test_func (const gchar * func_name)
1207 {
1208 /* if we have a whitelist, run it only if it's in the whitelist */
1209 if (gst_check_have_checks_list ("GST_CHECKS"))
1210 return gst_check_func_is_in_list ("GST_CHECKS", func_name);
1211
1212 /* if we have a blacklist, run it only if it's not in the blacklist */
1213 if (gst_check_have_checks_list ("GST_CHECKS_IGNORE"))
1214 return !gst_check_func_is_in_list ("GST_CHECKS_IGNORE", func_name);
1215
1216 /* no filter specified => run all checks */
1217 return TRUE;
1218 }
1219
1220 /**
1221 * gst_check_setup_events_with_stream_id:
1222 * @srcpad: The src #GstPad to push on
1223 * @element: The #GstElement use to create the stream id
1224 * @caps: (allow-none): #GstCaps in case caps event must be sent
1225 * @format: The #GstFormat of the default segment to send
1226 * @stream_id: A unique identifier for the stream
1227 *
1228 * Push stream-start, caps and segment event, which consist of the minimum
1229 * required events to allow streaming. Caps is optional to allow raw src
1230 * testing.
1231 */
1232 void
1233 gst_check_setup_events_with_stream_id (GstPad * srcpad, GstElement * element,
1234 GstCaps * caps, GstFormat format, const gchar * stream_id)
1235 {
1236 GstSegment segment;
1237
1238 gst_segment_init (&segment, format);
1239
1240 fail_unless (gst_pad_push_event (srcpad,
1241 gst_event_new_stream_start (stream_id)));
1242 if (caps)
1243 fail_unless (gst_pad_push_event (srcpad, gst_event_new_caps (caps)));
1244 fail_unless (gst_pad_push_event (srcpad, gst_event_new_segment (&segment)));
1245 }
1246
1247 /**
1248 * gst_check_setup_events:
1249 * @srcpad: The src #GstPad to push on
1250 * @element: The #GstElement use to create the stream id
1251 * @caps: (allow-none): #GstCaps in case caps event must be sent
1252 * @format: The #GstFormat of the default segment to send
1253 *
1254 * Push stream-start, caps and segment event, which consist of the minimum
1255 * required events to allow streaming. Caps is optional to allow raw src
1256 * testing. If @element has more than one src or sink pad, use
1257 * gst_check_setup_events_with_stream_id() instead.
1258 */
1259 void
1260 gst_check_setup_events (GstPad * srcpad, GstElement * element,
1261 GstCaps * caps, GstFormat format)
1262 {
1263 gchar *stream_id;
1264
1265 stream_id = gst_pad_create_stream_id (srcpad, element, NULL);
1266 gst_check_setup_events_with_stream_id (srcpad, element, caps, format,
1267 stream_id);
1268 g_free (stream_id);
1269 }
1270
1271 typedef struct _DestroyedObjectStruct
1272 {
1273 GObject *object;
1274 gboolean destroyed;
1275 } DestroyedObjectStruct;
1276
1277 static void
1278 weak_notify (DestroyedObjectStruct * destroyed, GObject ** object)
1279 {
1280 destroyed->destroyed = TRUE;
1281 }
1282
1283 /**
1284 * gst_check_objects_destroyed_on_unref:
1285 * @object_to_unref: The #GObject to unref
1286 * @first_object: (allow-none): The first object that should be destroyed as a
1287 * concequence of unrefing @object_to_unref.
1288 * @... : Additional object that should have been destroyed.
1289 *
1290 * Unrefs @object_to_unref and checks that is has properly been
1291 * destroyed, also checks that the other objects passed in
1292 * parameter have been destroyed as a concequence of
1293 * unrefing @object_to_unref. Last variable argument should be NULL.
1294 *
1295 * Since: 1.6
1296 */
1297 void
1298 gst_check_objects_destroyed_on_unref (gpointer object_to_unref,
1299 gpointer first_object, ...)
1300 {
1301 GObject *object;
1302 GList *objs = NULL, *tmp;
1303 DestroyedObjectStruct *destroyed = g_new0 (DestroyedObjectStruct, 1);
1304
1305 destroyed->object = object_to_unref;
1306 g_object_weak_ref (object_to_unref, (GWeakNotify) weak_notify, destroyed);
1307 objs = g_list_prepend (objs, destroyed);
1308
1309 if (first_object) {
1310 va_list varargs;
1311
1312 object = first_object;
1313
1314 va_start (varargs, first_object);
1315 while (object) {
1316 destroyed = g_new0 (DestroyedObjectStruct, 1);
1317 destroyed->object = object;
1318 g_object_weak_ref (object, (GWeakNotify) weak_notify, destroyed);
1319 objs = g_list_prepend (objs, destroyed);
1320 object = va_arg (varargs, GObject *);
1321 }
1322 va_end (varargs);
1323 }
1324 gst_object_unref (object_to_unref);
1325
1326 for (tmp = objs; tmp; tmp = tmp->next) {
1327 DestroyedObjectStruct *destroyed = tmp->data;
1328
1329 if (!destroyed->destroyed) {
1330 fail_unless (destroyed->destroyed,
1331 "%s_%p is not destroyed, %d refcounts left!",
1332 GST_IS_OBJECT (destroyed->
1333 object) ? GST_OBJECT_NAME (destroyed->object) :
1334 G_OBJECT_TYPE_NAME (destroyed), destroyed->object,
1335 destroyed->object->ref_count);
1336 }
1337 g_free (tmp->data);
1338 }
1339 g_list_free (objs);
1340 }
1341
1342 /**
1343 * gst_check_object_destroyed_on_unref:
1344 * @object_to_unref: The #GObject to unref
1345 *
1346 * Unrefs @object_to_unref and checks that is has properly been
1347 * destroyed.
1348 *
1349 * Since: 1.6
1350 */
1351 void
1352 gst_check_object_destroyed_on_unref (gpointer object_to_unref)
1353 {
1354 gst_check_objects_destroyed_on_unref (object_to_unref, NULL, NULL);
1355 }
1356
1357 /* For ABI compatibility with GStreamer < 1.5 */
1358 /* *INDENT-OFF* */
1359 GST_CHECK_API void
1360 _fail_unless (int result, const char *file, int line, const char *expr, ...)
1361 G_GNUC_PRINTF (4, 5);
1362 /* *INDENT-ON* */
1363
1364 void
1365 _fail_unless (int result, const char *file, int line, const char *expr, ...)
1366 {
1367 gchar *msg;
1368 va_list args;
1369
1370 if (result) {
1371 _mark_point (file, line);
1372 return;
1373 }
1374
1375 va_start (args, expr);
1376 msg = g_strdup_vprintf (expr, args);
1377 va_end (args);
1378
1379 _ck_assert_failed (file, line, msg, NULL);
1380 g_free (msg);
1381 }