1 /* GStreamer unit test for the viewfinderbin element
2  * Copyright (C) 2010 Thiago Santos <thiago.sousa.santos@collabora.co.uk>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19 
20 #ifdef HAVE_CONFIG_H
21 # include "config.h"
22 #endif
23 
24 #include <stdio.h>
25 #include <gst/check/gstcheck.h>
26 
27 typedef struct
28 {
29   GstElement *pipe;
30   GstElement *src;
31   GstElement *vfbin;
32 } GstViewFinderBinTestContext;
33 
34 static void
gstviewfinderbin_init_test_context(GstViewFinderBinTestContext * ctx,gint num_buffers)35 gstviewfinderbin_init_test_context (GstViewFinderBinTestContext * ctx,
36     gint num_buffers)
37 {
38   GstElement *sink;
39   fail_unless (ctx != NULL);
40 
41   ctx->pipe = gst_pipeline_new ("pipeline");
42   fail_unless (ctx->pipe != NULL);
43   ctx->src = gst_element_factory_make ("videotestsrc", "src");
44   fail_unless (ctx->src != NULL, "Failed to create videotestsrc element");
45   sink = gst_element_factory_make ("fakesink", NULL);
46   ctx->vfbin = gst_element_factory_make ("viewfinderbin", "vfbin");
47   fail_unless (ctx->vfbin != NULL, "Failed to create viewfinderbin element");
48   g_object_set (ctx->vfbin, "video-sink", sink, NULL);
49   gst_object_unref (sink);
50 
51   if (num_buffers > 0)
52     g_object_set (ctx->src, "num-buffers", num_buffers, NULL);
53 
54   fail_unless (gst_bin_add (GST_BIN (ctx->pipe), ctx->src));
55   fail_unless (gst_bin_add (GST_BIN (ctx->pipe), ctx->vfbin));
56   fail_unless (gst_element_link (ctx->src, ctx->vfbin));
57 }
58 
59 static void
gstviewfinderbin_unset_test_context(GstViewFinderBinTestContext * ctx)60 gstviewfinderbin_unset_test_context (GstViewFinderBinTestContext * ctx)
61 {
62   gst_element_set_state (ctx->pipe, GST_STATE_NULL);
63   gst_object_unref (ctx->pipe);
64   memset (ctx, 0, sizeof (GstViewFinderBinTestContext));
65 }
66 
GST_START_TEST(test_simple_run)67 GST_START_TEST (test_simple_run)
68 {
69   GstViewFinderBinTestContext ctx;
70   GstBus *bus;
71   GstMessage *msg;
72 
73   gstviewfinderbin_init_test_context (&ctx, 10);
74   bus = gst_element_get_bus (ctx.pipe);
75 
76   fail_if (gst_element_set_state (ctx.pipe, GST_STATE_PLAYING) ==
77       GST_STATE_CHANGE_FAILURE);
78 
79   msg = gst_bus_timed_pop_filtered (bus, GST_SECOND * 30,
80       GST_MESSAGE_EOS | GST_MESSAGE_ERROR);
81   fail_unless (msg != NULL);
82   fail_unless (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_EOS);
83   gst_message_unref (msg);
84 
85   gstviewfinderbin_unset_test_context (&ctx);
86   gst_object_unref (bus);
87 }
88 
89 GST_END_TEST;
90 
91 static Suite *
viewfinderbin_suite(void)92 viewfinderbin_suite (void)
93 {
94   Suite *s = suite_create ("viewfinderbin");
95   TCase *tc_chain = tcase_create ("general");
96 
97   suite_add_tcase (s, tc_chain);
98   tcase_add_test (tc_chain, test_simple_run);
99 
100   return s;
101 }
102 
103 GST_CHECK_MAIN (viewfinderbin);
104