diff options
Diffstat (limited to 'tests/check/elements/multifile.c')
-rw-r--r-- | tests/check/elements/multifile.c | 136 |
1 files changed, 123 insertions, 13 deletions
diff --git a/tests/check/elements/multifile.c b/tests/check/elements/multifile.c index 6fe527e..0a4849a 100644 --- a/tests/check/elements/multifile.c +++ b/tests/check/elements/multifile.c @@ -26,6 +26,7 @@ #include <unistd.h> #include <gst/check/gstcheck.h> +#include <gst/video/video.h> #include <stdlib.h> #include <unistd.h> @@ -40,21 +41,21 @@ run_pipeline (GstElement * pipeline) gst_element_set_state (pipeline, GST_STATE_NULL); } +#if !GLIB_CHECK_VERSION(2,30,0) static gchar * -g_mkdtemp (const gchar * template) +g_mkdtemp (gchar * template) { - gchar *s; gchar *tmpdir; - s = g_strdup (template); - tmpdir = mkdtemp (s); + tmpdir = mkdtemp (template); if (tmpdir == NULL) { - g_free (s); + g_free (template); } return tmpdir; } +#endif -GST_START_TEST (test_multifilesink) +GST_START_TEST (test_multifilesink_key_frame) { GstElement *pipeline; GstElement *mfs; @@ -71,10 +72,10 @@ GST_START_TEST (test_multifilesink) pipeline = gst_parse_launch - ("videotestsrc num-buffers=10 ! video/x-raw-yuv,format=(fourcc)I420,width=320,height=240 ! multifilesink", + ("videotestsrc num-buffers=10 ! video/x-raw-yuv,format=(fourcc)I420,width=320,height=240 ! multifilesink name=mfs", NULL); fail_if (pipeline == NULL); - mfs = gst_bin_get_by_name (GST_BIN (pipeline), "multifilesink0"); + mfs = gst_bin_get_by_name (GST_BIN (pipeline), "mfs"); fail_if (mfs == NULL); mfs_pattern = g_build_filename (my_tmpdir, "%05d", NULL); g_object_set (G_OBJECT (mfs), "location", mfs_pattern, NULL); @@ -93,7 +94,115 @@ GST_START_TEST (test_multifilesink) g_free (mfs_pattern); g_free (my_tmpdir); - g_free (template); +} + +GST_END_TEST; + +GST_START_TEST (test_multifilesink_max_files) +{ + GstElement *pipeline; + GstElement *mfs; + int i; + const gchar *tmpdir; + gchar *my_tmpdir; + gchar *template; + gchar *mfs_pattern; + + tmpdir = g_get_tmp_dir (); + template = g_build_filename (tmpdir, "multifile-test-XXXXXX", NULL); + my_tmpdir = g_mkdtemp (template); + fail_if (my_tmpdir == NULL); + + pipeline = + gst_parse_launch + ("videotestsrc num-buffers=10 ! video/x-raw-yuv,format=(fourcc)I420,width=320,height=240 ! multifilesink name=mfs", + NULL); + fail_if (pipeline == NULL); + mfs = gst_bin_get_by_name (GST_BIN (pipeline), "mfs"); + fail_if (mfs == NULL); + mfs_pattern = g_build_filename (my_tmpdir, "%05d", NULL); + g_object_set (G_OBJECT (mfs), "location", mfs_pattern, "max-files", 3, NULL); + g_object_unref (mfs); + run_pipeline (pipeline); + gst_object_unref (pipeline); + + for (i = 0; i < 7; i++) { + char *s; + + s = g_strdup_printf (mfs_pattern, i); + fail_unless (g_remove (s) != 0); + g_free (s); + } + for (i = 7; i < 10; i++) { + char *s; + + s = g_strdup_printf (mfs_pattern, i); + fail_if (g_remove (s) != 0); + g_free (s); + } + fail_if (g_remove (my_tmpdir) != 0); + + g_free (mfs_pattern); + g_free (my_tmpdir); +} + +GST_END_TEST; + +GST_START_TEST (test_multifilesink_key_unit) +{ + GstElement *mfs; + int i; + const gchar *tmpdir; + gchar *my_tmpdir; + gchar *template; + gchar *mfs_pattern; + GstBuffer *buf; + GstPad *sink; + + tmpdir = g_get_tmp_dir (); + template = g_build_filename (tmpdir, "multifile-test-XXXXXX", NULL); + my_tmpdir = g_mkdtemp (template); + fail_if (my_tmpdir == NULL); + + mfs = gst_element_factory_make ("multifilesink", NULL); + fail_if (mfs == NULL); + mfs_pattern = g_build_filename (my_tmpdir, "%05d", NULL); + g_object_set (G_OBJECT (mfs), "location", mfs_pattern, "next-file", 3, NULL); + fail_if (gst_element_set_state (mfs, + GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE); + + sink = gst_element_get_static_pad (mfs, "sink"); + buf = gst_buffer_new_and_alloc (4); + + memcpy (GST_BUFFER_DATA (buf), "foo", 4); + fail_if (gst_pad_chain (sink, gst_buffer_ref (buf)) != GST_FLOW_OK); + + memcpy (GST_BUFFER_DATA (buf), "bar", 4); + fail_if (gst_pad_chain (sink, gst_buffer_ref (buf)) != GST_FLOW_OK); + + fail_unless (gst_pad_send_event (sink, + gst_video_event_new_downstream_force_key_unit (GST_CLOCK_TIME_NONE, + GST_CLOCK_TIME_NONE, GST_CLOCK_TIME_NONE, TRUE, 1))); + + memcpy (GST_BUFFER_DATA (buf), "baz", 4); + fail_if (gst_pad_chain (sink, buf) != GST_FLOW_OK); + + fail_if (gst_element_set_state (mfs, + GST_STATE_NULL) == GST_STATE_CHANGE_FAILURE); + + for (i = 0; i < 2; i++) { + char *s; + + s = g_strdup_printf (mfs_pattern, i); + fail_if (g_remove (s) != 0); + g_free (s); + } + fail_if (g_remove (my_tmpdir) != 0); + + g_free (mfs_pattern); + g_free (my_tmpdir); + gst_object_unref (sink); + gst_object_unref (mfs); } GST_END_TEST; @@ -115,10 +224,10 @@ GST_START_TEST (test_multifilesrc) pipeline = gst_parse_launch - ("videotestsrc num-buffers=10 ! video/x-raw-yuv,format=(fourcc)I420,width=320,height=240 ! multifilesink", + ("videotestsrc num-buffers=10 ! video/x-raw-yuv,format=(fourcc)I420,width=320,height=240 ! multifilesink name=mfs", NULL); fail_if (pipeline == NULL); - mfs = gst_bin_get_by_name (GST_BIN (pipeline), "multifilesink0"); + mfs = gst_bin_get_by_name (GST_BIN (pipeline), "mfs"); fail_if (mfs == NULL); mfs_pattern = g_build_filename (my_tmpdir, "%05d", NULL); g_object_set (G_OBJECT (mfs), "location", mfs_pattern, NULL); @@ -151,7 +260,6 @@ GST_START_TEST (test_multifilesrc) g_free (mfs_pattern); g_free (my_tmpdir); - g_free (template); } GST_END_TEST; @@ -164,7 +272,9 @@ libvisual_suite (void) suite_add_tcase (s, tc_chain); - tcase_add_test (tc_chain, test_multifilesink); + tcase_add_test (tc_chain, test_multifilesink_key_frame); + tcase_add_test (tc_chain, test_multifilesink_max_files); + tcase_add_test (tc_chain, test_multifilesink_key_unit); tcase_add_test (tc_chain, test_multifilesrc); return s; |