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_check_teardown_sink_pad (fdsrc);
69 gst_check_teardown_element (fdsrc);
72 GST_START_TEST (test_num_buffers)
78 fail_if (pipe (pipe_fd) < 0);
81 g_object_set (G_OBJECT (src), "num-buffers", 3, NULL);
82 g_object_set (G_OBJECT (src), "fd", pipe_fd[0], NULL);
83 fail_unless (gst_element_set_state (src,
84 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
85 "could not set to playing");
87 memset (data, 0, 4096);
89 fail_if (write (pipe_fd[1], data, 4096) < 0);
93 fail_unless (g_list_length (buffers) == 3);
94 fail_unless (gst_element_set_state (src,
95 GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null");
101 g_list_foreach (buffers, (GFunc) gst_mini_object_unref, NULL);
102 g_list_free (buffers);
107 GST_START_TEST (test_nonseeking)
110 GstQuery *seeking_query;
115 fail_if (pipe (pipe_fd) < 0);
117 src = setup_fdsrc ();
118 g_object_set (G_OBJECT (src), "num-buffers", 3, NULL);
119 g_object_set (G_OBJECT (src), "fd", pipe_fd[0], NULL);
120 fail_unless (gst_element_set_state (src,
121 GST_STATE_PAUSED) == GST_STATE_CHANGE_SUCCESS,
122 "could not set to paused");
124 memset (data, 0, 4096);
125 fail_if (write (pipe_fd[1], data, 4096) < 0);
127 /* Test that fdsrc is non-seekable with a pipe */
128 fail_unless ((seeking_query = gst_query_new_seeking (GST_FORMAT_BYTES))
130 fail_unless (gst_element_query (src, seeking_query) == TRUE);
131 gst_query_parse_seeking (seeking_query, NULL, &seekable, NULL, NULL);
132 fail_unless (seekable == FALSE);
133 gst_query_unref (seeking_query);
135 fail_unless (gst_element_set_state (src,
136 GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null");
146 GST_START_TEST (test_seeking)
150 GstQuery *seeking_query;
154 #error TESTFILE not defined
156 fail_if ((in_fd = open (TESTFILE, O_RDONLY)) < 0);
157 src = setup_fdsrc ();
159 g_object_set (G_OBJECT (src), "fd", in_fd, NULL);
160 fail_unless (gst_element_set_state (src,
161 GST_STATE_PAUSED) == GST_STATE_CHANGE_SUCCESS,
162 "could not set to paused");
164 /* Test that fdsrc is seekable with a file fd */
165 fail_unless ((seeking_query = gst_query_new_seeking (GST_FORMAT_BYTES))
167 fail_unless (gst_element_query (src, seeking_query) == TRUE);
168 gst_query_parse_seeking (seeking_query, NULL, &seekable, NULL, NULL);
169 fail_unless (seekable == TRUE);
170 gst_query_unref (seeking_query);
172 fail_unless (gst_element_set_state (src,
173 GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null");
185 Suite *s = suite_create ("fdsrc");
186 TCase *tc_chain = tcase_create ("general");
188 suite_add_tcase (s, tc_chain);
189 tcase_add_test (tc_chain, test_num_buffers);
190 tcase_add_test (tc_chain, test_nonseeking);
191 tcase_add_test (tc_chain, test_seeking);
196 GST_CHECK_MAIN (fdsrc);