2007-10-25 23:42:52 +00:00
|
|
|
/* GStreamer unit test for multifile plugin
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 David A. Schleef <ds@schleef.org>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2008-02-08 02:48:54 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <glib/gstdio.h>
|
2007-10-25 23:42:52 +00:00
|
|
|
#include <gst/check/gstcheck.h>
|
|
|
|
|
|
|
|
static void
|
|
|
|
run_pipeline (GstElement * pipeline)
|
|
|
|
{
|
|
|
|
gst_element_set_state (pipeline, GST_STATE_PAUSED);
|
|
|
|
gst_element_get_state (pipeline, NULL, NULL, -1);
|
|
|
|
gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
|
|
|
/* FIXME too lazy */
|
|
|
|
g_usleep (1000000);
|
|
|
|
gst_element_set_state (pipeline, GST_STATE_NULL);
|
|
|
|
}
|
|
|
|
|
2008-02-08 03:44:12 +00:00
|
|
|
gchar *
|
|
|
|
g_mkdtemp (const gchar * template)
|
|
|
|
{
|
|
|
|
gchar *s;
|
|
|
|
gchar *tmpdir;
|
|
|
|
|
|
|
|
s = g_strdup (template);
|
|
|
|
tmpdir = mkdtemp (s);
|
|
|
|
if (tmpdir == NULL) {
|
|
|
|
g_free (s);
|
|
|
|
}
|
|
|
|
return tmpdir;
|
|
|
|
}
|
|
|
|
|
2007-10-25 23:42:52 +00:00
|
|
|
GST_START_TEST (test_multifilesink)
|
|
|
|
{
|
|
|
|
GstElement *pipeline;
|
2008-02-08 03:44:12 +00:00
|
|
|
GstElement *mfs;
|
2007-10-25 23:42:52 +00:00
|
|
|
int i;
|
2008-02-08 03:44:12 +00:00
|
|
|
const gchar *tmpdir;
|
|
|
|
gchar *my_tmpdir;
|
|
|
|
gchar *template;
|
|
|
|
gchar *mfs_pattern;
|
2007-10-25 23:42:52 +00:00
|
|
|
|
2008-02-08 03:44:12 +00:00
|
|
|
tmpdir = g_get_tmp_dir ();
|
|
|
|
template = g_build_filename (tmpdir, "multifile-test-XXXXXX", NULL);
|
|
|
|
my_tmpdir = g_mkdtemp (template);
|
|
|
|
fail_if (my_tmpdir == NULL);
|
2007-10-25 23:42:52 +00:00
|
|
|
|
|
|
|
pipeline =
|
|
|
|
gst_parse_launch
|
2008-02-08 03:44:12 +00:00
|
|
|
("videotestsrc num-buffers=10 ! video/x-raw-yuv,format=(fourcc)I420,width=320,height=240 ! multifilesink",
|
2007-10-25 23:42:52 +00:00
|
|
|
NULL);
|
|
|
|
fail_if (pipeline == NULL);
|
2008-02-08 03:44:12 +00:00
|
|
|
mfs = gst_bin_get_by_name (GST_BIN (pipeline), "multifilesink0");
|
|
|
|
fail_if (mfs == NULL);
|
|
|
|
mfs_pattern = g_build_filename (my_tmpdir, "%05d", NULL);
|
|
|
|
g_object_set (G_OBJECT (mfs), "location", mfs_pattern, NULL);
|
2007-10-25 23:42:52 +00:00
|
|
|
run_pipeline (pipeline);
|
|
|
|
gst_object_unref (pipeline);
|
|
|
|
|
|
|
|
for (i = 0; i < 10; i++) {
|
2008-02-08 03:44:12 +00:00
|
|
|
char *s;
|
2007-10-25 23:42:52 +00:00
|
|
|
|
2008-02-08 03:44:12 +00:00
|
|
|
s = g_strdup_printf (mfs_pattern, i);
|
2007-10-25 23:42:52 +00:00
|
|
|
fail_if (g_remove (s) != 0);
|
2008-02-08 03:44:12 +00:00
|
|
|
g_free (s);
|
2007-10-25 23:42:52 +00:00
|
|
|
}
|
2008-02-08 03:44:12 +00:00
|
|
|
fail_if (g_remove (my_tmpdir) != 0);
|
2007-10-25 23:42:52 +00:00
|
|
|
|
2008-02-08 03:44:12 +00:00
|
|
|
g_free (mfs_pattern);
|
|
|
|
g_free (my_tmpdir);
|
|
|
|
g_free (template);
|
2007-10-25 23:42:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
|
|
|
GST_START_TEST (test_multifilesrc)
|
|
|
|
{
|
|
|
|
GstElement *pipeline;
|
2008-02-08 03:44:12 +00:00
|
|
|
GstElement *mfs;
|
2007-10-25 23:42:52 +00:00
|
|
|
int i;
|
2008-02-08 03:44:12 +00:00
|
|
|
const gchar *tmpdir;
|
|
|
|
gchar *my_tmpdir;
|
|
|
|
gchar *template;
|
|
|
|
gchar *mfs_pattern;
|
2007-10-25 23:42:52 +00:00
|
|
|
|
2008-02-08 03:44:12 +00:00
|
|
|
tmpdir = g_get_tmp_dir ();
|
|
|
|
template = g_build_filename (tmpdir, "multifile-test-XXXXXX", NULL);
|
|
|
|
my_tmpdir = g_mkdtemp (template);
|
|
|
|
fail_if (my_tmpdir == NULL);
|
2007-10-25 23:42:52 +00:00
|
|
|
|
|
|
|
pipeline =
|
|
|
|
gst_parse_launch
|
2008-02-08 03:44:12 +00:00
|
|
|
("videotestsrc num-buffers=10 ! video/x-raw-yuv,format=(fourcc)I420,width=320,height=240 ! multifilesink",
|
2007-10-25 23:42:52 +00:00
|
|
|
NULL);
|
|
|
|
fail_if (pipeline == NULL);
|
2008-02-08 03:44:12 +00:00
|
|
|
mfs = gst_bin_get_by_name (GST_BIN (pipeline), "multifilesink0");
|
|
|
|
fail_if (mfs == NULL);
|
|
|
|
mfs_pattern = g_build_filename (my_tmpdir, "%05d", NULL);
|
|
|
|
g_object_set (G_OBJECT (mfs), "location", mfs_pattern, NULL);
|
2007-10-25 23:42:52 +00:00
|
|
|
run_pipeline (pipeline);
|
|
|
|
gst_object_unref (pipeline);
|
|
|
|
|
|
|
|
pipeline =
|
|
|
|
gst_parse_launch
|
2008-02-08 03:44:12 +00:00
|
|
|
("multifilesrc ! video/x-raw-yuv,format=(fourcc)I420,width=320,height=240,framerate=10/1 ! fakesink",
|
2007-10-25 23:42:52 +00:00
|
|
|
NULL);
|
|
|
|
fail_if (pipeline == NULL);
|
2008-02-08 03:44:12 +00:00
|
|
|
mfs = gst_bin_get_by_name (GST_BIN (pipeline), "multifilesrc0");
|
|
|
|
fail_if (mfs == NULL);
|
|
|
|
mfs_pattern = g_build_filename (my_tmpdir, "%05d", NULL);
|
|
|
|
g_object_set (G_OBJECT (mfs), "location", mfs_pattern, NULL);
|
2007-10-25 23:42:52 +00:00
|
|
|
run_pipeline (pipeline);
|
|
|
|
gst_object_unref (pipeline);
|
|
|
|
|
|
|
|
for (i = 0; i < 10; i++) {
|
2008-02-08 03:44:12 +00:00
|
|
|
char *s;
|
2007-10-25 23:42:52 +00:00
|
|
|
|
2008-02-08 03:44:12 +00:00
|
|
|
s = g_strdup_printf (mfs_pattern, i);
|
2007-10-25 23:42:52 +00:00
|
|
|
fail_if (g_remove (s) != 0);
|
2008-02-08 03:44:12 +00:00
|
|
|
g_free (s);
|
2007-10-25 23:42:52 +00:00
|
|
|
}
|
2008-02-08 03:44:12 +00:00
|
|
|
fail_if (g_remove (my_tmpdir) != 0);
|
2007-10-25 23:42:52 +00:00
|
|
|
|
2008-02-08 03:44:12 +00:00
|
|
|
g_free (mfs_pattern);
|
|
|
|
g_free (my_tmpdir);
|
|
|
|
g_free (template);
|
2007-10-25 23:42:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
|
|
|
static Suite *
|
|
|
|
libvisual_suite (void)
|
|
|
|
{
|
|
|
|
Suite *s = suite_create ("multifile");
|
|
|
|
TCase *tc_chain = tcase_create ("general");
|
|
|
|
|
|
|
|
suite_add_tcase (s, tc_chain);
|
|
|
|
|
|
|
|
tcase_add_test (tc_chain, test_multifilesink);
|
|
|
|
tcase_add_test (tc_chain, test_multifilesrc);
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_CHECK_MAIN (libvisual);
|