1 /* GStreamer unit test for multifile plugin
3 * Copyright (C) 2007 David A. Schleef <ds@schleef.org>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
25 #include <glib/gstdio.h>
28 #include <gst/check/gstcheck.h>
29 #include <gst/video/video.h>
34 run_pipeline (GstElement * pipeline)
36 gst_element_set_state (pipeline, GST_STATE_PAUSED);
37 gst_element_get_state (pipeline, NULL, NULL, -1);
38 gst_element_set_state (pipeline, GST_STATE_PLAYING);
41 gst_element_set_state (pipeline, GST_STATE_NULL);
44 #if !GLIB_CHECK_VERSION(2,30,0)
46 g_mkdtemp (gchar * template)
50 tmpdir = mkdtemp (template);
58 GST_START_TEST (test_multifilesink_key_frame)
68 tmpdir = g_get_tmp_dir ();
69 template = g_build_filename (tmpdir, "multifile-test-XXXXXX", NULL);
70 my_tmpdir = g_mkdtemp (template);
71 fail_if (my_tmpdir == NULL);
75 ("videotestsrc num-buffers=10 ! video/x-raw-yuv,format=(fourcc)I420,width=320,height=240 ! multifilesink name=mfs",
77 fail_if (pipeline == NULL);
78 mfs = gst_bin_get_by_name (GST_BIN (pipeline), "mfs");
79 fail_if (mfs == NULL);
80 mfs_pattern = g_build_filename (my_tmpdir, "%05d", NULL);
81 g_object_set (G_OBJECT (mfs), "location", mfs_pattern, NULL);
83 run_pipeline (pipeline);
84 gst_object_unref (pipeline);
86 for (i = 0; i < 10; i++) {
89 s = g_strdup_printf (mfs_pattern, i);
90 fail_if (g_remove (s) != 0);
93 fail_if (g_remove (my_tmpdir) != 0);
101 GST_START_TEST (test_multifilesink_max_files)
103 GstElement *pipeline;
111 tmpdir = g_get_tmp_dir ();
112 template = g_build_filename (tmpdir, "multifile-test-XXXXXX", NULL);
113 my_tmpdir = g_mkdtemp (template);
114 fail_if (my_tmpdir == NULL);
118 ("videotestsrc num-buffers=10 ! video/x-raw-yuv,format=(fourcc)I420,width=320,height=240 ! multifilesink name=mfs",
120 fail_if (pipeline == NULL);
121 mfs = gst_bin_get_by_name (GST_BIN (pipeline), "mfs");
122 fail_if (mfs == NULL);
123 mfs_pattern = g_build_filename (my_tmpdir, "%05d", NULL);
124 g_object_set (G_OBJECT (mfs), "location", mfs_pattern, "max-files", 3, NULL);
125 g_object_unref (mfs);
126 run_pipeline (pipeline);
127 gst_object_unref (pipeline);
129 for (i = 0; i < 7; i++) {
132 s = g_strdup_printf (mfs_pattern, i);
133 fail_unless (g_remove (s) != 0);
136 for (i = 7; i < 10; i++) {
139 s = g_strdup_printf (mfs_pattern, i);
140 fail_if (g_remove (s) != 0);
143 fail_if (g_remove (my_tmpdir) != 0);
145 g_free (mfs_pattern);
151 GST_START_TEST (test_multifilesink_key_unit)
162 tmpdir = g_get_tmp_dir ();
163 template = g_build_filename (tmpdir, "multifile-test-XXXXXX", NULL);
164 my_tmpdir = g_mkdtemp (template);
165 fail_if (my_tmpdir == NULL);
167 mfs = gst_element_factory_make ("multifilesink", NULL);
168 fail_if (mfs == NULL);
169 mfs_pattern = g_build_filename (my_tmpdir, "%05d", NULL);
170 g_object_set (G_OBJECT (mfs), "location", mfs_pattern, "next-file", 3, NULL);
171 fail_if (gst_element_set_state (mfs,
172 GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE);
174 sink = gst_element_get_static_pad (mfs, "sink");
175 buf = gst_buffer_new_and_alloc (4);
177 memcpy (GST_BUFFER_DATA (buf), "foo", 4);
178 fail_if (gst_pad_chain (sink, gst_buffer_ref (buf)) != GST_FLOW_OK);
180 memcpy (GST_BUFFER_DATA (buf), "bar", 4);
181 fail_if (gst_pad_chain (sink, gst_buffer_ref (buf)) != GST_FLOW_OK);
183 fail_unless (gst_pad_send_event (sink,
184 gst_video_event_new_downstream_force_key_unit (GST_CLOCK_TIME_NONE,
185 GST_CLOCK_TIME_NONE, GST_CLOCK_TIME_NONE, TRUE, 1)));
187 memcpy (GST_BUFFER_DATA (buf), "baz", 4);
188 fail_if (gst_pad_chain (sink, buf) != GST_FLOW_OK);
190 fail_if (gst_element_set_state (mfs,
191 GST_STATE_NULL) == GST_STATE_CHANGE_FAILURE);
193 for (i = 0; i < 2; i++) {
196 s = g_strdup_printf (mfs_pattern, i);
197 fail_if (g_remove (s) != 0);
200 fail_if (g_remove (my_tmpdir) != 0);
202 g_free (mfs_pattern);
204 gst_object_unref (sink);
205 gst_object_unref (mfs);
210 GST_START_TEST (test_multifilesrc)
212 GstElement *pipeline;
220 tmpdir = g_get_tmp_dir ();
221 template = g_build_filename (tmpdir, "multifile-test-XXXXXX", NULL);
222 my_tmpdir = g_mkdtemp (template);
223 fail_if (my_tmpdir == NULL);
227 ("videotestsrc num-buffers=10 ! video/x-raw-yuv,format=(fourcc)I420,width=320,height=240 ! multifilesink name=mfs",
229 fail_if (pipeline == NULL);
230 mfs = gst_bin_get_by_name (GST_BIN (pipeline), "mfs");
231 fail_if (mfs == NULL);
232 mfs_pattern = g_build_filename (my_tmpdir, "%05d", NULL);
233 g_object_set (G_OBJECT (mfs), "location", mfs_pattern, NULL);
234 g_free (mfs_pattern);
235 g_object_unref (mfs);
236 run_pipeline (pipeline);
237 gst_object_unref (pipeline);
241 ("multifilesrc ! video/x-raw-yuv,format=(fourcc)I420,width=320,height=240,framerate=10/1 ! fakesink",
243 fail_if (pipeline == NULL);
244 mfs = gst_bin_get_by_name (GST_BIN (pipeline), "multifilesrc0");
245 fail_if (mfs == NULL);
246 mfs_pattern = g_build_filename (my_tmpdir, "%05d", NULL);
247 g_object_set (G_OBJECT (mfs), "location", mfs_pattern, NULL);
248 g_object_unref (mfs);
249 run_pipeline (pipeline);
250 gst_object_unref (pipeline);
252 for (i = 0; i < 10; i++) {
255 s = g_strdup_printf (mfs_pattern, i);
256 fail_if (g_remove (s) != 0);
259 fail_if (g_remove (my_tmpdir) != 0);
261 g_free (mfs_pattern);
268 libvisual_suite (void)
270 Suite *s = suite_create ("multifile");
271 TCase *tc_chain = tcase_create ("general");
273 suite_add_tcase (s, tc_chain);
275 tcase_add_test (tc_chain, test_multifilesink_key_frame);
276 tcase_add_test (tc_chain, test_multifilesink_max_files);
277 tcase_add_test (tc_chain, test_multifilesink_key_unit);
278 tcase_add_test (tc_chain, test_multifilesrc);
283 GST_CHECK_MAIN (libvisual);