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 GList *buffers = NULL;
28 gboolean have_eos = FALSE;
30 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
36 chain_func (GstPad * pad, GstBuffer * buffer)
38 buffers = g_list_append (buffers, buffer);
44 event_func (GstPad * pad, GstEvent * event)
46 if (GST_EVENT_TYPE (event) == GST_EVENT_EOS) {
47 /* we take the lock here because it's good practice to so, even though
48 * no buffers will be pushed anymore anyway */
49 GST_STREAM_LOCK (pad);
51 GST_STREAM_UNLOCK (pad);
52 gst_event_unref (event);
56 gst_event_unref (event);
64 GstPad *srcpad, *sinkpad;
66 src = gst_element_factory_make ("fakesrc", "src");
67 fail_if (src == NULL, "Could not create a fakesrc");
70 gst_pad_new_from_template (gst_static_pad_template_get (&sinktemplate),
72 fail_if (sinkpad == NULL, "Could not create a sinkpad");
74 srcpad = gst_element_get_pad (src, "src");
75 fail_if (srcpad == NULL, "Could not get source pad from fakesrc");
76 gst_pad_set_caps (sinkpad, NULL);
77 gst_pad_set_chain_function (sinkpad, chain_func);
78 gst_pad_set_event_function (sinkpad, event_func);
80 fail_unless (gst_pad_link (srcpad, sinkpad) == GST_PAD_LINK_OK,
81 "Could not link source and sink pads");
86 cleanup_fakesrc (GstElement * src)
88 GstPad *srcpad, *sinkpad;
90 fail_unless (gst_element_set_state (src, GST_STATE_NULL) == GST_STATE_SUCCESS,
91 "could not set to null");
93 srcpad = gst_element_get_pad (src, "src");
94 sinkpad = gst_pad_get_peer (srcpad);
96 ASSERT_OBJECT_REFCOUNT (src, "src", 1);
97 gst_object_unref (src);
99 gst_pad_unlink (srcpad, sinkpad);
101 /* pad refs held by both creator and this function (through _get) */
102 ASSERT_OBJECT_REFCOUNT (srcpad, "srcpad", 2);
103 gst_object_unref (srcpad);
104 gst_object_unref (srcpad);
106 ASSERT_OBJECT_REFCOUNT (sinkpad, "sinkpad", 2);
107 gst_object_unref (sinkpad);
108 gst_object_unref (sinkpad);
111 GST_START_TEST (test_num_buffers)
115 src = setup_fakesrc ();
116 g_object_set (G_OBJECT (src), "num-buffers", 3, NULL);
117 fail_unless (gst_element_set_state (src,
118 GST_STATE_PLAYING) == GST_STATE_SUCCESS, "could not set to playing");
124 fail_unless (g_list_length (buffers) == 3);
125 g_list_foreach (buffers, (GFunc) gst_mini_object_unref, NULL);
126 g_list_free (buffers);
129 cleanup_fakesrc (src);
134 GST_START_TEST (test_sizetype_empty)
139 src = setup_fakesrc ();
141 g_object_set (G_OBJECT (src), "sizetype", 1, 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_SUCCESS, "could not set to playing");
151 fail_unless (g_list_length (buffers) == 100);
154 GstBuffer *buf = l->data;
156 fail_unless (GST_BUFFER_SIZE (buf) == 0);
159 g_list_foreach (buffers, (GFunc) gst_mini_object_unref, NULL);
160 g_list_free (buffers);
163 cleanup_fakesrc (src);
168 GST_START_TEST (test_sizetype_fixed)
173 src = setup_fakesrc ();
175 g_object_set (G_OBJECT (src), "sizetype", 2, NULL);
176 g_object_set (G_OBJECT (src), "sizemax", 8192, NULL);
177 g_object_set (G_OBJECT (src), "num-buffers", 100, NULL);
179 fail_unless (gst_element_set_state (src,
180 GST_STATE_PLAYING) == GST_STATE_SUCCESS, "could not set to playing");
186 fail_unless (g_list_length (buffers) == 100);
189 GstBuffer *buf = l->data;
191 fail_unless (GST_BUFFER_SIZE (buf) == 8192);
194 g_list_foreach (buffers, (GFunc) gst_mini_object_unref, NULL);
195 g_list_free (buffers);
198 cleanup_fakesrc (src);
203 GST_START_TEST (test_sizetype_random)
208 src = setup_fakesrc ();
210 g_object_set (G_OBJECT (src), "sizetype", 3, NULL);
211 g_object_set (G_OBJECT (src), "sizemin", 4096, NULL);
212 g_object_set (G_OBJECT (src), "sizemax", 8192, NULL);
213 g_object_set (G_OBJECT (src), "num-buffers", 100, NULL);
215 fail_unless (gst_element_set_state (src,
216 GST_STATE_PLAYING) == GST_STATE_SUCCESS, "could not set to playing");
222 fail_unless (g_list_length (buffers) == 100);
225 GstBuffer *buf = l->data;
227 fail_if (GST_BUFFER_SIZE (buf) > 8192);
228 fail_if (GST_BUFFER_SIZE (buf) < 4096);
231 g_list_foreach (buffers, (GFunc) gst_mini_object_unref, NULL);
232 g_list_free (buffers);
235 cleanup_fakesrc (src);
244 Suite *s = suite_create ("fakesrc");
245 TCase *tc_chain = tcase_create ("general");
247 suite_add_tcase (s, tc_chain);
248 tcase_add_test (tc_chain, test_num_buffers);
249 tcase_add_test (tc_chain, test_sizetype_empty);
250 tcase_add_test (tc_chain, test_sizetype_fixed);
251 tcase_add_test (tc_chain, test_sizetype_random);
257 main (int argc, char **argv)
261 Suite *s = fakesrc_suite ();
262 SRunner *sr = srunner_create (s);
264 gst_check_init (&argc, &argv);
266 srunner_run_all (sr, CK_NORMAL);
267 nf = srunner_ntests_failed (sr);