From 72ef18d535286ebe0ee826f50f88d7b991de9dae Mon Sep 17 00:00:00 2001 From: Thiago Santos Date: Mon, 20 Dec 2010 02:59:14 -0300 Subject: [PATCH] viewfinderbin: Add basic check test Adds minimum check test. It's not a very useful test, but at least it allows us to run it under valgrind and check for leaks automatically --- tests/check/Makefile.am | 3 +- tests/check/elements/viewfinderbin.c | 103 +++++++++++++++++++++++++++ 2 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 tests/check/elements/viewfinderbin.c diff --git a/tests/check/Makefile.am b/tests/check/Makefile.am index 864ce0888b..dc86ff433a 100644 --- a/tests/check/Makefile.am +++ b/tests/check/Makefile.am @@ -130,7 +130,8 @@ VALGRIND_TESTS_DISABLE = \ if BUILD_EXPERIMENTAL EXPERIMENTAL_CHECKS=elements/camerabin2 \ elements/imagecapturebin \ - elements/videorecordingbin + elements/videorecordingbin \ + elements/viewfinderbin endif # these tests don't even pass diff --git a/tests/check/elements/viewfinderbin.c b/tests/check/elements/viewfinderbin.c new file mode 100644 index 0000000000..c5766052c2 --- /dev/null +++ b/tests/check/elements/viewfinderbin.c @@ -0,0 +1,103 @@ +/* GStreamer unit test for the viewfinderbin element + * Copyright (C) 2010 Thiago Santos + * + * 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 +#include + +typedef struct +{ + GstElement *pipe; + GstElement *src; + GstElement *vfbin; +} GstViewFinderBinTestContext; + +static void +gstviewfinderbin_init_test_context (GstViewFinderBinTestContext * ctx, + gint num_buffers) +{ + GstElement *sink; + 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"); + sink = gst_element_factory_make ("fakesink", NULL); + ctx->vfbin = gst_element_factory_make ("viewfinderbin", "vfbin"); + fail_unless (ctx->vfbin != NULL, "Failed to create viewfinderbin element"); + g_object_set (ctx->vfbin, "video-sink", sink, NULL); + gst_object_unref (sink); + + 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->vfbin)); + fail_unless (gst_element_link (ctx->src, ctx->vfbin)); +} + +static void +gstviewfinderbin_unset_test_context (GstViewFinderBinTestContext * ctx) +{ + gst_element_set_state (ctx->pipe, GST_STATE_NULL); + gst_object_unref (ctx->pipe); + memset (ctx, 0, sizeof (GstViewFinderBinTestContext)); +} + +GST_START_TEST (test_simple_run) +{ + GstViewFinderBinTestContext ctx; + GstBus *bus; + GstMessage *msg; + + gstviewfinderbin_init_test_context (&ctx, 10); + bus = gst_element_get_bus (ctx.pipe); + + fail_if (gst_element_set_state (ctx.pipe, GST_STATE_PLAYING) == + GST_STATE_CHANGE_FAILURE); + + msg = gst_bus_timed_pop_filtered (bus, GST_SECOND * 30, + GST_MESSAGE_EOS | GST_MESSAGE_ERROR); + fail_unless (msg != NULL); + fail_unless (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_EOS); + gst_message_unref (msg); + + gstviewfinderbin_unset_test_context (&ctx); + gst_object_unref (bus); +} + +GST_END_TEST; + +static Suite * +viewfinderbin_suite (void) +{ + Suite *s = suite_create ("viewfinderbin"); + TCase *tc_chain = tcase_create ("general"); + + suite_add_tcase (s, tc_chain); + tcase_add_test (tc_chain, test_simple_run); + + return s; +} + +GST_CHECK_MAIN (viewfinderbin);