2 * Copyright (C) <2005> Thomas Vander Stichele <thomas at apestaart dot org>
4 * cleanup.c: Unit test for cleanup of pipelines
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
23 #include <gst/check/gstcheck.h>
26 setup_pipeline (const gchar * pipe_descr)
31 pipeline = gst_parse_launch (pipe_descr, &error);
33 fail_if (error != NULL, "Error parsing pipeline %s: %s", pipe_descr,
37 fail_unless (pipeline != NULL, "Failed to create pipeline %s", pipe_descr);
42 expected_fail_pipe (const gchar * pipe_descr)
47 #ifndef GST_DISABLE_GST_DEBUG
48 gst_debug_set_default_threshold (GST_LEVEL_NONE);
51 pipeline = gst_parse_launch (pipe_descr, &error);
52 fail_unless (error != NULL, "Expected failure pipeline %s: succeeded!");
55 /* We get a pipeline back even when parsing has failed, sometimes! */
57 gst_object_unref (pipeline);
61 check_pipeline_runs (GstElement * p)
63 GstStateChangeReturn ret;
65 /* Check that the pipeline changes state to PAUSED and back to NULL */
66 ret = gst_element_set_state (p, GST_STATE_PAUSED);
67 if (ret == GST_STATE_CHANGE_ASYNC)
68 ret = gst_element_get_state (p, NULL, NULL, GST_CLOCK_TIME_NONE);
69 fail_unless (ret != GST_STATE_CHANGE_FAILURE,
70 "Could not set pipeline to paused");
72 ret = gst_element_set_state (p, GST_STATE_NULL);
73 if (ret == GST_STATE_CHANGE_ASYNC)
74 ret = gst_element_get_state (p, NULL, NULL, GST_CLOCK_TIME_NONE);
75 fail_unless (ret != GST_STATE_CHANGE_FAILURE,
76 "Could not set pipeline to null");
79 static const gchar *test_lines[] = {
80 "filesrc location=music.mp3 ! identity ! fakesink",
81 "filesrc location=music.ogg ! tee ! identity ! identity ! fakesink",
82 "filesrc location=http://domain.com/music.mp3 ! identity ! fakesink",
83 "filesrc location=movie.avi ! tee name=demuxer ! ( queue ! identity ! fakesink ) ( demuxer. ! queue ! identity ! fakesink )",
84 "fakesrc ! video/x-raw-yuv ! fakesink",
85 "fakesrc ! video/raw, format=(fourcc)YUY2; video/raw, format=(fourcc)YV12 ! fakesink",
86 "fakesrc ! audio/x-raw-int, width=[16, 32], depth={16, 24, 32}, signed=TRUE ! fakesink",
90 GST_START_TEST (test_launch_lines)
95 for (s = test_lines; *s != NULL; s++) {
96 pipeline = setup_pipeline (*s);
97 gst_object_unref (pipeline);
103 #define PIPELINE1 "fakesrc"
104 #define PIPELINE2 "fakesrc name=donald num-buffers= 27 silent =TruE sizetype = 3 data= Subbuffer\\ data"
105 #define PIPELINE3 "fakesrc identity fakesink"
106 #define PIPELINE4 "fakesrc num-buffers=4 .src ! identity !.sink identity .src ! .sink fakesink"
107 #define PIPELINE5 "fakesrc num-buffers=4 name=src identity name=id1 identity name = id2 fakesink name =sink src. ! id1. id1.! id2.sink id2.src!sink.sink"
108 #define PIPELINE6 "pipeline.(name=\"john\" fakesrc num-buffers=4 ( bin. ( ! queue ! identity !( queue ! fakesink )) ))"
109 #define PIPELINE7 "fakesrc num-buffers=4 ! tee name=tee .src%d! queue ! fakesink tee.src%d ! queue ! fakesink queue name =\"foo\" ! fakesink tee.src%d ! foo."
110 /* aggregator is borked
111 * #define PIPELINE8 "fakesrc num-buffers=4 ! tee name=tee1 .src0,src1 ! .sink0, sink1 aggregator ! fakesink"
113 #define PIPELINE8 "fakesrc num-buffers=4 ! fakesink"
114 #define PIPELINE9 "fakesrc num-buffers=4 ! test. fakesink name=test"
115 #define PIPELINE10 "( fakesrc num-buffers=\"4\" ! ) identity ! fakesink"
116 #define PIPELINE11 "fakesink name = sink identity name=id ( fakesrc num-buffers=\"4\" ! id. ) id. ! sink."
117 #define PIPELINE12 "fakesrc num-buffers=4 name=\"a=b\" a=b. ! fakesink"
118 #define PIPELINE13 "file:///tmp/test.file ! fakesink"
120 GST_START_TEST (test_launch_lines2)
129 * - specifying an element works :)
130 * - if only 1 element is requested, no bin is returned, but the element
132 cur = setup_pipeline (PIPELINE1);
133 fail_unless (G_OBJECT_TYPE (cur) == g_type_from_name ("GstFakeSrc"),
134 "parse_launch did not produce a fakesrc");
135 gst_object_unref (cur);
140 * - string, int, boolean and enums can be properly set
141 * - first test of escaping strings
143 cur = setup_pipeline (PIPELINE2);
144 g_object_get (G_OBJECT (cur), "name", &s, "num-buffers", &i,
146 fail_if (s == NULL, "name was NULL");
147 fail_unless (strcmp (s, "donald") == 0, "fakesrc name was not 'donald'");
148 fail_unless (i == 27, "num-buffers was not 27");
149 fail_unless (b == TRUE, "silent was not TRUE");
152 g_object_get (G_OBJECT (cur), "sizetype", &i, NULL);
153 fail_unless (i == 3, "sizetype != 3");
155 g_object_get (G_OBJECT (cur), "data", &i, NULL);
156 fail_unless (i == 2, "data != 2");
157 gst_object_unref (cur);
161 * - specifying multiple elements without links works
162 * - if multiple toplevel elements exist, a pipeline is returned
164 cur = setup_pipeline (PIPELINE3);
165 fail_unless (GST_BIN_NUMCHILDREN (cur) == 3,
166 "Pipeline does not contain 3 children");
167 gst_object_unref (cur);
171 * - test default link "!"
172 * - test if specifying pads on links works
174 cur = setup_pipeline (PIPELINE4);
175 check_pipeline_runs (cur);
176 gst_object_unref (cur);
180 * - test if appending the links works, too
181 * - check if the pipeline constructed works the same as the one before (how?)
183 cur = setup_pipeline (PIPELINE5);
184 check_pipeline_runs (cur);
185 gst_object_unref (cur);
189 * - test various types of bins
190 * - test if linking across bins works
191 * - test if escaping strings works
193 cur = setup_pipeline (PIPELINE6);
194 fail_unless (GST_IS_PIPELINE (cur), "Parse did not produce a pipeline");
195 g_object_get (G_OBJECT (cur), "name", &s, NULL);
196 fail_if (s == NULL, "name was NULL");
197 fail_unless (strcmp (s, "john") == 0, "Name was not 'john'");
199 check_pipeline_runs (cur);
200 gst_object_unref (cur);
204 * - test request pads
206 cur = setup_pipeline (PIPELINE7);
207 check_pipeline_runs (cur);
208 gst_object_unref (cur);
212 * - multiple pads on 1 link
214 cur = setup_pipeline (PIPELINE8);
215 check_pipeline_runs (cur);
216 gst_object_unref (cur);
220 * - failed in grammar.y cvs version 1.17
222 cur = setup_pipeline (PIPELINE9);
223 check_pipeline_runs (cur);
224 gst_object_unref (cur);
228 * - failed in grammar.y cvs version 1.17
230 cur = setup_pipeline (PIPELINE10);
231 check_pipeline_runs (cur);
232 gst_object_unref (cur);
236 * - failed in grammar.y cvs version 1.18
238 cur = setup_pipeline (PIPELINE11);
239 check_pipeline_runs (cur);
240 gst_object_unref (cur);
244 * - fails because a=b. is not a valid element reference in parse.l
246 expected_fail_pipe (PIPELINE12);
250 * - URI detection works
252 cur = setup_pipeline (PIPELINE13);
253 gst_object_unref (cur);
261 Suite *s = suite_create ("Parse Launch syntax");
262 TCase *tc_chain = tcase_create ("parselaunch");
264 /* time out after 20s, not the default 3 */
265 tcase_set_timeout (tc_chain, 20);
267 suite_add_tcase (s, tc_chain);
268 tcase_add_test (tc_chain, test_launch_lines);
269 tcase_add_test (tc_chain, test_launch_lines2);
273 GST_CHECK_MAIN (parse);