5 * Copyright (C) <2005> Jan Schmidt <thaytan at mad dot scientist 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.
24 #include <sys/types.h>
28 #include <gst/check/gstcheck.h>
30 gboolean have_eos = FALSE;
34 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
40 event_func (GstPad * pad, GstEvent * event)
42 if (GST_EVENT_TYPE (event) == GST_EVENT_EOS) {
44 gst_event_unref (event);
48 gst_event_unref (event);
57 GST_DEBUG ("setup_fdsrc");
58 fdsrc = gst_check_setup_element ("fdsrc");
59 mysinkpad = gst_check_setup_sink_pad (fdsrc, &sinktemplate, NULL);
60 gst_pad_set_event_function (mysinkpad, event_func);
61 gst_pad_set_active (mysinkpad, TRUE);
66 cleanup_fdsrc (GstElement * fdsrc)
68 gst_pad_set_active (mysinkpad, FALSE);
69 gst_check_teardown_sink_pad (fdsrc);
70 gst_check_teardown_element (fdsrc);
73 GST_START_TEST (test_num_buffers)
79 fail_if (pipe (pipe_fd) < 0);
82 g_object_set (G_OBJECT (src), "num-buffers", 3, NULL);
83 g_object_set (G_OBJECT (src), "fd", pipe_fd[0], NULL);
84 fail_unless (gst_element_set_state (src,
85 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
86 "could not set to playing");
88 memset (data, 0, 4096);
90 fail_if (write (pipe_fd[1], data, 4096) < 0);
94 fail_unless (g_list_length (buffers) == 3);
95 fail_unless (gst_element_set_state (src,
96 GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null");
102 g_list_foreach (buffers, (GFunc) gst_mini_object_unref, NULL);
103 g_list_free (buffers);
108 GST_START_TEST (test_nonseeking)
111 GstQuery *seeking_query;
116 fail_if (pipe (pipe_fd) < 0);
118 src = setup_fdsrc ();
119 g_object_set (G_OBJECT (src), "num-buffers", 3, NULL);
120 g_object_set (G_OBJECT (src), "fd", pipe_fd[0], NULL);
121 fail_unless (gst_element_set_state (src,
122 GST_STATE_PAUSED) == GST_STATE_CHANGE_SUCCESS,
123 "could not set to paused");
125 memset (data, 0, 4096);
126 fail_if (write (pipe_fd[1], data, 4096) < 0);
128 /* Test that fdsrc is non-seekable with a pipe */
129 fail_unless ((seeking_query = gst_query_new_seeking (GST_FORMAT_BYTES))
131 fail_unless (gst_element_query (src, seeking_query) == TRUE);
132 gst_query_parse_seeking (seeking_query, NULL, &seekable, NULL, NULL);
133 fail_unless (seekable == FALSE);
134 gst_query_unref (seeking_query);
136 fail_unless (gst_element_set_state (src,
137 GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null");
147 GST_START_TEST (test_seeking)
151 GstQuery *seeking_query;
155 #error TESTFILE not defined
157 fail_if ((in_fd = open (TESTFILE, O_RDONLY)) < 0);
158 src = setup_fdsrc ();
160 g_object_set (G_OBJECT (src), "fd", in_fd, NULL);
161 fail_unless (gst_element_set_state (src,
162 GST_STATE_PAUSED) == GST_STATE_CHANGE_SUCCESS,
163 "could not set to paused");
165 /* Test that fdsrc is seekable with a file fd */
166 fail_unless ((seeking_query = gst_query_new_seeking (GST_FORMAT_BYTES))
168 fail_unless (gst_element_query (src, seeking_query) == TRUE);
169 gst_query_parse_seeking (seeking_query, NULL, &seekable, NULL, NULL);
170 fail_unless (seekable == TRUE);
171 gst_query_unref (seeking_query);
173 fail_unless (gst_element_set_state (src,
174 GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null");
186 Suite *s = suite_create ("fdsrc");
187 TCase *tc_chain = tcase_create ("general");
189 suite_add_tcase (s, tc_chain);
190 tcase_add_test (tc_chain, test_num_buffers);
191 tcase_add_test (tc_chain, test_nonseeking);
192 tcase_add_test (tc_chain, test_seeking);
197 GST_CHECK_MAIN (fdsrc);