Initialize Tizen 2.3
[framework/multimedia/gstreamer0.10.git] / wearable / tests / check / libs / basesink.c
1 /* GStreamer
2  *
3  * Copyright (C) 2010 Alessandro Decina <alessandro.decina@collabora.co.uk>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24 #include <gst/gst.h>
25 #include <gst/check/gstcheck.h>
26 #include <gst/base/gstbasesink.h>
27
28 GST_START_TEST (basesink_last_buffer_enabled)
29 {
30   GstElement *src, *sink, *pipeline;
31   GstBus *bus;
32   GstMessage *msg;
33   GstBuffer *last_buffer;
34
35   pipeline = gst_pipeline_new ("pipeline");
36   sink = gst_element_factory_make ("fakesink", "sink");
37   src = gst_element_factory_make ("fakesrc", "src");
38
39   fail_unless (gst_bin_add (GST_BIN (pipeline), src) == TRUE);
40   fail_unless (gst_bin_add (GST_BIN (pipeline), sink) == TRUE);
41   fail_unless (gst_element_link (src, sink) == TRUE);
42
43   bus = gst_element_get_bus (pipeline);
44
45   /* try with enable-last-buffer set to TRUE */
46   g_object_set (src, "num-buffers", 1, NULL);
47   fail_unless (gst_element_set_state (pipeline, GST_STATE_PLAYING)
48       != GST_STATE_CHANGE_FAILURE);
49   msg = gst_bus_poll (bus, GST_MESSAGE_EOS | GST_MESSAGE_ERROR, -1);
50   fail_unless (msg != NULL);
51   fail_unless (GST_MESSAGE_TYPE (msg) != GST_MESSAGE_ERROR);
52   fail_unless (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_EOS);
53   gst_message_unref (msg);
54
55   /* last-buffer should be != NULL */
56   fail_unless (gst_base_sink_is_last_buffer_enabled (GST_BASE_SINK (sink))
57       == TRUE);
58   g_object_get (sink, "last-buffer", &last_buffer, NULL);
59   fail_unless (last_buffer != NULL);
60   gst_buffer_unref (last_buffer);
61
62   /* set enable-last-buffer to FALSE now, this should set last-buffer to NULL */
63   g_object_set (sink, "enable-last-buffer", FALSE, NULL);
64   fail_unless (gst_base_sink_is_last_buffer_enabled (GST_BASE_SINK (sink))
65       == FALSE);
66   g_object_get (sink, "last-buffer", &last_buffer, NULL);
67   fail_unless (last_buffer == NULL);
68
69   gst_element_set_state (pipeline, GST_STATE_NULL);
70
71   GST_INFO ("stopped");
72
73   gst_object_unref (bus);
74   gst_object_unref (pipeline);
75 }
76
77 GST_END_TEST;
78
79 GST_START_TEST (basesink_last_buffer_disabled)
80 {
81   GstElement *src, *sink, *pipeline;
82   GstBus *bus;
83   GstMessage *msg;
84   GstBuffer *last_buffer;
85
86   pipeline = gst_pipeline_new ("pipeline");
87   sink = gst_element_factory_make ("fakesink", "sink");
88   src = gst_element_factory_make ("fakesrc", "src");
89
90   fail_unless (gst_bin_add (GST_BIN (pipeline), src) == TRUE);
91   fail_unless (gst_bin_add (GST_BIN (pipeline), sink) == TRUE);
92   fail_unless (gst_element_link (src, sink) == TRUE);
93
94   bus = gst_element_get_bus (pipeline);
95
96   /* set enable-last-buffer to FALSE */
97   g_object_set (src, "num-buffers", 1, NULL);
98   gst_base_sink_set_last_buffer_enabled (GST_BASE_SINK (sink), FALSE);
99   gst_element_set_state (pipeline, GST_STATE_PLAYING);
100   msg = gst_bus_poll (bus, GST_MESSAGE_EOS | GST_MESSAGE_ERROR, -1);
101   fail_unless (msg != NULL);
102   fail_unless (GST_MESSAGE_TYPE (msg) != GST_MESSAGE_ERROR);
103   fail_unless (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_EOS);
104   gst_message_unref (msg);
105
106   /* last-buffer should be NULL */
107   g_object_get (sink, "last-buffer", &last_buffer, NULL);
108   fail_unless (last_buffer == NULL);
109
110   gst_element_set_state (pipeline, GST_STATE_NULL);
111
112   GST_INFO ("stopped");
113
114   gst_object_unref (bus);
115   gst_object_unref (pipeline);
116 }
117
118 GST_END_TEST;
119
120 static Suite *
121 gst_basesrc_suite (void)
122 {
123   Suite *s = suite_create ("GstBaseSink");
124   TCase *tc = tcase_create ("general");
125
126   suite_add_tcase (s, tc);
127   tcase_add_test (tc, basesink_last_buffer_enabled);
128   tcase_add_test (tc, basesink_last_buffer_disabled);
129
130   return s;
131 }
132
133 GST_CHECK_MAIN (gst_basesrc);