1 /* GStreamer unit tests for queue2
3 * Copyright (C) 2011 Tim-Philipp Müller <tim centricular net>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
21 #include <gst/check/gstcheck.h>
24 setup_queue2 (GstElement * pipe, GstElement * input, GstElement * output)
27 GstPad *sinkpad, *srcpad;
29 queue2 = gst_element_factory_make ("queue2", NULL);
30 fail_unless (queue2 != NULL, "failed to create 'queue2' element");
32 gst_bin_add (GST_BIN (pipe), queue2);
33 gst_bin_add (GST_BIN (pipe), input);
34 gst_bin_add (GST_BIN (pipe), output);
36 sinkpad = gst_element_get_static_pad (queue2, "sink");
37 fail_unless (sinkpad != NULL, "failed to get queue2 sink pad");
39 srcpad = gst_element_get_static_pad (input, "src");
40 fail_unless (srcpad != NULL, "failed to find src pad for input element");
42 fail_unless_equals_int (GST_PAD_LINK_OK, gst_pad_link (srcpad, sinkpad));
43 gst_object_unref (srcpad);
44 gst_object_unref (sinkpad);
46 srcpad = gst_element_get_static_pad (queue2, "src");
47 fail_unless (srcpad != NULL);
49 sinkpad = gst_element_get_static_pad (output, "sink");
50 fail_unless (sinkpad != NULL, "failed to find sink pad of output element");
52 fail_unless_equals_int (GST_PAD_LINK_OK, gst_pad_link (srcpad, sinkpad));
54 gst_object_unref (srcpad);
55 gst_object_unref (sinkpad);
60 GST_START_TEST (test_simple_pipeline)
62 GstElement *pipe, *input, *output;
65 pipe = gst_pipeline_new ("pipeline");
67 input = gst_element_factory_make ("fakesrc", NULL);
68 fail_unless (input != NULL, "failed to create 'fakesrc' element");
69 g_object_set (input, "num-buffers", 256, "sizetype", 3, NULL);
71 output = gst_element_factory_make ("fakesink", NULL);
72 fail_unless (output != NULL, "failed to create 'fakesink' element");
74 setup_queue2 (pipe, input, output);
76 gst_element_set_state (pipe, GST_STATE_PLAYING);
78 msg = gst_bus_poll (GST_ELEMENT_BUS (pipe),
79 GST_MESSAGE_EOS | GST_MESSAGE_ERROR, -1);
81 fail_if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR,
82 "Expected EOS message, got ERROR message");
83 gst_message_unref (msg);
85 GST_LOG ("Got EOS, cleaning up");
87 gst_element_set_state (pipe, GST_STATE_NULL);
88 gst_object_unref (pipe);
93 GST_START_TEST (test_simple_pipeline_ringbuffer)
95 GstElement *pipe, *queue2, *input, *output;
98 pipe = gst_pipeline_new ("pipeline");
100 input = gst_element_factory_make ("fakesrc", NULL);
101 fail_unless (input != NULL, "failed to create 'fakesrc' element");
102 g_object_set (input, "num-buffers", 256, "sizetype", 3, NULL);
104 output = gst_element_factory_make ("fakesink", NULL);
105 fail_unless (output != NULL, "failed to create 'fakesink' element");
107 queue2 = setup_queue2 (pipe, input, output);
108 g_object_set (queue2, "ring-buffer-max-size", (guint64) 1024 * 50, NULL);
110 gst_element_set_state (pipe, GST_STATE_PLAYING);
112 msg = gst_bus_poll (GST_ELEMENT_BUS (pipe),
113 GST_MESSAGE_EOS | GST_MESSAGE_ERROR, -1);
115 fail_if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR,
116 "Expected EOS message, got ERROR message");
117 gst_message_unref (msg);
119 GST_LOG ("Got EOS, cleaning up");
121 gst_element_set_state (pipe, GST_STATE_NULL);
122 gst_object_unref (pipe);
128 do_test_simple_shutdown_while_running (guint64 ring_buffer_max_size)
130 GstElement *pipe, *q2;
135 pipe = gst_pipeline_new ("pipeline");
137 input = gst_element_factory_make ("fakesrc", NULL);
138 fail_unless (input != NULL, "failed to create 'fakesrc' element");
139 g_object_set (input, "format", GST_FORMAT_TIME, "sizetype", 2,
140 "sizemax", 10, NULL);
142 output = gst_element_factory_make ("fakesink", NULL);
143 fail_unless (output != NULL, "failed to create 'fakesink' element");
145 q2 = setup_queue2 (pipe, input, output);
147 if (ring_buffer_max_size > 0) {
148 g_object_set (q2, "ring-buffer-max-size", ring_buffer_max_size,
149 "temp-template", NULL, NULL);
152 gst_element_set_state (pipe, GST_STATE_PAUSED);
154 /* wait until pipeline is up and running */
155 msg = gst_bus_poll (GST_ELEMENT_BUS (pipe),
156 GST_MESSAGE_ERROR | GST_MESSAGE_ASYNC_DONE, -1);
157 fail_if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR, "Got ERROR message");
158 gst_message_unref (msg);
160 GST_LOG ("pipeline is running now");
161 gst_element_set_state (pipe, GST_STATE_PLAYING);
162 g_usleep (G_USEC_PER_SEC / 20);
164 /* now shut down only the sink, so the queue gets a wrong-state flow return */
165 gst_element_set_state (output, GST_STATE_NULL);
166 GST_LOG ("Cleaning up");
168 gst_element_set_state (pipe, GST_STATE_NULL);
169 gst_object_unref (pipe);
172 GST_START_TEST (test_simple_shutdown_while_running)
176 /* run a couple of iterations, gives higher chance of different code paths
177 * being executed at time the flush is detected (esp. useful to make sure
178 * things are cleaned up properly when running under valgrind) */
179 for (i = 0; i < 10; ++i) {
180 do_test_simple_shutdown_while_running (0);
186 GST_START_TEST (test_simple_shutdown_while_running_ringbuffer)
190 /* run a couple of iterations, gives higher chance of different code paths
191 * being executed at time the flush is detected (esp. useful to make sure
192 * things are cleaned up properly when running under valgrind) */
193 for (i = 0; i < 10; ++i) {
194 do_test_simple_shutdown_while_running (1024 * 1024);
200 GST_START_TEST (test_simple_create_destroy)
204 queue2 = gst_element_factory_make ("queue2", NULL);
205 gst_object_unref (queue2);
213 Suite *s = suite_create ("queue2");
214 TCase *tc_chain = tcase_create ("general");
216 suite_add_tcase (s, tc_chain);
217 tcase_add_test (tc_chain, test_simple_create_destroy);
218 tcase_add_test (tc_chain, test_simple_pipeline);
219 tcase_add_test (tc_chain, test_simple_pipeline_ringbuffer);
220 tcase_add_test (tc_chain, test_simple_shutdown_while_running);
221 tcase_add_test (tc_chain, test_simple_shutdown_while_running_ringbuffer);
225 GST_CHECK_MAIN (queue2)