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 fail_unless (ret == GST_STATE_SUCCESS, "no success state return");
72 ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
73 fail_unless (ret == GST_STATE_SUCCESS, "cannot start play");
75 ret = gst_element_get_state (pipeline, ¤t, &pending, NULL);
76 fail_unless (ret == GST_STATE_SUCCESS, "not playing");
77 fail_unless (current == GST_STATE_PLAYING, "not playing");
78 fail_unless (pending == GST_STATE_VOID_PENDING, "not playing");
82 /* a pipeline with live source should return NO_PREROLL in
83 * PAUSE. When removing the live source it should return ASYNC
85 START_TEST (test_livesrc_remove)
87 GstElement *sink, *src, *pipeline;
88 GstElementStateReturn ret;
89 GstElementState current, pending;
90 GstPad *srcpad, *sinkpad;
93 pipeline = gst_pipeline_new ("pipeline");
94 src = gst_element_factory_make ("fakesrc", "src");
95 g_object_set (G_OBJECT (src), "is-live", TRUE, NULL);
96 sink = gst_element_factory_make ("fakesink", "sink");
98 gst_bin_add (GST_BIN (pipeline), src);
99 gst_bin_add (GST_BIN (pipeline), sink);
101 srcpad = gst_element_get_pad (src, "src");
102 sinkpad = gst_element_get_pad (sink, "sink");
103 gst_pad_link (srcpad, sinkpad);
104 gst_object_unref (GST_OBJECT (srcpad));
105 gst_object_unref (GST_OBJECT (sinkpad));
107 ret = gst_element_set_state (pipeline, GST_STATE_PAUSED);
108 fail_unless (ret == GST_STATE_NO_PREROLL, "no no_preroll state return");
110 ret = gst_element_get_state (src, ¤t, &pending, NULL);
111 fail_unless (ret == GST_STATE_NO_PREROLL, "not paused");
112 fail_unless (current == GST_STATE_PAUSED, "not paused");
113 fail_unless (pending == GST_STATE_VOID_PENDING, "not playing");
115 gst_bin_remove (GST_BIN (pipeline), src);
117 GST_TIME_TO_TIMEVAL (0, tv);
118 ret = gst_element_get_state (pipeline, ¤t, &pending, &tv);
119 fail_unless (ret == GST_STATE_ASYNC, "not async");
120 fail_unless (current == GST_STATE_PAUSED, "not paused");
121 fail_unless (pending == GST_STATE_VOID_PENDING, "not playing");
126 /* a sink should go ASYNC to PAUSE. PAUSE does not complete
127 * since we have a live source. */
128 START_TEST (test_livesrc_sink)
130 GstElement *sink, *src, *pipeline;
131 GstElementStateReturn ret;
132 GstElementState current, pending;
133 GstPad *srcpad, *sinkpad;
135 pipeline = gst_pipeline_new ("pipeline");
136 src = gst_element_factory_make ("fakesrc", "src");
137 g_object_set (G_OBJECT (src), "is-live", TRUE, NULL);
138 sink = gst_element_factory_make ("fakesink", "sink");
140 gst_bin_add (GST_BIN (pipeline), src);
141 gst_bin_add (GST_BIN (pipeline), sink);
143 srcpad = gst_element_get_pad (src, "src");
144 sinkpad = gst_element_get_pad (sink, "sink");
145 gst_pad_link (srcpad, sinkpad);
146 gst_object_unref (GST_OBJECT (srcpad));
147 gst_object_unref (GST_OBJECT (sinkpad));
149 ret = gst_element_set_state (pipeline, GST_STATE_PAUSED);
150 fail_unless (ret == GST_STATE_NO_PREROLL, "no no_preroll state return");
152 ret = gst_element_get_state (src, ¤t, &pending, NULL);
153 fail_unless (ret == GST_STATE_NO_PREROLL, "not paused");
154 fail_unless (current == GST_STATE_PAUSED, "not paused");
155 fail_unless (pending == GST_STATE_VOID_PENDING, "not playing");
157 ret = gst_element_get_state (pipeline, ¤t, &pending, NULL);
158 fail_unless (ret == GST_STATE_NO_PREROLL, "not paused");
159 fail_unless (current == GST_STATE_PAUSED, "not paused");
160 fail_unless (pending == GST_STATE_VOID_PENDING, "not playing");
162 ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
163 fail_unless (ret == GST_STATE_SUCCESS, "cannot force play");
165 ret = gst_element_get_state (pipeline, ¤t, &pending, NULL);
166 fail_unless (ret == GST_STATE_SUCCESS, "not playing");
167 fail_unless (current == GST_STATE_PLAYING, "not playing");
168 fail_unless (pending == GST_STATE_VOID_PENDING, "not playing");
172 /* test: try changing state of sinks */
173 Suite * gst_object_suite (void)
175 Suite *s = suite_create ("Sinks");
176 TCase *tc_chain = tcase_create ("general");
178 /* turn off timeout */
179 tcase_set_timeout (tc_chain, 60);
181 suite_add_tcase (s, tc_chain);
182 tcase_add_test (tc_chain, test_sink);
183 tcase_add_test (tc_chain, test_src_sink);
184 tcase_add_test (tc_chain, test_livesrc_remove);
185 tcase_add_test (tc_chain, test_livesrc_sink);
191 main (int argc, char **argv)
195 Suite *s = gst_object_suite ();
196 SRunner *sr = srunner_create (s);
198 gst_check_init (&argc, &argv);
200 srunner_run_all (sr, CK_NORMAL);
201 nf = srunner_ntests_failed (sr);