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_PAUSED, "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 gst_object_unref (sink);
58 /* a sink should go ASYNC to PAUSE. PAUSE should complete when
60 GST_START_TEST (test_src_sink)
62 GstElement *sink, *src, *pipeline;
63 GstStateChangeReturn ret;
64 GstState current, pending;
65 GstPad *srcpad, *sinkpad;
67 pipeline = gst_pipeline_new ("pipeline");
68 src = gst_element_factory_make ("fakesrc", "src");
69 sink = gst_element_factory_make ("fakesink", "sink");
71 gst_bin_add (GST_BIN (pipeline), src);
72 gst_bin_add (GST_BIN (pipeline), sink);
74 srcpad = gst_element_get_pad (src, "src");
75 sinkpad = gst_element_get_pad (sink, "sink");
76 gst_pad_link (srcpad, sinkpad);
77 gst_object_unref (srcpad);
78 gst_object_unref (sinkpad);
80 ret = gst_element_set_state (pipeline, GST_STATE_PAUSED);
81 ret = gst_element_get_state (pipeline, NULL, NULL, NULL);
82 fail_unless (ret == GST_STATE_CHANGE_SUCCESS, "no success state return");
84 ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
85 fail_unless (ret == GST_STATE_CHANGE_SUCCESS, "cannot start play");
87 ret = gst_element_get_state (pipeline, ¤t, &pending, NULL);
88 fail_unless (ret == GST_STATE_CHANGE_SUCCESS, "not playing");
89 fail_unless (current == GST_STATE_PLAYING, "not playing");
90 fail_unless (pending == GST_STATE_VOID_PENDING, "not playing");
94 /* a pipeline with live source should return NO_PREROLL in
95 * PAUSE. When removing the live source it should return ASYNC
97 GST_START_TEST (test_livesrc_remove)
99 GstElement *sink, *src, *pipeline;
100 GstStateChangeReturn ret;
101 GstState current, pending;
102 GstPad *srcpad, *sinkpad;
105 pipeline = gst_pipeline_new ("pipeline");
106 src = gst_element_factory_make ("fakesrc", "src");
107 g_object_set (G_OBJECT (src), "is-live", TRUE, NULL);
108 sink = gst_element_factory_make ("fakesink", "sink");
110 gst_bin_add (GST_BIN (pipeline), src);
111 gst_bin_add (GST_BIN (pipeline), sink);
113 srcpad = gst_element_get_pad (src, "src");
114 sinkpad = gst_element_get_pad (sink, "sink");
115 gst_pad_link (srcpad, sinkpad);
116 gst_object_unref (srcpad);
117 gst_object_unref (sinkpad);
119 ret = gst_element_set_state (pipeline, GST_STATE_PAUSED);
120 fail_unless (ret == GST_STATE_CHANGE_NO_PREROLL,
121 "no no_preroll state return");
123 ret = gst_element_get_state (src, ¤t, &pending, NULL);
124 fail_unless (ret == GST_STATE_CHANGE_NO_PREROLL, "not paused");
125 fail_unless (current == GST_STATE_PAUSED, "not paused");
126 fail_unless (pending == GST_STATE_VOID_PENDING, "not playing");
128 gst_bin_remove (GST_BIN (pipeline), src);
130 GST_TIME_TO_TIMEVAL (0, tv);
131 ret = gst_element_get_state (pipeline, ¤t, &pending, &tv);
132 fail_unless (ret == GST_STATE_CHANGE_ASYNC, "not async");
133 fail_unless (current == GST_STATE_PAUSED, "not paused");
134 fail_unless (pending == GST_STATE_VOID_PENDING, "not playing");
139 /* a sink should go ASYNC to PAUSE. PAUSE does not complete
140 * since we have a live source. */
141 GST_START_TEST (test_livesrc_sink)
143 GstElement *sink, *src, *pipeline;
144 GstStateChangeReturn ret;
145 GstState current, pending;
146 GstPad *srcpad, *sinkpad;
148 pipeline = gst_pipeline_new ("pipeline");
149 src = gst_element_factory_make ("fakesrc", "src");
150 g_object_set (G_OBJECT (src), "is-live", TRUE, NULL);
151 sink = gst_element_factory_make ("fakesink", "sink");
153 gst_bin_add (GST_BIN (pipeline), src);
154 gst_bin_add (GST_BIN (pipeline), sink);
156 srcpad = gst_element_get_pad (src, "src");
157 sinkpad = gst_element_get_pad (sink, "sink");
158 gst_pad_link (srcpad, sinkpad);
159 gst_object_unref (srcpad);
160 gst_object_unref (sinkpad);
162 ret = gst_element_set_state (pipeline, GST_STATE_PAUSED);
163 fail_unless (ret == GST_STATE_CHANGE_NO_PREROLL,
164 "no no_preroll state return");
166 ret = gst_element_get_state (src, ¤t, &pending, NULL);
167 fail_unless (ret == GST_STATE_CHANGE_NO_PREROLL, "not paused");
168 fail_unless (current == GST_STATE_PAUSED, "not paused");
169 fail_unless (pending == GST_STATE_VOID_PENDING, "not playing");
171 ret = gst_element_get_state (pipeline, ¤t, &pending, NULL);
172 fail_unless (ret == GST_STATE_CHANGE_NO_PREROLL, "not paused");
173 fail_unless (current == GST_STATE_PAUSED, "not paused");
174 fail_unless (pending == GST_STATE_VOID_PENDING, "not playing");
176 ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
177 fail_unless (ret == GST_STATE_CHANGE_SUCCESS, "cannot force play");
179 ret = gst_element_get_state (pipeline, ¤t, &pending, NULL);
180 fail_unless (ret == GST_STATE_CHANGE_SUCCESS, "not playing");
181 fail_unless (current == GST_STATE_PLAYING, "not playing");
182 fail_unless (pending == GST_STATE_VOID_PENDING, "not playing");
188 /* test: try changing state of sinks */
190 gst_object_suite (void)
192 Suite *s = suite_create ("Sinks");
193 TCase *tc_chain = tcase_create ("general");
195 suite_add_tcase (s, tc_chain);
196 tcase_add_test (tc_chain, test_sink);
197 tcase_add_test (tc_chain, test_src_sink);
198 tcase_add_test (tc_chain, test_livesrc_remove);
199 tcase_add_test (tc_chain, test_livesrc_sink);
205 main (int argc, char **argv)
209 Suite *s = gst_object_suite ();
210 SRunner *sr = srunner_create (s);
212 gst_check_init (&argc, &argv);
214 srunner_run_all (sr, CK_NORMAL);
215 nf = srunner_ntests_failed (sr);