summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThiago Santos <thiago.sousa.santos@collabora.co.uk>2010-12-02 02:21:49 -0300
committerThiago Santos <thiago.sousa.santos@collabora.co.uk>2010-12-08 15:38:29 -0300
commitc7bdfa86af7e7be1bdd63e390ed959be327bd62e (patch)
tree1a32eaaf4e773fdbb1503716275ce4a461a5b3f9
parent0685b8921e45032baa63912ff5e0b3deee6757e1 (diff)
tests: camerabin2: adds tests for elements
Adds basic tests for both imagecapturebin and for videorecordingbin elements
-rw-r--r--tests/check/Makefile.am2
-rw-r--r--tests/check/elements/.gitignore2
-rw-r--r--tests/check/elements/imagecapturebin.c133
-rw-r--r--tests/check/elements/videorecordingbin.c125
4 files changed, 262 insertions, 0 deletions
diff --git a/tests/check/Makefile.am b/tests/check/Makefile.am
index 695af1189..f664924af 100644
--- a/tests/check/Makefile.am
+++ b/tests/check/Makefile.am
@@ -150,6 +150,7 @@ check_PROGRAMS = \
elements/camerabin \
elements/dataurisrc \
elements/flacparse \
+ elements/imagecapturebin \
elements/legacyresample \
$(check_jifmux) \
elements/jpegparse \
@@ -164,6 +165,7 @@ check_PROGRAMS = \
elements/rtpmux \
$(check_schro) \
elements/valve \
+ elements/videorecordingbin \
$(check_vp8) \
$(check_zbar) \
$(check_orc) \
diff --git a/tests/check/elements/.gitignore b/tests/check/elements/.gitignore
index 7c1133db4..175b0bea0 100644
--- a/tests/check/elements/.gitignore
+++ b/tests/check/elements/.gitignore
@@ -14,6 +14,7 @@ flacparse
gdpdepay
gdppay
id3mux
+imagecapturebin
interleave
jifmux
jpegparse
@@ -36,6 +37,7 @@ spectrum
timidity
y4menc
valve
+videorecordingbin
vp8dec
vp8enc
zbar
diff --git a/tests/check/elements/imagecapturebin.c b/tests/check/elements/imagecapturebin.c
new file mode 100644
index 000000000..860e3f5aa
--- /dev/null
+++ b/tests/check/elements/imagecapturebin.c
@@ -0,0 +1,133 @@
+/* GStreamer unit test for the imagecapturebin element
+ * Copyright (C) 2010 Thiago Santos <thiago.sousa.santos@collabora.co.uk>
+ *
+ * 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <stdio.h>
+#include <gst/check/gstcheck.h>
+
+#define N_BUFFERS 3
+
+typedef struct
+{
+ GstElement *pipe;
+ GstElement *src;
+ GstElement *icbin;
+} GstImageCaptureBinTestContext;
+
+static void
+gstimagecapturebin_init_test_context (GstImageCaptureBinTestContext * ctx,
+ gint num_buffers)
+{
+ fail_unless (ctx != NULL);
+
+ ctx->pipe = gst_pipeline_new ("pipeline");
+ fail_unless (ctx->pipe != NULL);
+ ctx->src = gst_element_factory_make ("videotestsrc", "src");
+ fail_unless (ctx->src != NULL, "Failed to create videotestsrc element");
+ ctx->icbin = gst_element_factory_make ("imagecapturebin", "icbin");
+ fail_unless (ctx->icbin != NULL, "Failed to create imagecapturebin element");
+
+ if (num_buffers > 0)
+ g_object_set (ctx->src, "num-buffers", num_buffers, NULL);
+
+ fail_unless (gst_bin_add (GST_BIN (ctx->pipe), ctx->src));
+ fail_unless (gst_bin_add (GST_BIN (ctx->pipe), ctx->icbin));
+ fail_unless (gst_element_link (ctx->src, ctx->icbin));
+}
+
+static void
+gstimagecapturebin_unset_test_context (GstImageCaptureBinTestContext * ctx)
+{
+ gst_element_set_state (ctx->pipe, GST_STATE_NULL);
+ gst_object_unref (ctx->pipe);
+ memset (ctx, 0, sizeof (GstImageCaptureBinTestContext));
+}
+
+static gchar *
+make_test_file_name (void)
+{
+ return g_strdup_printf ("%s" G_DIR_SEPARATOR_S
+ "imagecapturbintest_%%d.cap", g_get_tmp_dir ());
+}
+
+GST_START_TEST (test_simple_capture)
+{
+ GstImageCaptureBinTestContext ctx;
+ GstBus *bus;
+ GstMessage *msg;
+ gchar *test_file_name;
+ gint i;
+
+ gstimagecapturebin_init_test_context (&ctx, N_BUFFERS);
+ bus = gst_element_get_bus (ctx.pipe);
+
+ test_file_name = make_test_file_name ();
+ g_object_set (ctx.icbin, "location", test_file_name, NULL);
+
+ fail_if (gst_element_set_state (ctx.pipe, GST_STATE_PLAYING) ==
+ GST_STATE_CHANGE_FAILURE);
+
+ msg = gst_bus_timed_pop_filtered (bus, GST_SECOND * 10,
+ GST_MESSAGE_EOS | GST_MESSAGE_ERROR);
+ fail_unless (msg != NULL);
+ fail_unless (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_EOS);
+
+ /* check there are N_BUFFERS files */
+ for (i = 0; i < N_BUFFERS; i++) {
+ gchar *filename;
+ FILE *f;
+
+ filename = g_strdup_printf (test_file_name, i);
+
+ fail_unless (g_file_test (filename, G_FILE_TEST_EXISTS));
+ fail_unless (g_file_test (filename, G_FILE_TEST_IS_REGULAR));
+ fail_if (g_file_test (filename, G_FILE_TEST_IS_SYMLINK));
+
+ /* check the file isn't empty */
+ f = fopen (filename, "r");
+ fseek (f, 0, SEEK_END);
+ fail_unless (ftell (f) > 0);
+ fclose (f);
+
+ g_free (filename);
+ }
+
+ gstimagecapturebin_unset_test_context (&ctx);
+ gst_object_unref (bus);
+ g_free (test_file_name);
+}
+
+GST_END_TEST;
+
+static Suite *
+imagecapturebin_suite (void)
+{
+ Suite *s = suite_create ("imagecapturebin");
+ TCase *tc_chain = tcase_create ("general");
+
+ suite_add_tcase (s, tc_chain);
+ tcase_add_test (tc_chain, test_simple_capture);
+
+ return s;
+}
+
+GST_CHECK_MAIN (imagecapturebin);
diff --git a/tests/check/elements/videorecordingbin.c b/tests/check/elements/videorecordingbin.c
new file mode 100644
index 000000000..c002e3d8e
--- /dev/null
+++ b/tests/check/elements/videorecordingbin.c
@@ -0,0 +1,125 @@
+/* GStreamer unit test for the videorecordingbin element
+ * Copyright (C) 2010 Thiago Santos <thiago.sousa.santos@collabora.co.uk>
+ *
+ * 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <stdio.h>
+#include <gst/check/gstcheck.h>
+
+#define N_BUFFERS 100
+
+typedef struct
+{
+ GstElement *pipe;
+ GstElement *src;
+ GstElement *vrbin;
+} GstVideoRecordingBinTestContext;
+
+static void
+gstvideorecordingbin_init_test_context (GstVideoRecordingBinTestContext * ctx,
+ gint num_buffers)
+{
+ fail_unless (ctx != NULL);
+
+ ctx->pipe = gst_pipeline_new ("pipeline");
+ fail_unless (ctx->pipe != NULL);
+ ctx->src = gst_element_factory_make ("videotestsrc", "src");
+ fail_unless (ctx->src != NULL, "Failed to create videotestsrc element");
+ ctx->vrbin = gst_element_factory_make ("videorecordingbin", "icbin");
+ fail_unless (ctx->vrbin != NULL,
+ "Failed to create videorecordingbin element");
+
+ if (num_buffers > 0)
+ g_object_set (ctx->src, "num-buffers", num_buffers, NULL);
+
+ fail_unless (gst_bin_add (GST_BIN (ctx->pipe), ctx->src));
+ fail_unless (gst_bin_add (GST_BIN (ctx->pipe), ctx->vrbin));
+ fail_unless (gst_element_link (ctx->src, ctx->vrbin));
+}
+
+static void
+gstvideorecordingbin_unset_test_context (GstVideoRecordingBinTestContext * ctx)
+{
+ gst_element_set_state (ctx->pipe, GST_STATE_NULL);
+ gst_object_unref (ctx->pipe);
+ memset (ctx, 0, sizeof (GstVideoRecordingBinTestContext));
+}
+
+static gchar *
+make_test_file_name (gint num)
+{
+ return g_strdup_printf ("%s" G_DIR_SEPARATOR_S
+ "videorecordingbintest_%d.cap", g_get_tmp_dir (), num);
+}
+
+GST_START_TEST (test_simple_recording)
+{
+ GstVideoRecordingBinTestContext ctx;
+ GstBus *bus;
+ GstMessage *msg;
+ gchar *test_file_name;
+ FILE *f;
+
+ gstvideorecordingbin_init_test_context (&ctx, N_BUFFERS);
+ bus = gst_element_get_bus (ctx.pipe);
+
+ test_file_name = make_test_file_name (0);
+ g_object_set (ctx.vrbin, "location", test_file_name, NULL);
+
+ fail_if (gst_element_set_state (ctx.pipe, GST_STATE_PLAYING) ==
+ GST_STATE_CHANGE_FAILURE);
+
+ msg = gst_bus_timed_pop_filtered (bus, GST_SECOND * 10,
+ GST_MESSAGE_EOS | GST_MESSAGE_ERROR);
+ fail_unless (msg != NULL);
+ fail_unless (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_EOS);
+
+ /* check there is a recorded file */
+ fail_unless (g_file_test (test_file_name, G_FILE_TEST_EXISTS));
+ fail_unless (g_file_test (test_file_name, G_FILE_TEST_IS_REGULAR));
+ fail_if (g_file_test (test_file_name, G_FILE_TEST_IS_SYMLINK));
+
+ /* check the file isn't empty */
+ f = fopen (test_file_name, "r");
+ fseek (f, 0, SEEK_END);
+ fail_unless (ftell (f) > 0);
+ fclose (f);
+
+ gstvideorecordingbin_unset_test_context (&ctx);
+ gst_object_unref (bus);
+ g_free (test_file_name);
+}
+
+GST_END_TEST;
+
+static Suite *
+videorecordingbin_suite (void)
+{
+ Suite *s = suite_create ("videorecordingbin");
+ TCase *tc_chain = tcase_create ("general");
+
+ suite_add_tcase (s, tc_chain);
+ tcase_add_test (tc_chain, test_simple_recording);
+
+ return s;
+}
+
+GST_CHECK_MAIN (videorecordingbin);