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);
63 cleanup_fakesrc (GstElement * fakesrc)
65 gst_pad_set_active (mysinkpad, FALSE);
66 gst_check_teardown_sink_pad (fakesrc);
67 gst_check_teardown_element (fakesrc);
70 GST_START_TEST (test_num_buffers)
74 src = setup_fakesrc ();
75 g_object_set (G_OBJECT (src), "num-buffers", 3, NULL);
76 fail_unless (gst_element_set_state (src,
77 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
78 "could not set to playing");
84 fail_unless (g_list_length (buffers) == 3);
85 gst_check_drop_buffers ();
87 fail_unless (gst_element_set_state (src,
88 GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null");
91 cleanup_fakesrc (src);
96 GST_START_TEST (test_sizetype_empty)
101 src = setup_fakesrc ();
103 g_object_set (G_OBJECT (src), "sizetype", 1, NULL);
104 g_object_set (G_OBJECT (src), "num-buffers", 100, NULL);
106 fail_unless (gst_element_set_state (src,
107 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
108 "could not set to playing");
114 fail_unless (g_list_length (buffers) == 100);
117 GstBuffer *buf = l->data;
119 fail_unless (GST_BUFFER_SIZE (buf) == 0);
122 gst_check_drop_buffers ();
124 fail_unless (gst_element_set_state (src,
125 GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null");
128 cleanup_fakesrc (src);
133 GST_START_TEST (test_sizetype_fixed)
138 src = setup_fakesrc ();
140 g_object_set (G_OBJECT (src), "sizetype", 2, NULL);
141 g_object_set (G_OBJECT (src), "sizemax", 8192, NULL);
142 g_object_set (G_OBJECT (src), "num-buffers", 100, NULL);
144 fail_unless (gst_element_set_state (src,
145 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
146 "could not set to playing");
152 fail_unless (g_list_length (buffers) == 100);
155 GstBuffer *buf = l->data;
157 fail_unless (GST_BUFFER_SIZE (buf) == 8192);
160 gst_check_drop_buffers ();
162 fail_unless (gst_element_set_state (src,
163 GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null");
166 cleanup_fakesrc (src);
171 GST_START_TEST (test_sizetype_random)
176 src = setup_fakesrc ();
178 g_object_set (G_OBJECT (src), "sizetype", 3, NULL);
179 g_object_set (G_OBJECT (src), "sizemin", 4096, NULL);
180 g_object_set (G_OBJECT (src), "sizemax", 8192, NULL);
181 g_object_set (G_OBJECT (src), "num-buffers", 100, NULL);
183 fail_unless (gst_element_set_state (src,
184 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
185 "could not set to playing");
191 fail_unless (g_list_length (buffers) == 100);
194 GstBuffer *buf = l->data;
196 fail_if (GST_BUFFER_SIZE (buf) > 8192);
197 fail_if (GST_BUFFER_SIZE (buf) < 4096);
200 gst_check_drop_buffers ();
202 fail_unless (gst_element_set_state (src,
203 GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null");
206 cleanup_fakesrc (src);
211 GST_START_TEST (test_no_preroll)
214 GstStateChangeReturn ret;
216 src = setup_fakesrc ();
218 g_object_set (G_OBJECT (src), "is-live", TRUE, NULL);
220 ret = gst_element_set_state (src, GST_STATE_PAUSED);
222 fail_unless (ret == GST_STATE_CHANGE_NO_PREROLL,
223 "error going to paused the first time");
225 ret = gst_element_set_state (src, GST_STATE_PAUSED);
227 fail_unless (ret == GST_STATE_CHANGE_NO_PREROLL,
228 "error going to paused the second time");
230 fail_unless (gst_element_set_state (src,
231 GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null");
234 cleanup_fakesrc (src);
242 Suite *s = suite_create ("fakesrc");
243 TCase *tc_chain = tcase_create ("general");
245 suite_add_tcase (s, tc_chain);
246 tcase_add_test (tc_chain, test_num_buffers);
247 tcase_add_test (tc_chain, test_sizetype_empty);
248 tcase_add_test (tc_chain, test_sizetype_fixed);
249 tcase_add_test (tc_chain, test_sizetype_random);
250 tcase_add_test (tc_chain, test_no_preroll);
255 GST_CHECK_MAIN (fakesrc);