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