adder: Don't fail when alsasrc is unavailable
[platform/upstream/gstreamer.git] / tests / check / elements / adder.c
1 /* GStreamer
2  *
3  * unit test for adder
4  *
5  * Copyright (C) <2005> Thomas Vander Stichele <thomas at apestaart dot org>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23 #ifdef HAVE_CONFIG_H
24 # include <config.h>
25 #endif
26
27 #ifdef HAVE_VALGRIND
28 # include <valgrind/valgrind.h>
29 #endif
30
31 #include <unistd.h>
32
33 #include <gst/check/gstcheck.h>
34
35 static GMainLoop *main_loop;
36
37 static void
38 message_received (GstBus * bus, GstMessage * message, GstPipeline * bin)
39 {
40   GST_INFO ("bus message from \"%" GST_PTR_FORMAT "\": %" GST_PTR_FORMAT,
41       GST_MESSAGE_SRC (message), message);
42
43   switch (message->type) {
44     case GST_MESSAGE_EOS:
45       g_main_loop_quit (main_loop);
46       break;
47     case GST_MESSAGE_WARNING:{
48       GError *gerror;
49       gchar *debug;
50
51       gst_message_parse_warning (message, &gerror, &debug);
52       gst_object_default_error (GST_MESSAGE_SRC (message), gerror, debug);
53       g_error_free (gerror);
54       g_free (debug);
55       break;
56     }
57     case GST_MESSAGE_ERROR:{
58       GError *gerror;
59       gchar *debug;
60
61       gst_message_parse_error (message, &gerror, &debug);
62       gst_object_default_error (GST_MESSAGE_SRC (message), gerror, debug);
63       g_error_free (gerror);
64       g_free (debug);
65       g_main_loop_quit (main_loop);
66       break;
67     }
68     default:
69       break;
70   }
71 }
72
73
74 static GstFormat format = GST_FORMAT_UNDEFINED;
75 static gint64 position = -1;
76
77 static void
78 test_event_message_received (GstBus * bus, GstMessage * message,
79     GstPipeline * bin)
80 {
81   GST_INFO ("bus message from \"%" GST_PTR_FORMAT "\": %" GST_PTR_FORMAT,
82       GST_MESSAGE_SRC (message), message);
83
84   switch (message->type) {
85     case GST_MESSAGE_SEGMENT_DONE:
86       gst_message_parse_segment_done (message, &format, &position);
87       GST_INFO ("received segment_done : %" G_GINT64_FORMAT, position);
88       g_main_loop_quit (main_loop);
89       break;
90     default:
91       g_assert_not_reached ();
92       break;
93   }
94 }
95
96
97 GST_START_TEST (test_event)
98 {
99   GstElement *bin, *src1, *src2, *adder, *sink;
100   GstBus *bus;
101   GstEvent *seek_event;
102   gboolean res;
103
104   GST_INFO ("preparing test");
105
106   /* build pipeline */
107   bin = gst_pipeline_new ("pipeline");
108   bus = gst_element_get_bus (bin);
109   gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH);
110
111   /* FIXME, fakesrc with default setting will produce 0 sized
112    * buffers and incompatible caps for adder that will make
113    * adder EOS and error out */
114   src1 = gst_element_factory_make ("audiotestsrc", "src1");
115   g_object_set (src1, "wave", 4, NULL); /* silence */
116   src2 = gst_element_factory_make ("audiotestsrc", "src2");
117   g_object_set (src2, "wave", 4, NULL); /* silence */
118   adder = gst_element_factory_make ("adder", "adder");
119   sink = gst_element_factory_make ("fakesink", "sink");
120   gst_bin_add_many (GST_BIN (bin), src1, src2, adder, sink, NULL);
121
122   res = gst_element_link (src1, adder);
123   fail_unless (res == TRUE, NULL);
124   res = gst_element_link (src2, adder);
125   fail_unless (res == TRUE, NULL);
126   res = gst_element_link (adder, sink);
127   fail_unless (res == TRUE, NULL);
128
129   seek_event = gst_event_new_seek (1.0, GST_FORMAT_TIME,
130       GST_SEEK_FLAG_SEGMENT | GST_SEEK_FLAG_FLUSH,
131       GST_SEEK_TYPE_SET, (GstClockTime) 0,
132       GST_SEEK_TYPE_SET, (GstClockTime) 2 * GST_SECOND);
133
134   format = GST_FORMAT_UNDEFINED;
135   position = -1;
136
137   main_loop = g_main_loop_new (NULL, FALSE);
138   g_signal_connect (bus, "message::segment-done",
139       (GCallback) test_event_message_received, bin);
140   g_signal_connect (bus, "message::error", (GCallback) message_received, bin);
141   g_signal_connect (bus, "message::warning", (GCallback) message_received, bin);
142   g_signal_connect (bus, "message::eos", (GCallback) message_received, bin);
143
144   GST_INFO ("starting test");
145
146   /* prepare playing */
147   res = gst_element_set_state (bin, GST_STATE_PAUSED);
148   fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
149
150   /* wait for completion */
151   res = gst_element_get_state (bin, NULL, NULL, GST_CLOCK_TIME_NONE);
152   fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
153
154   res = gst_element_send_event (bin, seek_event);
155   fail_unless (res == TRUE, NULL);
156
157   /* run pipeline */
158   res = gst_element_set_state (bin, GST_STATE_PLAYING);
159   fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
160
161   g_main_loop_run (main_loop);
162
163   res = gst_element_set_state (bin, GST_STATE_NULL);
164   fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
165
166   fail_unless (position == 2 * GST_SECOND, NULL);
167
168   /* cleanup */
169   g_main_loop_unref (main_loop);
170   gst_object_unref (G_OBJECT (bus));
171   gst_object_unref (G_OBJECT (bin));
172 }
173
174 GST_END_TEST;
175
176 static guint play_count = 0;
177 static GstEvent *play_seek_event = NULL;
178
179 static void
180 test_play_twice_message_received (GstBus * bus, GstMessage * message,
181     GstPipeline * bin)
182 {
183   gboolean res;
184
185   GST_INFO ("bus message from \"%" GST_PTR_FORMAT "\": %" GST_PTR_FORMAT,
186       GST_MESSAGE_SRC (message), message);
187
188   switch (message->type) {
189     case GST_MESSAGE_SEGMENT_DONE:
190       play_count++;
191       if (play_count == 1) {
192         res = gst_element_set_state (GST_ELEMENT (bin), GST_STATE_READY);
193         fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
194
195         /* prepare playing again */
196         res = gst_element_set_state (GST_ELEMENT (bin), GST_STATE_PAUSED);
197         fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
198
199         /* wait for completion */
200         res =
201             gst_element_get_state (GST_ELEMENT (bin), NULL, NULL,
202             GST_CLOCK_TIME_NONE);
203         fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
204
205         res = gst_element_send_event (GST_ELEMENT (bin),
206             gst_event_ref (play_seek_event));
207         fail_unless (res == TRUE, NULL);
208
209         res = gst_element_set_state (GST_ELEMENT (bin), GST_STATE_PLAYING);
210         fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
211       } else {
212         g_main_loop_quit (main_loop);
213       }
214       break;
215     default:
216       g_assert_not_reached ();
217       break;
218   }
219 }
220
221
222 GST_START_TEST (test_play_twice)
223 {
224   GstElement *bin, *src1, *src2, *adder, *sink;
225   GstBus *bus;
226   gboolean res;
227
228   GST_INFO ("preparing test");
229
230   /* build pipeline */
231   bin = gst_pipeline_new ("pipeline");
232   bus = gst_element_get_bus (bin);
233   gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH);
234
235   src1 = gst_element_factory_make ("audiotestsrc", "src1");
236   g_object_set (src1, "wave", 4, NULL); /* silence */
237   src2 = gst_element_factory_make ("audiotestsrc", "src2");
238   g_object_set (src2, "wave", 4, NULL); /* silence */
239   adder = gst_element_factory_make ("adder", "adder");
240   sink = gst_element_factory_make ("fakesink", "sink");
241   gst_bin_add_many (GST_BIN (bin), src1, src2, adder, sink, NULL);
242
243   res = gst_element_link (src1, adder);
244   fail_unless (res == TRUE, NULL);
245   res = gst_element_link (src2, adder);
246   fail_unless (res == TRUE, NULL);
247   res = gst_element_link (adder, sink);
248   fail_unless (res == TRUE, NULL);
249
250   play_seek_event = gst_event_new_seek (1.0, GST_FORMAT_TIME,
251       GST_SEEK_FLAG_SEGMENT | GST_SEEK_FLAG_FLUSH,
252       GST_SEEK_TYPE_SET, (GstClockTime) 0,
253       GST_SEEK_TYPE_SET, (GstClockTime) 2 * GST_SECOND);
254
255   play_count = 0;
256
257   main_loop = g_main_loop_new (NULL, FALSE);
258   g_signal_connect (bus, "message::segment-done",
259       (GCallback) test_play_twice_message_received, bin);
260   g_signal_connect (bus, "message::error", (GCallback) message_received, bin);
261   g_signal_connect (bus, "message::warning", (GCallback) message_received, bin);
262   g_signal_connect (bus, "message::eos", (GCallback) message_received, bin);
263
264   GST_INFO ("starting test");
265
266   /* prepare playing */
267   res = gst_element_set_state (bin, GST_STATE_PAUSED);
268   fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
269
270   /* wait for completion */
271   res =
272       gst_element_get_state (GST_ELEMENT (bin), NULL, NULL,
273       GST_CLOCK_TIME_NONE);
274   fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
275
276   res = gst_element_send_event (bin, gst_event_ref (play_seek_event));
277   fail_unless (res == TRUE, NULL);
278
279   GST_INFO ("seeked");
280
281   /* run pipeline */
282   res = gst_element_set_state (bin, GST_STATE_PLAYING);
283   fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
284
285   g_main_loop_run (main_loop);
286
287   res = gst_element_set_state (bin, GST_STATE_NULL);
288   fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
289
290   fail_unless (play_count == 2, NULL);
291
292   /* cleanup */
293   g_main_loop_unref (main_loop);
294   gst_event_ref (play_seek_event);
295   gst_object_unref (G_OBJECT (bus));
296   gst_object_unref (G_OBJECT (bin));
297 }
298
299 GST_END_TEST;
300
301 GST_START_TEST (test_play_twice_then_add_and_play_again)
302 {
303   GstElement *bin, *src1, *src2, *src3, *adder, *sink;
304   GstBus *bus;
305   gboolean res;
306   gint i;
307
308   GST_INFO ("preparing test");
309
310   /* build pipeline */
311   bin = gst_pipeline_new ("pipeline");
312   bus = gst_element_get_bus (bin);
313   gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH);
314
315   src1 = gst_element_factory_make ("audiotestsrc", "src1");
316   g_object_set (src1, "wave", 4, NULL); /* silence */
317   src2 = gst_element_factory_make ("audiotestsrc", "src2");
318   g_object_set (src2, "wave", 4, NULL); /* silence */
319   adder = gst_element_factory_make ("adder", "adder");
320   sink = gst_element_factory_make ("fakesink", "sink");
321   gst_bin_add_many (GST_BIN (bin), src1, src2, adder, sink, NULL);
322
323   res = gst_element_link (src1, adder);
324   fail_unless (res == TRUE, NULL);
325   res = gst_element_link (src2, adder);
326   fail_unless (res == TRUE, NULL);
327   res = gst_element_link (adder, sink);
328   fail_unless (res == TRUE, NULL);
329
330   play_seek_event = gst_event_new_seek (1.0, GST_FORMAT_TIME,
331       GST_SEEK_FLAG_SEGMENT | GST_SEEK_FLAG_FLUSH,
332       GST_SEEK_TYPE_SET, (GstClockTime) 0,
333       GST_SEEK_TYPE_SET, (GstClockTime) 2 * GST_SECOND);
334
335   main_loop = g_main_loop_new (NULL, FALSE);
336   g_signal_connect (bus, "message::segment-done",
337       (GCallback) test_play_twice_message_received, bin);
338   g_signal_connect (bus, "message::error", (GCallback) message_received, bin);
339   g_signal_connect (bus, "message::warning", (GCallback) message_received, bin);
340   g_signal_connect (bus, "message::eos", (GCallback) message_received, bin);
341
342   /* run it twice */
343   for (i = 0; i < 2; i++) {
344     play_count = 0;
345
346     GST_INFO ("starting test-loop %d", i);
347
348     /* prepare playing */
349     res = gst_element_set_state (bin, GST_STATE_PAUSED);
350     fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
351
352     /* wait for completion */
353     res =
354         gst_element_get_state (GST_ELEMENT (bin), NULL, NULL,
355         GST_CLOCK_TIME_NONE);
356     fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
357
358     res = gst_element_send_event (bin, gst_event_ref (play_seek_event));
359     fail_unless (res == TRUE, NULL);
360
361     GST_INFO ("seeked");
362
363     /* run pipeline */
364     res = gst_element_set_state (bin, GST_STATE_PLAYING);
365     fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
366
367     g_main_loop_run (main_loop);
368
369     res = gst_element_set_state (bin, GST_STATE_READY);
370     fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
371
372     fail_unless (play_count == 2, NULL);
373
374     /* plug another source */
375     if (i == 0) {
376       src3 = gst_element_factory_make ("audiotestsrc", "src3");
377       g_object_set (src3, "wave", 4, NULL);     /* silence */
378       gst_bin_add (GST_BIN (bin), src3);
379
380       res = gst_element_link (src3, adder);
381       fail_unless (res == TRUE, NULL);
382     }
383   }
384
385   res = gst_element_set_state (bin, GST_STATE_NULL);
386   fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
387
388   /* cleanup */
389   g_main_loop_unref (main_loop);
390   gst_event_ref (play_seek_event);
391   gst_object_unref (G_OBJECT (bus));
392   gst_object_unref (G_OBJECT (bin));
393 }
394
395 GST_END_TEST;
396
397
398 static void
399 test_live_seeking_eos_message_received (GstBus * bus, GstMessage * message,
400     GstPipeline * bin)
401 {
402   GST_INFO ("bus message from \"%" GST_PTR_FORMAT "\": %" GST_PTR_FORMAT,
403       GST_MESSAGE_SRC (message), message);
404
405   switch (message->type) {
406     case GST_MESSAGE_EOS:
407       g_main_loop_quit (main_loop);
408       break;
409     default:
410       g_assert_not_reached ();
411       break;
412   }
413 }
414
415
416 /* test failing seeks on live-sources */
417 GST_START_TEST (test_live_seeking)
418 {
419   GstElement *bin, *src1, *src2, *ac1, *ac2, *adder, *sink;
420   GstBus *bus;
421   gboolean res;
422   gint i;
423
424   GST_INFO ("preparing test");
425   main_loop = NULL;
426   play_seek_event = NULL;
427
428   /* build pipeline */
429   bin = gst_pipeline_new ("pipeline");
430   bus = gst_element_get_bus (bin);
431   gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH);
432
433   /* normal audiosources behave differently than audiotestsrc */
434 #if 0
435   src1 = gst_element_factory_make ("audiotestsrc", "src1");
436   g_object_set (src1, "wave", 4, "is-live", TRUE, NULL);        /* silence */
437 #else
438   src1 = gst_element_factory_make ("alsasrc", "src1");
439   if (!src1) {
440     GST_INFO ("no audiosrc, skipping");
441     goto cleanup;
442   }
443   /* Test that the audio source can get to paused, else skip */
444   res = gst_element_set_state (src1, GST_STATE_PAUSED);
445   (void) gst_element_set_state (src1, GST_STATE_NULL);
446   if (res == GST_STATE_CHANGE_FAILURE) {
447     gst_object_unref (src1);
448     goto cleanup;
449   }
450
451   /* live sources ignore seeks, force eos after 2 sec (4 buffers half second
452    * each) - don't use autoaudiosrc, as then we can't set anything here */
453   g_object_set (src1, "num-buffers", 4, "blocksize", 44100, NULL);
454 #endif
455   ac1 = gst_element_factory_make ("audioconvert", "ac1");
456   src2 = gst_element_factory_make ("audiotestsrc", "src2");
457   g_object_set (src2, "wave", 4, NULL); /* silence */
458   ac2 = gst_element_factory_make ("audioconvert", "ac2");
459   adder = gst_element_factory_make ("adder", "adder");
460   sink = gst_element_factory_make ("fakesink", "sink");
461   gst_bin_add_many (GST_BIN (bin), src1, ac1, src2, ac2, adder, sink, NULL);
462
463   res = gst_element_link (src1, ac1);
464   fail_unless (res == TRUE, NULL);
465   res = gst_element_link (ac1, adder);
466   fail_unless (res == TRUE, NULL);
467   res = gst_element_link (src2, ac2);
468   fail_unless (res == TRUE, NULL);
469   res = gst_element_link (ac2, adder);
470   fail_unless (res == TRUE, NULL);
471   res = gst_element_link (adder, sink);
472   fail_unless (res == TRUE, NULL);
473
474   play_seek_event = gst_event_new_seek (1.0, GST_FORMAT_TIME,
475       GST_SEEK_FLAG_FLUSH,
476       GST_SEEK_TYPE_SET, (GstClockTime) 0,
477       GST_SEEK_TYPE_SET, (GstClockTime) 2 * GST_SECOND);
478
479   main_loop = g_main_loop_new (NULL, FALSE);
480   g_signal_connect (bus, "message::error", (GCallback) message_received, bin);
481   g_signal_connect (bus, "message::warning", (GCallback) message_received, bin);
482   g_signal_connect (bus, "message::eos",
483       (GCallback) test_live_seeking_eos_message_received, bin);
484
485   /* run it twice */
486   for (i = 0; i < 2; i++) {
487
488     GST_INFO ("starting test-loop %d", i);
489
490     /* prepare playing */
491     res = gst_element_set_state (bin, GST_STATE_PAUSED);
492     fail_unless (res != GST_STATE_CHANGE_FAILURE);
493
494     /* wait for completion */
495     res =
496         gst_element_get_state (GST_ELEMENT (bin), NULL, NULL,
497         GST_CLOCK_TIME_NONE);
498     fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
499
500     res = gst_element_send_event (bin, gst_event_ref (play_seek_event));
501 #if 0
502     fail_unless (res == TRUE, NULL);
503 #else
504     /* adder is picky, if a single seek fails it totaly fails */
505     fail_unless (res == FALSE, NULL);
506 #endif
507
508     GST_INFO ("seeked");
509
510     /* run pipeline */
511     res = gst_element_set_state (bin, GST_STATE_PLAYING);
512     fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
513
514     GST_INFO ("playing");
515
516     g_main_loop_run (main_loop);
517
518     res = gst_element_set_state (bin, GST_STATE_NULL);
519     fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
520   }
521
522   /* cleanup */
523 cleanup:
524   if (main_loop)
525     g_main_loop_unref (main_loop);
526   if (play_seek_event)
527     gst_event_unref (play_seek_event);
528   gst_object_unref (G_OBJECT (bus));
529   gst_object_unref (G_OBJECT (bin));
530 }
531
532 GST_END_TEST;
533
534 /* check if adding pads work as expected */
535 GST_START_TEST (test_add_pad)
536 {
537   GstElement *bin, *src1, *src2, *adder, *sink;
538   GstBus *bus;
539   gboolean res;
540
541   GST_INFO ("preparing test");
542
543   /* build pipeline */
544   bin = gst_pipeline_new ("pipeline");
545   bus = gst_element_get_bus (bin);
546   gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH);
547
548   src1 = gst_element_factory_make ("audiotestsrc", "src1");
549   g_object_set (src1, "num-buffers", 4, NULL);
550   g_object_set (src1, "wave", 4, NULL); /* silence */
551   src2 = gst_element_factory_make ("audiotestsrc", "src2");
552   /* one buffer less, we connect with 1 buffer of delay */
553   g_object_set (src2, "num-buffers", 3, NULL);
554   g_object_set (src2, "wave", 4, NULL); /* silence */
555   adder = gst_element_factory_make ("adder", "adder");
556   sink = gst_element_factory_make ("fakesink", "sink");
557   gst_bin_add_many (GST_BIN (bin), src1, adder, sink, NULL);
558
559   res = gst_element_link (src1, adder);
560   fail_unless (res == TRUE, NULL);
561   res = gst_element_link (adder, sink);
562   fail_unless (res == TRUE, NULL);
563
564   main_loop = g_main_loop_new (NULL, FALSE);
565   g_signal_connect (bus, "message::segment-done", (GCallback) message_received,
566       bin);
567   g_signal_connect (bus, "message::error", (GCallback) message_received, bin);
568   g_signal_connect (bus, "message::warning", (GCallback) message_received, bin);
569   g_signal_connect (bus, "message::eos", (GCallback) message_received, bin);
570
571   GST_INFO ("starting test");
572
573   /* prepare playing */
574   res = gst_element_set_state (bin, GST_STATE_PAUSED);
575   fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
576
577   /* wait for completion */
578   res =
579       gst_element_get_state (GST_ELEMENT (bin), NULL, NULL,
580       GST_CLOCK_TIME_NONE);
581   fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
582
583   /* add other element */
584   gst_bin_add_many (GST_BIN (bin), src2, NULL);
585
586   /* now link the second element */
587   res = gst_element_link (src2, adder);
588   fail_unless (res == TRUE, NULL);
589
590   /* set to PAUSED as well */
591   res = gst_element_set_state (src2, GST_STATE_PAUSED);
592
593   /* now play all */
594   res = gst_element_set_state (bin, GST_STATE_PLAYING);
595   fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
596
597   g_main_loop_run (main_loop);
598
599   res = gst_element_set_state (bin, GST_STATE_NULL);
600   fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
601
602   /* cleanup */
603   g_main_loop_unref (main_loop);
604   gst_object_unref (G_OBJECT (bus));
605   gst_object_unref (G_OBJECT (bin));
606 }
607
608 GST_END_TEST;
609
610 /* check if removing pads work as expected */
611 GST_START_TEST (test_remove_pad)
612 {
613   GstElement *bin, *src, *adder, *sink;
614   GstBus *bus;
615   GstPad *pad;
616   gboolean res;
617
618   GST_INFO ("preparing test");
619
620   /* build pipeline */
621   bin = gst_pipeline_new ("pipeline");
622   bus = gst_element_get_bus (bin);
623   gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH);
624
625   src = gst_element_factory_make ("audiotestsrc", "src");
626   g_object_set (src, "num-buffers", 4, NULL);
627   g_object_set (src, "wave", 4, NULL);
628   adder = gst_element_factory_make ("adder", "adder");
629   sink = gst_element_factory_make ("fakesink", "sink");
630   gst_bin_add_many (GST_BIN (bin), src, adder, sink, NULL);
631
632   res = gst_element_link (src, adder);
633   fail_unless (res == TRUE, NULL);
634   res = gst_element_link (adder, sink);
635   fail_unless (res == TRUE, NULL);
636
637   /* create an unconnected sinkpad in adder */
638   pad = gst_element_get_request_pad (adder, "sink%d");
639   fail_if (pad == NULL, NULL);
640
641   main_loop = g_main_loop_new (NULL, FALSE);
642   g_signal_connect (bus, "message::segment-done", (GCallback) message_received,
643       bin);
644   g_signal_connect (bus, "message::error", (GCallback) message_received, bin);
645   g_signal_connect (bus, "message::warning", (GCallback) message_received, bin);
646   g_signal_connect (bus, "message::eos", (GCallback) message_received, bin);
647
648   GST_INFO ("starting test");
649
650   /* prepare playing, this will not preroll as adder is waiting
651    * on the unconnected sinkpad. */
652   res = gst_element_set_state (bin, GST_STATE_PAUSED);
653   fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
654
655   /* wait for completion for one second, will return ASYNC */
656   res = gst_element_get_state (GST_ELEMENT (bin), NULL, NULL, GST_SECOND);
657   fail_unless (res == GST_STATE_CHANGE_ASYNC, NULL);
658
659   /* get rid of the pad now, adder should stop waiting on it and
660    * continue the preroll */
661   gst_element_release_request_pad (adder, pad);
662   gst_object_unref (pad);
663
664   /* wait for completion, should work now */
665   res =
666       gst_element_get_state (GST_ELEMENT (bin), NULL, NULL,
667       GST_CLOCK_TIME_NONE);
668   fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
669
670   /* now play all */
671   res = gst_element_set_state (bin, GST_STATE_PLAYING);
672   fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
673
674   g_main_loop_run (main_loop);
675
676   res = gst_element_set_state (bin, GST_STATE_NULL);
677   fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
678
679   /* cleanup */
680   g_main_loop_unref (main_loop);
681   gst_object_unref (G_OBJECT (bus));
682   gst_object_unref (G_OBJECT (bin));
683 }
684
685 GST_END_TEST;
686
687
688 static Suite *
689 adder_suite (void)
690 {
691   Suite *s = suite_create ("adder");
692   TCase *tc_chain = tcase_create ("general");
693
694   suite_add_tcase (s, tc_chain);
695   tcase_add_test (tc_chain, test_event);
696   tcase_add_test (tc_chain, test_play_twice);
697   tcase_add_test (tc_chain, test_play_twice_then_add_and_play_again);
698   tcase_add_test (tc_chain, test_live_seeking);
699   tcase_add_test (tc_chain, test_add_pad);
700   tcase_add_test (tc_chain, test_remove_pad);
701
702   /* Use a longer timeout */
703 #ifdef HAVE_VALGRIND
704   if (RUNNING_ON_VALGRIND) {
705     tcase_set_timeout (tc_chain, 5 * 60);
706   } else
707 #endif
708   {
709     /* this is shorter than the default 60 seconds?! (tpm) */
710     /* tcase_set_timeout (tc_chain, 6); */
711   }
712
713   return s;
714 }
715
716 int
717 main (int argc, char **argv)
718 {
719   int nf;
720
721   Suite *s = adder_suite ();
722   SRunner *sr = srunner_create (s);
723
724   gst_check_init (&argc, &argv);
725
726   srunner_run_all (sr, CK_NORMAL);
727   nf = srunner_ntests_failed (sr);
728   srunner_free (sr);
729
730   return nf;
731 }