Added gst-plugins-base-subtitles0.10-0.10.34 for Meego Harmattan 1.2
[mafwsubrenderer] / gst-plugins-base-subtitles0.10 / tests / check / elements / appsrc.c
1 /* GStreamer
2  *
3  * Copyright (C) 2010, Thiago Santos <thiago.sousa.santos@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 #include <gst/check/gstcheck.h>
22 #include <gst/app/gstappsrc.h>
23
24 #define SAMPLE_CAPS "application/x-gst-check-test"
25
26 static GstPad *mysinkpad;
27
28 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
29     GST_PAD_SINK,
30     GST_PAD_ALWAYS,
31     GST_STATIC_CAPS_ANY);
32
33 static GstElement *
34 setup_appsrc (void)
35 {
36   GstElement *appsrc;
37
38   GST_DEBUG ("setup_appsrc");
39   appsrc = gst_check_setup_element ("appsrc");
40   mysinkpad = gst_check_setup_sink_pad (appsrc, &sinktemplate, NULL);
41
42   gst_pad_set_active (mysinkpad, TRUE);
43
44   return appsrc;
45 }
46
47 static void
48 cleanup_appsrc (GstElement * appsrc)
49 {
50   GST_DEBUG ("cleanup_appsrc");
51
52   gst_check_teardown_sink_pad (appsrc);
53   gst_check_teardown_element (appsrc);
54 }
55
56
57 /*
58  * Pushes 4 buffers into appsrc and checks the caps on them on the output.
59  *
60  * Appsrc is configured with caps=null, so the buffers should have the
61  * same caps that they were pushed with.
62  *
63  * The 4 buffers have NULL, SAMPLE_CAPS, NULL, SAMPLE_CAPS caps,
64  * respectively.
65  */
66 GST_START_TEST (test_appsrc_null_caps)
67 {
68   GstElement *src;
69   GstBuffer *buffer;
70   GList *iter;
71   GstCaps *caps;
72
73   src = setup_appsrc ();
74
75   g_object_set (src, "caps", NULL, NULL);
76   caps = gst_caps_from_string (SAMPLE_CAPS);
77
78   ASSERT_SET_STATE (src, GST_STATE_PLAYING, GST_STATE_CHANGE_SUCCESS);
79
80   buffer = gst_buffer_new_and_alloc (4);
81   fail_unless (gst_app_src_push_buffer (GST_APP_SRC (src),
82           buffer) == GST_FLOW_OK);
83
84   buffer = gst_buffer_new_and_alloc (4);
85   gst_buffer_set_caps (buffer, caps);
86   fail_unless (gst_app_src_push_buffer (GST_APP_SRC (src),
87           buffer) == GST_FLOW_OK);
88
89   fail_unless (gst_app_src_end_of_stream (GST_APP_SRC (src)) == GST_FLOW_OK);
90
91   /* Give some time to the appsrc loop to push the buffers */
92   g_usleep (G_USEC_PER_SEC * 3);
93
94   /* Check the output caps */
95   fail_unless (g_list_length (buffers) == 2);
96   iter = buffers;
97   buffer = (GstBuffer *) iter->data;
98   fail_unless (GST_BUFFER_CAPS (buffer) == NULL);
99
100   iter = g_list_next (iter);
101   buffer = (GstBuffer *) iter->data;
102   fail_unless (gst_caps_is_equal (GST_BUFFER_CAPS (buffer), caps));
103
104   ASSERT_SET_STATE (src, GST_STATE_NULL, GST_STATE_CHANGE_SUCCESS);
105   gst_caps_unref (caps);
106   cleanup_appsrc (src);
107 }
108
109 GST_END_TEST;
110
111
112 /*
113  * Pushes 4 buffers into appsrc and checks the caps on them on the output.
114  *
115  * Appsrc is configured with caps=SAMPLE_CAPS, so the buffers should have the
116  * same caps that they were pushed with.
117  *
118  * The 4 buffers have NULL, SAMPLE_CAPS, NULL, SAMPLE_CAPS caps,
119  * respectively.
120  */
121 GST_START_TEST (test_appsrc_non_null_caps)
122 {
123   GstElement *src;
124   GstBuffer *buffer;
125   GList *iter;
126   GstCaps *caps;
127
128   src = setup_appsrc ();
129
130   caps = gst_caps_from_string (SAMPLE_CAPS);
131   g_object_set (src, "caps", caps, NULL);
132
133   ASSERT_SET_STATE (src, GST_STATE_PLAYING, GST_STATE_CHANGE_SUCCESS);
134
135   buffer = gst_buffer_new_and_alloc (4);
136   fail_unless (gst_app_src_push_buffer (GST_APP_SRC (src),
137           buffer) == GST_FLOW_OK);
138
139   buffer = gst_buffer_new_and_alloc (4);
140   gst_buffer_set_caps (buffer, caps);
141   fail_unless (gst_app_src_push_buffer (GST_APP_SRC (src),
142           buffer) == GST_FLOW_OK);
143
144   buffer = gst_buffer_new_and_alloc (4);
145   fail_unless (gst_app_src_push_buffer (GST_APP_SRC (src),
146           buffer) == GST_FLOW_OK);
147
148   buffer = gst_buffer_new_and_alloc (4);
149   gst_buffer_set_caps (buffer, caps);
150   fail_unless (gst_app_src_push_buffer (GST_APP_SRC (src),
151           buffer) == GST_FLOW_OK);
152
153   fail_unless (gst_app_src_end_of_stream (GST_APP_SRC (src)) == GST_FLOW_OK);
154
155   /* Give some time to the appsrc loop to push the buffers */
156   g_usleep (G_USEC_PER_SEC * 3);
157
158   /* Check the output caps */
159   fail_unless (g_list_length (buffers) == 4);
160   for (iter = buffers; iter; iter = g_list_next (iter)) {
161     GstBuffer *buf = (GstBuffer *) iter->data;
162
163     fail_unless (gst_caps_is_equal (GST_BUFFER_CAPS (buf), caps));
164   }
165
166   ASSERT_SET_STATE (src, GST_STATE_NULL, GST_STATE_CHANGE_SUCCESS);
167   gst_caps_unref (caps);
168   cleanup_appsrc (src);
169 }
170
171 GST_END_TEST;
172
173
174 static Suite *
175 appsrc_suite (void)
176 {
177   Suite *s = suite_create ("appsrc");
178   TCase *tc_chain = tcase_create ("general");
179
180   tcase_add_test (tc_chain, test_appsrc_null_caps);
181   tcase_add_test (tc_chain, test_appsrc_non_null_caps);
182
183   suite_add_tcase (s, tc_chain);
184
185   return s;
186 }
187
188 GST_CHECK_MAIN (appsrc);