29 */ |
29 */ |
30 #include <string.h> |
30 #include <string.h> |
31 #include "gstcheck.h" |
31 #include "gstcheck.h" |
32 #include <glib_global.h> |
32 #include <glib_global.h> |
33 |
33 |
34 //#include "libgstreamer_wsd_solution.h" |
|
35 |
|
36 GST_DEBUG_CATEGORY (check_debug); |
34 GST_DEBUG_CATEGORY (check_debug); |
37 |
35 |
38 /* logging function for tests |
36 /* logging function for tests |
39 * a test uses g_message() to log a debug line |
37 * a test uses g_message() to log a debug line |
40 * a gst unit test can be run with GST_TEST_DEBUG env var set to see the |
38 * a gst unit test can be run with GST_TEST_DEBUG env var set to see the |
41 * messages |
39 * messages |
42 */ |
40 */ |
43 |
41 |
44 //gboolean _gst_check_threads_running = FALSE; |
42 //gboolean _gst_check_threads_running = FALSE; |
45 //GList *thread_list = NULL; |
43 //GList *thread_list = NULL; |
|
44 #ifdef __SYMBIAN32__ |
|
45 EXPORT_C |
|
46 GstDebugCategory ** _check_debug() |
|
47 { |
|
48 return &check_debug; |
|
49 } |
|
50 #endif |
46 #if EMULATOR |
51 #if EMULATOR |
47 GET_GLOBAL_VAR_FROM_TLS(thread_list,gstcheck,GList*) |
52 GET_GLOBAL_VAR_FROM_TLS(thread_list,gstcheck,GList*) |
48 #define thread_list (*GET_GSTREAMER_WSD_VAR_NAME(thread_list,gstcheck,g)()) |
53 #define thread_list (*GET_GSTREAMER_WSD_VAR_NAME(thread_list,gstcheck,g)()) |
49 #else |
54 #else |
50 EXPORT_C GList *thread_list = NULL; |
55 EXPORT_C GList *thread_list = NULL; |
97 #define check_cond (*GET_GSTREAMER_WSD_VAR_NAME(check_cond,gstcheck,g)()) |
102 #define check_cond (*GET_GSTREAMER_WSD_VAR_NAME(check_cond,gstcheck,g)()) |
98 #else |
103 #else |
99 EXPORT_C GCond *check_cond = NULL; |
104 EXPORT_C GCond *check_cond = NULL; |
100 #endif |
105 #endif |
101 |
106 |
102 |
|
103 /* FIXME 0.11: shouldn't _gst_check_debug be static? Not used anywhere */ |
107 /* FIXME 0.11: shouldn't _gst_check_debug be static? Not used anywhere */ |
104 EXPORT_C gboolean _gst_check_debug = FALSE; |
108 EXPORT_C gboolean _gst_check_debug = FALSE; |
105 #if EMULATOR |
109 #if EMULATOR |
106 static GET_GLOBAL_VAR_FROM_TLS(raised_critical,gstcheck,gboolean) |
110 static GET_GLOBAL_VAR_FROM_TLS(raised_critical,gstcheck,gboolean) |
107 #define _gst_check_raised_critical (*GET_GSTREAMER_WSD_VAR_NAME(raised_critical,gstcheck,g)()) |
111 #define _gst_check_raised_critical (*GET_GSTREAMER_WSD_VAR_NAME(raised_critical,gstcheck,g)()) |
136 { |
140 { |
137 if (_gst_check_debug) { |
141 if (_gst_check_debug) { |
138 g_print ("%s", message); |
142 g_print ("%s", message); |
139 } |
143 } |
140 } |
144 } |
141 |
|
142 |
145 |
143 static void gst_check_log_critical_func |
146 static void gst_check_log_critical_func |
144 (const gchar * log_domain, GLogLevelFlags log_level, |
147 (const gchar * log_domain, GLogLevelFlags log_level, |
145 const gchar * message, gpointer user_data) |
148 const gchar * message, gpointer user_data) |
146 { |
149 { |
271 |
274 |
272 GstPad * |
275 GstPad * |
273 gst_check_setup_src_pad (GstElement * element, |
276 gst_check_setup_src_pad (GstElement * element, |
274 GstStaticPadTemplate * template, GstCaps * caps) |
277 GstStaticPadTemplate * template, GstCaps * caps) |
275 { |
278 { |
|
279 GstPad *srcpad; |
|
280 |
|
281 srcpad = gst_check_setup_src_pad_by_name (element, template, "sink"); |
|
282 if (caps) |
|
283 fail_unless (gst_pad_set_caps (srcpad, caps), "could not set caps on pad"); |
|
284 return srcpad; |
|
285 } |
|
286 #ifdef __SYMBIAN32__ |
|
287 EXPORT_C |
|
288 #endif |
|
289 |
|
290 |
|
291 GstPad * |
|
292 gst_check_setup_src_pad_by_name (GstElement * element, |
|
293 GstStaticPadTemplate * template, gchar * name) |
|
294 { |
276 GstPad *srcpad, *sinkpad; |
295 GstPad *srcpad, *sinkpad; |
277 |
296 |
278 /* sending pad */ |
297 /* sending pad */ |
279 srcpad = gst_pad_new_from_static_template (template, "src"); |
298 srcpad = gst_pad_new_from_static_template (template, "src"); |
280 GST_DEBUG_OBJECT (element, "setting up sending pad %p", srcpad); |
299 GST_DEBUG_OBJECT (element, "setting up sending pad %p", srcpad); |
281 fail_if (srcpad == NULL, "Could not create a srcpad"); |
300 fail_if (srcpad == NULL, "Could not create a srcpad"); |
282 ASSERT_OBJECT_REFCOUNT (srcpad, "srcpad", 1); |
301 ASSERT_OBJECT_REFCOUNT (srcpad, "srcpad", 1); |
283 |
302 |
284 sinkpad = gst_element_get_pad (element, "sink"); |
303 sinkpad = gst_element_get_static_pad (element, name); |
|
304 if (sinkpad == NULL) |
|
305 sinkpad = gst_element_get_request_pad (element, name); |
285 fail_if (sinkpad == NULL, "Could not get sink pad from %s", |
306 fail_if (sinkpad == NULL, "Could not get sink pad from %s", |
286 GST_ELEMENT_NAME (element)); |
307 GST_ELEMENT_NAME (element)); |
287 ASSERT_OBJECT_REFCOUNT (sinkpad, "sinkpad", 2); |
308 ASSERT_OBJECT_REFCOUNT (sinkpad, "sinkpad", 2); |
288 if (caps) |
|
289 fail_unless (gst_pad_set_caps (srcpad, caps), "could not set caps on pad"); |
|
290 fail_unless (gst_pad_link (srcpad, sinkpad) == GST_PAD_LINK_OK, |
309 fail_unless (gst_pad_link (srcpad, sinkpad) == GST_PAD_LINK_OK, |
291 "Could not link source and %s sink pads", GST_ELEMENT_NAME (element)); |
310 "Could not link source and %s sink pads", GST_ELEMENT_NAME (element)); |
292 gst_object_unref (sinkpad); /* because we got it higher up */ |
311 gst_object_unref (sinkpad); /* because we got it higher up */ |
293 ASSERT_OBJECT_REFCOUNT (sinkpad, "sinkpad", 1); |
312 ASSERT_OBJECT_REFCOUNT (sinkpad, "sinkpad", 1); |
294 |
313 |
298 EXPORT_C |
317 EXPORT_C |
299 #endif |
318 #endif |
300 |
319 |
301 |
320 |
302 void |
321 void |
|
322 gst_check_teardown_pad_by_name (GstElement * element, gchar * name) |
|
323 { |
|
324 GstPad *pad_peer, *pad_element; |
|
325 |
|
326 /* clean up floating src pad */ |
|
327 pad_element = gst_element_get_static_pad (element, name); |
|
328 ASSERT_OBJECT_REFCOUNT (pad_element, "pad", 2); |
|
329 pad_peer = gst_pad_get_peer (pad_element); |
|
330 |
|
331 if (pad_peer) { |
|
332 if (gst_pad_get_direction (pad_element) == GST_PAD_SINK) |
|
333 gst_pad_unlink (pad_peer, pad_element); |
|
334 else |
|
335 gst_pad_unlink (pad_element, pad_peer); |
|
336 |
|
337 /* caps could have been set, make sure they get unset */ |
|
338 gst_pad_set_caps (pad_peer, NULL); |
|
339 } |
|
340 |
|
341 /* pad refs held by both creator and this function (through _get) */ |
|
342 ASSERT_OBJECT_REFCOUNT (pad_element, "element pad_element", 2); |
|
343 gst_object_unref (pad_element); |
|
344 /* one more ref is held by element itself */ |
|
345 |
|
346 if (pad_peer) { |
|
347 /* pad refs held by both creator and this function (through _get_peer) */ |
|
348 ASSERT_OBJECT_REFCOUNT (pad_peer, "check pad_peer", 2); |
|
349 gst_object_unref (pad_peer); |
|
350 gst_object_unref (pad_peer); |
|
351 } |
|
352 } |
|
353 #ifdef __SYMBIAN32__ |
|
354 EXPORT_C |
|
355 #endif |
|
356 |
|
357 |
|
358 void |
303 gst_check_teardown_src_pad (GstElement * element) |
359 gst_check_teardown_src_pad (GstElement * element) |
304 { |
360 { |
305 GstPad *srcpad, *sinkpad; |
361 gst_check_teardown_pad_by_name (element, "sink"); |
306 |
|
307 /* clean up floating src pad */ |
|
308 sinkpad = gst_element_get_pad (element, "sink"); |
|
309 ASSERT_OBJECT_REFCOUNT (sinkpad, "sinkpad", 2); |
|
310 srcpad = gst_pad_get_peer (sinkpad); |
|
311 |
|
312 gst_pad_unlink (srcpad, sinkpad); |
|
313 |
|
314 /* caps could have been set, make sure they get unset */ |
|
315 gst_pad_set_caps (srcpad, NULL); |
|
316 |
|
317 /* pad refs held by both creator and this function (through _get) */ |
|
318 ASSERT_OBJECT_REFCOUNT (sinkpad, "element sinkpad", 2); |
|
319 gst_object_unref (sinkpad); |
|
320 /* one more ref is held by element itself */ |
|
321 |
|
322 /* pad refs held by both creator and this function (through _get_peer) */ |
|
323 ASSERT_OBJECT_REFCOUNT (srcpad, "check srcpad", 2); |
|
324 gst_object_unref (srcpad); |
|
325 gst_object_unref (srcpad); |
|
326 } |
362 } |
327 |
363 |
328 /* FIXME: set_caps isn't that useful; might want to check if fixed, |
364 /* FIXME: set_caps isn't that useful; might want to check if fixed, |
329 * then use set_use_fixed or somesuch */ |
365 * then use set_use_fixed or somesuch */ |
330 #ifdef __SYMBIAN32__ |
366 #ifdef __SYMBIAN32__ |
332 #endif |
368 #endif |
333 |
369 |
334 GstPad * |
370 GstPad * |
335 gst_check_setup_sink_pad (GstElement * element, GstStaticPadTemplate * template, |
371 gst_check_setup_sink_pad (GstElement * element, GstStaticPadTemplate * template, |
336 GstCaps * caps) |
372 GstCaps * caps) |
|
373 { |
|
374 GstPad *sinkpad; |
|
375 |
|
376 sinkpad = gst_check_setup_sink_pad_by_name (element, template, "src"); |
|
377 if (caps) |
|
378 fail_unless (gst_pad_set_caps (sinkpad, caps), "Could not set pad caps"); |
|
379 return sinkpad; |
|
380 } |
|
381 #ifdef __SYMBIAN32__ |
|
382 EXPORT_C |
|
383 #endif |
|
384 |
|
385 |
|
386 GstPad * |
|
387 gst_check_setup_sink_pad_by_name (GstElement * element, |
|
388 GstStaticPadTemplate * template, gchar * name) |
337 { |
389 { |
338 GstPad *srcpad, *sinkpad; |
390 GstPad *srcpad, *sinkpad; |
339 |
391 |
340 /* receiving pad */ |
392 /* receiving pad */ |
341 sinkpad = gst_pad_new_from_static_template (template, "sink"); |
393 sinkpad = gst_pad_new_from_static_template (template, "sink"); |
342 GST_DEBUG_OBJECT (element, "setting up receiving pad %p", sinkpad); |
394 GST_DEBUG_OBJECT (element, "setting up receiving pad %p", sinkpad); |
343 fail_if (sinkpad == NULL, "Could not create a sinkpad"); |
395 fail_if (sinkpad == NULL, "Could not create a sinkpad"); |
344 |
396 |
345 srcpad = gst_element_get_pad (element, "src"); |
397 srcpad = gst_element_get_static_pad (element, name); |
|
398 if (srcpad == NULL) |
|
399 srcpad = gst_element_get_request_pad (element, name); |
346 fail_if (srcpad == NULL, "Could not get source pad from %s", |
400 fail_if (srcpad == NULL, "Could not get source pad from %s", |
347 GST_ELEMENT_NAME (element)); |
401 GST_ELEMENT_NAME (element)); |
348 if (caps) |
|
349 fail_unless (gst_pad_set_caps (sinkpad, caps), "Could not set pad caps"); |
|
350 gst_pad_set_chain_function (sinkpad, gst_check_chain_func); |
402 gst_pad_set_chain_function (sinkpad, gst_check_chain_func); |
351 |
403 |
352 GST_DEBUG_OBJECT (element, "Linking element src pad and receiving sink pad"); |
404 GST_DEBUG_OBJECT (element, "Linking element src pad and receiving sink pad"); |
353 fail_unless (gst_pad_link (srcpad, sinkpad) == GST_PAD_LINK_OK, |
405 fail_unless (gst_pad_link (srcpad, sinkpad) == GST_PAD_LINK_OK, |
354 "Could not link %s source and sink pads", GST_ELEMENT_NAME (element)); |
406 "Could not link %s source and sink pads", GST_ELEMENT_NAME (element)); |
364 |
416 |
365 |
417 |
366 void |
418 void |
367 gst_check_teardown_sink_pad (GstElement * element) |
419 gst_check_teardown_sink_pad (GstElement * element) |
368 { |
420 { |
369 GstPad *srcpad, *sinkpad; |
421 gst_check_teardown_pad_by_name (element, "src"); |
370 |
|
371 /* clean up floating sink pad */ |
|
372 srcpad = gst_element_get_pad (element, "src"); |
|
373 sinkpad = gst_pad_get_peer (srcpad); |
|
374 |
|
375 gst_pad_unlink (srcpad, sinkpad); |
|
376 |
|
377 /* pad refs held by both creator and this function (through _get_pad) */ |
|
378 ASSERT_OBJECT_REFCOUNT (srcpad, "element srcpad", 2); |
|
379 gst_object_unref (srcpad); |
|
380 /* one more ref is held by element itself */ |
|
381 |
|
382 /* pad refs held by both creator and this function (through _get_peer) */ |
|
383 ASSERT_OBJECT_REFCOUNT (sinkpad, "check sinkpad", 2); |
|
384 gst_object_unref (sinkpad); |
|
385 gst_object_unref (sinkpad); |
|
386 } |
422 } |
387 |
423 |
388 /** |
424 /** |
389 * gst_check_drop_buffers: |
425 * gst_check_drop_buffers: |
390 * |
426 * |
481 |
516 |
482 fail_unless (GST_IS_BUFFER (buffer), "There should be a buffer in buffer_in"); |
517 fail_unless (GST_IS_BUFFER (buffer), "There should be a buffer in buffer_in"); |
483 src_caps = GST_BUFFER_CAPS (buffer); |
518 src_caps = GST_BUFFER_CAPS (buffer); |
484 src_pad = gst_pad_new (NULL, GST_PAD_SRC); |
519 src_pad = gst_pad_new (NULL, GST_PAD_SRC); |
485 gst_pad_set_caps (src_pad, src_caps); |
520 gst_pad_set_caps (src_pad, src_caps); |
486 pad_peer = gst_element_get_pad (element, "sink"); |
521 pad_peer = gst_element_get_static_pad (element, "sink"); |
487 fail_if (pad_peer == NULL, ""); |
522 fail_if (pad_peer == NULL); |
488 fail_unless (gst_pad_link (src_pad, pad_peer) == GST_PAD_LINK_OK, |
523 fail_unless (gst_pad_link (src_pad, pad_peer) == GST_PAD_LINK_OK, |
489 "Could not link source and %s sink pads", GST_ELEMENT_NAME (element)); |
524 "Could not link source and %s sink pads", GST_ELEMENT_NAME (element)); |
490 gst_object_unref (pad_peer); |
525 gst_object_unref (pad_peer); |
491 /* activate the pad */ |
526 /* activate the pad */ |
492 gst_pad_set_active (src_pad, TRUE); |
527 gst_pad_set_active (src_pad, TRUE); |
503 |
538 |
504 GST_DEBUG ("sink caps requested by buffer out: '%s'", temp); |
539 GST_DEBUG ("sink caps requested by buffer out: '%s'", temp); |
505 g_free (temp); |
540 g_free (temp); |
506 fail_unless (gst_caps_is_fixed (sink_caps), "we need fixed caps"); |
541 fail_unless (gst_caps_is_fixed (sink_caps), "we need fixed caps"); |
507 /* get the sink pad */ |
542 /* get the sink pad */ |
508 sink_pad = gst_pad_new ('\0', GST_PAD_SINK); |
543 sink_pad = gst_pad_new (NULL, GST_PAD_SINK); |
509 fail_unless (GST_IS_PAD (sink_pad), ""); |
544 fail_unless (GST_IS_PAD (sink_pad)); |
510 gst_pad_set_caps (sink_pad, sink_caps); |
545 gst_pad_set_caps (sink_pad, sink_caps); |
511 /* get the peer pad */ |
546 /* get the peer pad */ |
512 pad_peer = gst_element_get_pad (element, "src"); |
547 pad_peer = gst_element_get_static_pad (element, "src"); |
513 fail_unless (gst_pad_link (pad_peer, sink_pad) == GST_PAD_LINK_OK, |
548 fail_unless (gst_pad_link (pad_peer, sink_pad) == GST_PAD_LINK_OK, |
514 "Could not link sink and %s source pads", GST_ELEMENT_NAME (element)); |
549 "Could not link sink and %s source pads", GST_ELEMENT_NAME (element)); |
515 gst_object_unref (pad_peer); |
550 gst_object_unref (pad_peer); |
516 /* configure the sink pad */ |
551 /* configure the sink pad */ |
517 gst_pad_set_chain_function (sink_pad, gst_check_chain_func); |
552 gst_pad_set_chain_function (sink_pad, gst_check_chain_func); |
566 gst_check_teardown_element (element); |
601 gst_check_teardown_element (element); |
567 } |
602 } |
568 |
603 |
569 /** |
604 /** |
570 * gst_check_element_push_buffer: |
605 * gst_check_element_push_buffer: |
571 * @element: name of the element that needs to be created |
606 * @element_name: name of the element that needs to be created |
572 * @buffer_in: push this buffer to the element |
607 * @buffer_in: push this buffer to the element |
573 * @buffer_out: compare the result with this buffer |
608 * @buffer_out: compare the result with this buffer |
574 * |
609 * |
575 * Create an @element with the factory with the name and push the |
610 * Create an @element with the factory with the name and push the |
576 * @buffer_in to this element. The element should create one buffer |
611 * @buffer_in to this element. The element should create one buffer |