3 * unit test for fakesrc
5 * Copyright (C) <2005> Thomas Vander Stichele <thomas at apestaart dot org>
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.
25 #include <gst/check/gstcheck.h>
27 static gboolean have_eos = FALSE;
29 static GstPad *mysinkpad;
31 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
37 event_func (GstPad * pad, GstEvent * event)
39 if (GST_EVENT_TYPE (event) == GST_EVENT_EOS) {
41 gst_event_unref (event);
45 gst_event_unref (event);
54 GST_DEBUG ("setup_fakesrc");
55 fakesrc = gst_check_setup_element ("fakesrc");
56 mysinkpad = gst_check_setup_sink_pad (fakesrc, &sinktemplate, NULL);
57 gst_pad_set_event_function (mysinkpad, event_func);
58 gst_pad_set_active (mysinkpad, TRUE);
64 cleanup_fakesrc (GstElement * fakesrc)
66 gst_pad_set_active (mysinkpad, FALSE);
67 gst_check_teardown_sink_pad (fakesrc);
68 gst_check_teardown_element (fakesrc);
71 GST_START_TEST (test_num_buffers)
75 src = setup_fakesrc ();
76 g_object_set (G_OBJECT (src), "num-buffers", 3, NULL);
77 fail_unless (gst_element_set_state (src,
78 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
79 "could not set to playing");
85 fail_unless_equals_int (g_list_length (buffers), 3);
86 gst_check_drop_buffers ();
88 fail_unless (gst_element_set_state (src,
89 GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null");
92 cleanup_fakesrc (src);
97 GST_START_TEST (test_sizetype_empty)
102 src = setup_fakesrc ();
104 g_object_set (G_OBJECT (src), "sizetype", 1, NULL);
105 g_object_set (G_OBJECT (src), "num-buffers", 100, NULL);
107 fail_unless (gst_element_set_state (src,
108 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
109 "could not set to playing");
115 fail_unless_equals_int (g_list_length (buffers), 100);
118 GstBuffer *buf = l->data;
120 fail_unless (GST_BUFFER_SIZE (buf) == 0);
123 gst_check_drop_buffers ();
125 fail_unless (gst_element_set_state (src,
126 GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null");
129 cleanup_fakesrc (src);
134 GST_START_TEST (test_sizetype_fixed)
139 src = setup_fakesrc ();
141 g_object_set (G_OBJECT (src), "sizetype", 2, NULL);
142 g_object_set (G_OBJECT (src), "sizemax", 8192, NULL);
143 g_object_set (G_OBJECT (src), "num-buffers", 100, NULL);
145 fail_unless (gst_element_set_state (src,
146 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
147 "could not set to playing");
153 fail_unless (g_list_length (buffers) == 100);
156 GstBuffer *buf = l->data;
158 fail_unless (GST_BUFFER_SIZE (buf) == 8192);
161 gst_check_drop_buffers ();
163 fail_unless (gst_element_set_state (src,
164 GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null");
167 cleanup_fakesrc (src);
172 GST_START_TEST (test_sizetype_random)
177 src = setup_fakesrc ();
179 g_object_set (G_OBJECT (src), "sizetype", 3, NULL);
180 g_object_set (G_OBJECT (src), "sizemin", 4096, NULL);
181 g_object_set (G_OBJECT (src), "sizemax", 8192, NULL);
182 g_object_set (G_OBJECT (src), "num-buffers", 100, NULL);
184 fail_unless (gst_element_set_state (src,
185 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
186 "could not set to playing");
192 fail_unless (g_list_length (buffers) == 100);
195 GstBuffer *buf = l->data;
197 fail_if (GST_BUFFER_SIZE (buf) > 8192);
198 fail_if (GST_BUFFER_SIZE (buf) < 4096);
201 gst_check_drop_buffers ();
203 fail_unless (gst_element_set_state (src,
204 GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null");
207 cleanup_fakesrc (src);
212 GST_START_TEST (test_no_preroll)
215 GstStateChangeReturn ret;
217 src = setup_fakesrc ();
219 g_object_set (G_OBJECT (src), "is-live", TRUE, NULL);
221 ret = gst_element_set_state (src, GST_STATE_PAUSED);
223 fail_unless (ret == GST_STATE_CHANGE_NO_PREROLL,
224 "error going to paused the first time");
226 ret = gst_element_set_state (src, GST_STATE_PAUSED);
228 fail_unless (ret == GST_STATE_CHANGE_NO_PREROLL,
229 "error going to paused the second time");
231 fail_unless (gst_element_set_state (src,
232 GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null");
235 cleanup_fakesrc (src);
243 Suite *s = suite_create ("fakesrc");
244 TCase *tc_chain = tcase_create ("general");
246 suite_add_tcase (s, tc_chain);
247 tcase_add_test (tc_chain, test_num_buffers);
248 tcase_add_test (tc_chain, test_sizetype_empty);
249 tcase_add_test (tc_chain, test_sizetype_fixed);
250 tcase_add_test (tc_chain, test_sizetype_random);
251 tcase_add_test (tc_chain, test_no_preroll);
256 GST_CHECK_MAIN (fakesrc);