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 "../gstcheck.h"
25 /* a sink should go ASYNC to PAUSE. forcing PLAYING is possible */
26 START_TEST (test_sink)
29 GstElementStateReturn ret;
30 GstElementState current, pending;
32 sink = gst_element_factory_make ("fakesink", "sink");
34 ret = gst_element_set_state (sink, GST_STATE_PAUSED);
35 fail_unless (ret == GST_STATE_ASYNC, "no async state return");
37 ret = gst_element_set_state (sink, GST_STATE_PLAYING);
38 fail_unless (ret == GST_STATE_SUCCESS, "cannot force play");
40 ret = gst_element_get_state (sink, ¤t, &pending, NULL);
41 fail_unless (ret == GST_STATE_SUCCESS, "not playing");
42 fail_unless (current == GST_STATE_PLAYING, "not playing");
43 fail_unless (pending == GST_STATE_VOID_PENDING, "not playing");
47 /* a sink should go ASYNC to PAUSE. PAUSE should complete when
49 START_TEST (test_src_sink)
51 GstElement *sink, *src, *pipeline;
52 GstElementStateReturn ret;
53 GstElementState current, pending;
54 GstPad *srcpad, *sinkpad;
56 pipeline = gst_pipeline_new ("pipeline");
57 src = gst_element_factory_make ("fakesrc", "src");
58 sink = gst_element_factory_make ("fakesink", "sink");
60 gst_bin_add (GST_BIN (pipeline), src);
61 gst_bin_add (GST_BIN (pipeline), sink);
63 srcpad = gst_element_get_pad (src, "src");
64 sinkpad = gst_element_get_pad (sink, "sink");
65 gst_pad_link (srcpad, sinkpad);
66 gst_object_unref (GST_OBJECT (srcpad));
67 gst_object_unref (GST_OBJECT (sinkpad));
69 ret = gst_element_set_state (pipeline, GST_STATE_PAUSED);
70 ret = gst_element_get_state (pipeline, NULL, NULL, NULL);
71 fail_unless (ret == GST_STATE_SUCCESS, "no success state return");
73 ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
74 fail_unless (ret == GST_STATE_SUCCESS, "cannot start play");
76 ret = gst_element_get_state (pipeline, ¤t, &pending, NULL);
77 fail_unless (ret == GST_STATE_SUCCESS, "not playing");
78 fail_unless (current == GST_STATE_PLAYING, "not playing");
79 fail_unless (pending == GST_STATE_VOID_PENDING, "not playing");
83 /* a pipeline with live source should return NO_PREROLL in
84 * PAUSE. When removing the live source it should return ASYNC
86 START_TEST (test_livesrc_remove)
88 GstElement *sink, *src, *pipeline;
89 GstElementStateReturn ret;
90 GstElementState current, pending;
91 GstPad *srcpad, *sinkpad;
94 pipeline = gst_pipeline_new ("pipeline");
95 src = gst_element_factory_make ("fakesrc", "src");
96 g_object_set (G_OBJECT (src), "is-live", TRUE, NULL);
97 sink = gst_element_factory_make ("fakesink", "sink");
99 gst_bin_add (GST_BIN (pipeline), src);
100 gst_bin_add (GST_BIN (pipeline), sink);
102 srcpad = gst_element_get_pad (src, "src");
103 sinkpad = gst_element_get_pad (sink, "sink");
104 gst_pad_link (srcpad, sinkpad);
105 gst_object_unref (GST_OBJECT (srcpad));
106 gst_object_unref (GST_OBJECT (sinkpad));
108 ret = gst_element_set_state (pipeline, GST_STATE_PAUSED);
109 fail_unless (ret == GST_STATE_NO_PREROLL, "no no_preroll state return");
111 ret = gst_element_get_state (src, ¤t, &pending, NULL);
112 fail_unless (ret == GST_STATE_NO_PREROLL, "not paused");
113 fail_unless (current == GST_STATE_PAUSED, "not paused");
114 fail_unless (pending == GST_STATE_VOID_PENDING, "not playing");
116 gst_bin_remove (GST_BIN (pipeline), src);
118 GST_TIME_TO_TIMEVAL (0, tv);
119 ret = gst_element_get_state (pipeline, ¤t, &pending, &tv);
120 fail_unless (ret == GST_STATE_ASYNC, "not async");
121 fail_unless (current == GST_STATE_PAUSED, "not paused");
122 fail_unless (pending == GST_STATE_VOID_PENDING, "not playing");
127 /* a sink should go ASYNC to PAUSE. PAUSE does not complete
128 * since we have a live source. */
129 START_TEST (test_livesrc_sink)
131 GstElement *sink, *src, *pipeline;
132 GstElementStateReturn ret;
133 GstElementState current, pending;
134 GstPad *srcpad, *sinkpad;
136 pipeline = gst_pipeline_new ("pipeline");
137 src = gst_element_factory_make ("fakesrc", "src");
138 g_object_set (G_OBJECT (src), "is-live", TRUE, NULL);
139 sink = gst_element_factory_make ("fakesink", "sink");
141 gst_bin_add (GST_BIN (pipeline), src);
142 gst_bin_add (GST_BIN (pipeline), sink);
144 srcpad = gst_element_get_pad (src, "src");
145 sinkpad = gst_element_get_pad (sink, "sink");
146 gst_pad_link (srcpad, sinkpad);
147 gst_object_unref (GST_OBJECT (srcpad));
148 gst_object_unref (GST_OBJECT (sinkpad));
150 ret = gst_element_set_state (pipeline, GST_STATE_PAUSED);
151 fail_unless (ret == GST_STATE_NO_PREROLL, "no no_preroll state return");
153 ret = gst_element_get_state (src, ¤t, &pending, NULL);
154 fail_unless (ret == GST_STATE_NO_PREROLL, "not paused");
155 fail_unless (current == GST_STATE_PAUSED, "not paused");
156 fail_unless (pending == GST_STATE_VOID_PENDING, "not playing");
158 ret = gst_element_get_state (pipeline, ¤t, &pending, NULL);
159 fail_unless (ret == GST_STATE_NO_PREROLL, "not paused");
160 fail_unless (current == GST_STATE_PAUSED, "not paused");
161 fail_unless (pending == GST_STATE_VOID_PENDING, "not playing");
163 ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
164 fail_unless (ret == GST_STATE_SUCCESS, "cannot force play");
166 ret = gst_element_get_state (pipeline, ¤t, &pending, NULL);
167 fail_unless (ret == GST_STATE_SUCCESS, "not playing");
168 fail_unless (current == GST_STATE_PLAYING, "not playing");
169 fail_unless (pending == GST_STATE_VOID_PENDING, "not playing");
173 /* test: try changing state of sinks */
174 Suite * gst_object_suite (void)
176 Suite *s = suite_create ("Sinks");
177 TCase *tc_chain = tcase_create ("general");
179 /* turn off timeout */
180 tcase_set_timeout (tc_chain, 60);
182 suite_add_tcase (s, tc_chain);
183 tcase_add_test (tc_chain, test_sink);
184 tcase_add_test (tc_chain, test_src_sink);
185 tcase_add_test (tc_chain, test_livesrc_remove);
186 tcase_add_test (tc_chain, test_livesrc_sink);
192 main (int argc, char **argv)
196 Suite *s = gst_object_suite ();
197 SRunner *sr = srunner_create (s);
199 gst_check_init (&argc, &argv);
201 srunner_run_all (sr, CK_NORMAL);
202 nf = srunner_ntests_failed (sr);