3 * Copyright (C) 2010 Alessandro Decina <alessandro.decina@collabora.co.uk>
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.
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.
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.
25 #include <gst/check/gstcheck.h>
26 #include <gst/base/gstbasesink.h>
28 GST_START_TEST (basesink_last_buffer_enabled)
30 GstElement *src, *sink, *pipeline;
33 GstBuffer *last_buffer;
35 pipeline = gst_pipeline_new ("pipeline");
36 sink = gst_element_factory_make ("fakesink", "sink");
37 src = gst_element_factory_make ("fakesrc", "src");
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);
43 bus = gst_element_get_bus (pipeline);
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);
55 /* last-buffer should be != NULL */
56 g_object_get (sink, "last-buffer", &last_buffer, NULL);
57 fail_unless (last_buffer != NULL);
58 gst_buffer_unref (last_buffer);
60 /* set enable-last-buffer to FALSE now, this should set last-buffer to NULL */
61 g_object_set (sink, "enable-last-buffer", FALSE, NULL);
62 g_object_get (sink, "last-buffer", &last_buffer, NULL);
63 fail_unless (last_buffer == NULL);
65 gst_element_set_state (pipeline, GST_STATE_NULL);
69 gst_object_unref (bus);
70 gst_object_unref (pipeline);
75 GST_START_TEST (basesink_last_buffer_disabled)
77 GstElement *src, *sink, *pipeline;
80 GstBuffer *last_buffer;
82 pipeline = gst_pipeline_new ("pipeline");
83 sink = gst_element_factory_make ("fakesink", "sink");
84 src = gst_element_factory_make ("fakesrc", "src");
86 fail_unless (gst_bin_add (GST_BIN (pipeline), src) == TRUE);
87 fail_unless (gst_bin_add (GST_BIN (pipeline), sink) == TRUE);
88 fail_unless (gst_element_link (src, sink) == TRUE);
90 bus = gst_element_get_bus (pipeline);
92 /* set enable-last-buffer to FALSE */
93 g_object_set (src, "num-buffers", 1, NULL);
94 g_object_set (sink, "enable-last-buffer", FALSE, NULL);
95 gst_element_set_state (pipeline, GST_STATE_PLAYING);
96 msg = gst_bus_poll (bus, GST_MESSAGE_EOS | GST_MESSAGE_ERROR, -1);
97 fail_unless (msg != NULL);
98 fail_unless (GST_MESSAGE_TYPE (msg) != GST_MESSAGE_ERROR);
99 fail_unless (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_EOS);
100 gst_message_unref (msg);
102 /* last-buffer should be NULL */
103 g_object_get (sink, "last-buffer", &last_buffer, NULL);
104 fail_unless (last_buffer == NULL);
106 gst_element_set_state (pipeline, GST_STATE_NULL);
108 GST_INFO ("stopped");
110 gst_object_unref (bus);
111 gst_object_unref (pipeline);
117 gst_basesrc_suite (void)
119 Suite *s = suite_create ("GstBaseSink");
120 TCase *tc = tcase_create ("general");
122 suite_add_tcase (s, tc);
123 tcase_add_test (tc, basesink_last_buffer_enabled);
124 tcase_add_test (tc, basesink_last_buffer_disabled);
129 GST_CHECK_MAIN (gst_basesrc);