5 * Copyright (C) <2005> Wim Taymans <wim at fluendo dot com>
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.
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.
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.
23 #include <gst/check/gstcheck.h>
25 /* a sink should go ASYNC to PAUSE. forcing PLAYING is possible */
26 GST_START_TEST (test_sink)
29 GstStateChangeReturn ret;
30 GstState current, pending;
33 sink = gst_element_factory_make ("fakesink", "sink");
35 ret = gst_element_set_state (sink, GST_STATE_PAUSED);
36 fail_unless (ret == GST_STATE_CHANGE_ASYNC, "no async state return");
38 ret = gst_element_set_state (sink, GST_STATE_PLAYING);
39 fail_unless (ret == GST_STATE_CHANGE_ASYNC, "no forced async state change");
41 GST_TIME_TO_TIMEVAL ((GstClockTime) 0, tv);
43 ret = gst_element_get_state (sink, ¤t, &pending, &tv);
44 fail_unless (ret == GST_STATE_CHANGE_ASYNC, "not changing state async");
45 fail_unless (current == GST_STATE_READY, "bad current state");
46 fail_unless (pending == GST_STATE_PLAYING, "bad pending state");
48 ret = gst_element_set_state (sink, GST_STATE_PAUSED);
49 fail_unless (ret == GST_STATE_CHANGE_ASYNC, "no async going back to paused");
51 ret = gst_element_set_state (sink, GST_STATE_READY);
52 fail_unless (ret == GST_STATE_CHANGE_SUCCESS, "failed to go to ready");
54 ret = gst_element_set_state (sink, GST_STATE_NULL);
55 fail_unless (ret == GST_STATE_CHANGE_SUCCESS, "failed to go to null");
57 gst_object_unref (sink);
61 /* a sink should go ASYNC to PAUSE. PAUSE should complete when
63 GST_START_TEST (test_src_sink)
65 GstElement *sink, *src, *pipeline;
66 GstStateChangeReturn ret;
67 GstState current, pending;
68 GstPad *srcpad, *sinkpad;
70 pipeline = gst_pipeline_new ("pipeline");
71 src = gst_element_factory_make ("fakesrc", "src");
72 sink = gst_element_factory_make ("fakesink", "sink");
74 gst_bin_add (GST_BIN (pipeline), src);
75 gst_bin_add (GST_BIN (pipeline), sink);
77 srcpad = gst_element_get_pad (src, "src");
78 sinkpad = gst_element_get_pad (sink, "sink");
79 gst_pad_link (srcpad, sinkpad);
80 gst_object_unref (srcpad);
81 gst_object_unref (sinkpad);
83 ret = gst_element_set_state (pipeline, GST_STATE_PAUSED);
84 fail_unless (ret == GST_STATE_CHANGE_ASYNC, "no async state return");
85 ret = gst_element_get_state (pipeline, NULL, NULL, NULL);
86 fail_unless (ret == GST_STATE_CHANGE_SUCCESS, "no success state return");
88 ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
89 fail_unless (ret == GST_STATE_CHANGE_SUCCESS, "cannot start play");
91 ret = gst_element_get_state (pipeline, ¤t, &pending, NULL);
92 fail_unless (ret == GST_STATE_CHANGE_SUCCESS, "not playing");
93 fail_unless (current == GST_STATE_PLAYING, "not playing");
94 fail_unless (pending == GST_STATE_VOID_PENDING, "not playing");
95 ret = gst_element_set_state (pipeline, GST_STATE_NULL);
96 fail_unless (ret == GST_STATE_CHANGE_SUCCESS, "cannot null pipeline");
98 gst_object_unref (pipeline);
103 /* a pipeline with live source should return NO_PREROLL in
104 * PAUSE. When removing the live source it should return ASYNC
106 GST_START_TEST (test_livesrc_remove)
108 GstElement *sink, *src, *pipeline;
109 GstStateChangeReturn ret;
110 GstState current, pending;
111 GstPad *srcpad, *sinkpad;
114 pipeline = gst_pipeline_new ("pipeline");
115 src = gst_element_factory_make ("fakesrc", "src");
116 g_object_set (G_OBJECT (src), "is-live", TRUE, NULL);
117 sink = gst_element_factory_make ("fakesink", "sink");
119 gst_bin_add (GST_BIN (pipeline), src);
120 gst_bin_add (GST_BIN (pipeline), sink);
122 srcpad = gst_element_get_pad (src, "src");
123 sinkpad = gst_element_get_pad (sink, "sink");
124 gst_pad_link (srcpad, sinkpad);
125 gst_object_unref (srcpad);
126 gst_object_unref (sinkpad);
128 ret = gst_element_set_state (pipeline, GST_STATE_PAUSED);
129 fail_unless (ret == GST_STATE_CHANGE_NO_PREROLL,
130 "no no_preroll state return");
132 ret = gst_element_get_state (src, ¤t, &pending, NULL);
133 fail_unless (ret == GST_STATE_CHANGE_NO_PREROLL, "not paused");
134 fail_unless (current == GST_STATE_PAUSED, "not paused");
135 fail_unless (pending == GST_STATE_VOID_PENDING, "not playing");
137 gst_bin_remove (GST_BIN (pipeline), src);
139 GST_TIME_TO_TIMEVAL (0, tv);
140 ret = gst_element_get_state (pipeline, ¤t, &pending, &tv);
141 fail_unless (ret == GST_STATE_CHANGE_ASYNC, "not async");
142 fail_unless (current == GST_STATE_PAUSED, "not paused");
143 fail_unless (pending == GST_STATE_PAUSED, "not paused");
147 /* a sink should go ASYNC to PAUSE. PAUSE does not complete
148 * since we have a live source. */
149 GST_START_TEST (test_livesrc_sink)
151 GstElement *sink, *src, *pipeline;
152 GstStateChangeReturn ret;
153 GstState current, pending;
154 GstPad *srcpad, *sinkpad;
156 pipeline = gst_pipeline_new ("pipeline");
157 src = gst_element_factory_make ("fakesrc", "src");
158 g_object_set (G_OBJECT (src), "is-live", TRUE, NULL);
159 sink = gst_element_factory_make ("fakesink", "sink");
161 gst_bin_add (GST_BIN (pipeline), src);
162 gst_bin_add (GST_BIN (pipeline), sink);
164 srcpad = gst_element_get_pad (src, "src");
165 sinkpad = gst_element_get_pad (sink, "sink");
166 gst_pad_link (srcpad, sinkpad);
167 gst_object_unref (srcpad);
168 gst_object_unref (sinkpad);
170 ret = gst_element_set_state (pipeline, GST_STATE_PAUSED);
171 fail_unless (ret == GST_STATE_CHANGE_NO_PREROLL,
172 "no no_preroll state return");
174 ret = gst_element_get_state (src, ¤t, &pending, NULL);
175 fail_unless (ret == GST_STATE_CHANGE_NO_PREROLL, "not paused");
176 fail_unless (current == GST_STATE_PAUSED, "not paused");
177 fail_unless (pending == GST_STATE_VOID_PENDING, "not playing");
179 ret = gst_element_get_state (pipeline, ¤t, &pending, NULL);
180 fail_unless (ret == GST_STATE_CHANGE_NO_PREROLL, "not paused");
181 fail_unless (current == GST_STATE_PAUSED, "not paused");
182 fail_unless (pending == GST_STATE_VOID_PENDING, "not playing");
184 ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
185 ret = gst_element_get_state (pipeline, NULL, NULL, NULL);
186 fail_unless (ret == GST_STATE_CHANGE_SUCCESS, "cannot force play got %d",
189 ret = gst_element_get_state (pipeline, ¤t, &pending, NULL);
190 fail_unless (ret == GST_STATE_CHANGE_SUCCESS, "not playing");
191 fail_unless (current == GST_STATE_PLAYING, "not playing");
192 fail_unless (pending == GST_STATE_VOID_PENDING, "not playing");
198 /* test: try changing state of sinks */
200 gst_object_suite (void)
202 Suite *s = suite_create ("Sinks");
203 TCase *tc_chain = tcase_create ("general");
205 suite_add_tcase (s, tc_chain);
206 tcase_add_test (tc_chain, test_sink);
207 tcase_add_test (tc_chain, test_src_sink);
208 tcase_add_test (tc_chain, test_livesrc_remove);
209 tcase_add_test (tc_chain, test_livesrc_sink);
215 main (int argc, char **argv)
219 Suite *s = gst_object_suite ();
220 SRunner *sr = srunner_create (s);
222 gst_check_init (&argc, &argv);
224 srunner_run_all (sr, CK_NORMAL);
225 nf = srunner_ntests_failed (sr);