2 * Copyright (C) 2005 Andy Wingo <wingo@pobox.com>
4 * simple_launch_lines.c: Unit test for simple 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>
27 setup_pipeline (gchar * pipe_descr)
31 pipeline = gst_parse_launch (pipe_descr, NULL);
32 g_return_val_if_fail (GST_IS_PIPELINE (pipeline), NULL);
38 * @pipe: the pipeline to run
39 * @desc: the description for use in messages
40 * @events: is a mask of expected events
41 * @tevent: is the expected terminal event.
43 * the poll call will time out after half a second.
46 run_pipeline (GstElement * pipeline, gchar * descr,
47 GstMessageType events, GstMessageType tevent)
50 GstMessageType revent;
51 GstStateChangeReturn ret;
54 bus = gst_element_get_bus (pipeline);
57 ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
58 ret = gst_element_get_state (pipeline, NULL, NULL, NULL);
60 if (ret != GST_STATE_CHANGE_SUCCESS) {
61 g_critical ("Couldn't set pipeline to PLAYING");
66 GstMessage *message = gst_bus_poll (bus, GST_MESSAGE_ANY, GST_SECOND / 2);
69 revent = GST_MESSAGE_TYPE (message);
70 gst_message_unref (message);
72 revent = GST_MESSAGE_UNKNOWN;
75 if (revent == tevent) {
77 } else if (revent == GST_MESSAGE_UNKNOWN) {
78 g_critical ("Unexpected timeout in gst_bus_poll, looking for %d: %s",
81 } else if (revent & events) {
84 g_critical ("Unexpected message received of type %d, looking for %d: %s",
85 revent, tevent, descr);
89 gst_element_set_state (pipeline, GST_STATE_NULL);
90 gst_object_unref (pipeline);
91 gst_object_unref (bus);
94 GST_START_TEST (test_2_elements)
98 s = "fakesrc can-activate-push=false ! fakesink can-activate-pull=true";
99 run_pipeline (setup_pipeline (s), s,
100 GST_MESSAGE_NEW_CLOCK | GST_MESSAGE_STATE_CHANGED, GST_MESSAGE_UNKNOWN);
102 s = "fakesrc can-activate-push=true ! fakesink can-activate-pull=false";
103 run_pipeline (setup_pipeline (s), s,
104 GST_MESSAGE_NEW_CLOCK | GST_MESSAGE_STATE_CHANGED, GST_MESSAGE_UNKNOWN);
106 s = "fakesrc can-activate-push=false num-buffers=10 ! fakesink can-activate-pull=true";
107 run_pipeline (setup_pipeline (s), s,
108 GST_MESSAGE_NEW_CLOCK | GST_MESSAGE_STATE_CHANGED, GST_MESSAGE_EOS);
110 s = "fakesrc can-activate-push=true num-buffers=10 ! fakesink can-activate-pull=false";
111 run_pipeline (setup_pipeline (s), s,
112 GST_MESSAGE_NEW_CLOCK | GST_MESSAGE_STATE_CHANGED, GST_MESSAGE_EOS);
114 s = "fakesrc can-activate-push=false ! fakesink can-activate-pull=false";
115 ASSERT_CRITICAL (run_pipeline (setup_pipeline (s), s,
116 GST_MESSAGE_NEW_CLOCK | GST_MESSAGE_STATE_CHANGED,
117 GST_MESSAGE_UNKNOWN));
123 got_handoff (GstElement * sink, GstBuffer * buf, GstPad * pad, gpointer unused)
125 gst_element_post_message
126 (sink, gst_message_new_application (NULL, gst_structure_new ("foo",
131 assert_live_count (GType type, gint live)
133 GstAllocTrace *trace;
136 if (gst_alloc_trace_available ()) {
137 name = g_type_name (type);
139 trace = gst_alloc_trace_get (name);
141 g_return_if_fail (trace->live == live);
144 g_print ("\nSkipping live count tests; recompile with traces to enable\n");
148 GST_START_TEST (test_stop_from_app)
150 GstElement *fakesrc, *fakesink, *pipeline;
152 GstMessageType revent;
155 assert_live_count (GST_TYPE_BUFFER, 0);
157 fakesrc = gst_element_factory_make ("fakesrc", NULL);
158 fakesink = gst_element_factory_make ("fakesink", NULL);
159 pipeline = gst_element_factory_make ("pipeline", NULL);
161 g_return_if_fail (fakesrc && fakesink && pipeline);
163 gst_bin_add_many (GST_BIN (pipeline), fakesrc, fakesink, NULL);
164 gst_element_link (fakesrc, fakesink);
166 g_object_set (fakesink, "signal-handoffs", (gboolean) TRUE, NULL);
167 g_signal_connect (fakesink, "handoff", G_CALLBACK (got_handoff), NULL);
169 gst_element_set_state (pipeline, GST_STATE_PLAYING);
171 bus = gst_element_get_bus (pipeline);
174 /* will time out after half a second */
175 message = gst_bus_poll (bus, GST_MESSAGE_APPLICATION, GST_SECOND / 2);
177 revent = GST_MESSAGE_TYPE (message);
178 gst_message_unref (message);
180 revent = GST_MESSAGE_UNKNOWN;
182 g_return_if_fail (revent == GST_MESSAGE_APPLICATION);
184 gst_element_set_state (pipeline, GST_STATE_NULL);
185 gst_object_unref (pipeline);
186 gst_object_unref (bus);
188 assert_live_count (GST_TYPE_BUFFER, 0);
191 simple_launch_lines_suite (void)
193 Suite *s = suite_create ("Pipelines");
194 TCase *tc_chain = tcase_create ("linear");
196 /* time out after 20s, not the default 3 */
197 tcase_set_timeout (tc_chain, 0);
199 suite_add_tcase (s, tc_chain);
200 tcase_add_test (tc_chain, test_2_elements);
201 tcase_add_test (tc_chain, test_stop_from_app);
206 main (int argc, char **argv)
210 Suite *s = simple_launch_lines_suite ();
211 SRunner *sr = srunner_create (s);
213 gst_check_init (&argc, &argv);
215 srunner_run_all (sr, CK_NORMAL);
216 nf = srunner_ntests_failed (sr);