3 * unit test for vorbisdec
5 * Copyright (C) <2005> Thomas Vander Stichele <thomas at apestaart dot org>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
25 #include <gst/check/gstcheck.h>
27 GList *buffers = NULL;
29 /* For ease of programming we use globals to keep refs for our floating
30 * src and sink pads we create; otherwise we always have to do get_pad,
31 * get_peer, and then remove references in every test function */
32 GstPad *mysrcpad, *mysinkpad;
34 /* a valid first header packet */
35 guchar identification_header[30] = {
37 'v', 'o', 'r', 'b', 'i', 's',
38 0, 0, 0, 0, /* vorbis_version */
39 2, /* audio_channels */
40 0x44, 0xac, 0, 0, /* sample_rate */
41 0xff, 0xff, 0xff, 0xff, /* bitrate_maximum */
42 0x00, 0xee, 0x02, 0x00, /* bitrate_nominal */
43 0xff, 0xff, 0xff, 0xff, /* bitrate_minimum */
44 0xb8, /* blocksize_0, blocksize_1 */
45 0x01, /* framing_flag */
48 guchar comment_header[] = {
50 'v', 'o', 'r', 'b', 'i', 's',
51 2, 0, 0, 0, /* vendor_length */
53 1, 0, 0, 0, /* user_comment_list_length */
54 9, 0, 0, 0, /* length comment[0] */
55 'A', 'R', 'T', 'I', 'S', 'T', '=', 'm', 'e',
56 0x01, /* framing bit */
59 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
63 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
71 GstElement *vorbisdec;
73 GST_DEBUG ("setup_vorbisdec");
74 vorbisdec = gst_check_setup_element ("vorbisdec");
75 mysrcpad = gst_check_setup_src_pad (vorbisdec, &srctemplate, NULL);
76 mysinkpad = gst_check_setup_sink_pad (vorbisdec, &sinktemplate, NULL);
82 cleanup_vorbisdec (GstElement * vorbisdec)
84 GST_DEBUG ("cleanup_vorbisdec");
85 gst_element_set_state (vorbisdec, GST_STATE_NULL);
87 gst_check_teardown_src_pad (vorbisdec);
88 gst_check_teardown_sink_pad (vorbisdec);
89 gst_check_teardown_element (vorbisdec);
92 GST_START_TEST (test_wrong_channels_identification_header)
94 GstElement *vorbisdec;
95 GstBuffer *inbuffer, *outbuffer;
99 vorbisdec = setup_vorbisdec ();
100 fail_unless (gst_element_set_state (vorbisdec,
101 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
102 "could not set to playing");
103 bus = gst_bus_new ();
105 inbuffer = gst_buffer_new_and_alloc (30);
106 memcpy (GST_BUFFER_DATA (inbuffer), identification_header, 30);
107 /* set the channel count to 7, which is not supported */
108 GST_BUFFER_DATA (inbuffer)[11] = 7;
109 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
110 gst_buffer_ref (inbuffer);
112 gst_element_set_bus (vorbisdec, bus);
113 /* pushing gives away my reference ... */
114 fail_unless_equals_int (gst_pad_push (mysrcpad, inbuffer), GST_FLOW_ERROR);
115 /* ... and nothing ends up on the global buffer list */
116 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
117 gst_buffer_unref (inbuffer);
118 fail_unless_equals_int (g_list_length (buffers), 0);
120 fail_if ((message = gst_bus_pop (bus)) == NULL);
121 fail_unless_message_error (message, STREAM, NOT_IMPLEMENTED);
122 gst_message_unref (message);
123 gst_element_set_bus (vorbisdec, NULL);
126 gst_object_unref (GST_OBJECT (bus));
127 cleanup_vorbisdec (vorbisdec);
133 GST_START_TEST (test_empty_identification_header)
135 GstElement *vorbisdec;
136 GstBuffer *inbuffer, *outbuffer;
140 vorbisdec = setup_vorbisdec ();
141 bus = gst_bus_new ();
143 fail_unless (gst_element_set_state (vorbisdec,
144 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
145 "could not set to playing");
147 inbuffer = gst_buffer_new_and_alloc (0);
148 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
150 /* set a bus here so we avoid getting state change messages */
151 gst_element_set_bus (vorbisdec, bus);
153 fail_unless_equals_int (gst_pad_push (mysrcpad, inbuffer), GST_FLOW_ERROR);
154 /* ... but it ends up being collected on the global buffer list */
155 fail_unless_equals_int (g_list_length (buffers), 0);
157 fail_if ((message = gst_bus_pop (bus)) == NULL);
158 fail_unless_message_error (message, STREAM, DECODE);
159 gst_message_unref (message);
160 gst_element_set_bus (vorbisdec, NULL);
163 gst_object_unref (GST_OBJECT (bus));
164 cleanup_vorbisdec (vorbisdec);
169 /* FIXME: also tests comment header */
170 GST_START_TEST (test_identification_header)
172 GstElement *vorbisdec;
173 GstBuffer *inbuffer, *outbuffer;
176 GstTagList *tag_list;
179 vorbisdec = setup_vorbisdec ();
180 fail_unless (gst_element_set_state (vorbisdec,
181 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
182 "could not set to playing");
183 bus = gst_bus_new ();
185 inbuffer = gst_buffer_new_and_alloc (30);
186 memcpy (GST_BUFFER_DATA (inbuffer), identification_header, 30);
187 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
188 gst_buffer_ref (inbuffer);
190 gst_element_set_bus (vorbisdec, bus);
191 /* pushing gives away my reference ... */
192 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
193 /* ... and nothing ends up on the global buffer list */
194 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
195 gst_buffer_unref (inbuffer);
196 fail_unless (g_list_length (buffers) == 0);
197 fail_if ((message = gst_bus_pop (bus)) != NULL);
199 inbuffer = gst_buffer_new_and_alloc (sizeof (comment_header));
200 memcpy (GST_BUFFER_DATA (inbuffer), comment_header, sizeof (comment_header));
201 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
202 gst_buffer_ref (inbuffer);
204 /* pushing gives away my reference ... */
205 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
206 /* ... and nothing ends up on the global buffer list */
207 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
208 gst_buffer_unref (inbuffer);
209 fail_unless (g_list_length (buffers) == 0);
210 /* there's a tag message waiting */
211 fail_if ((message = gst_bus_pop (bus)) == NULL);
212 gst_message_parse_tag (message, &tag_list);
213 fail_unless_equals_int (gst_tag_list_get_tag_size (tag_list, GST_TAG_ARTIST),
215 fail_unless (gst_tag_list_get_string (tag_list, GST_TAG_ARTIST, &artist));
216 fail_unless_equals_string (artist, "me");
218 fail_unless_equals_int (gst_tag_list_get_tag_size (tag_list, "album"), 0);
219 gst_tag_list_free (tag_list);
220 gst_message_unref (message);
223 gst_bus_set_flushing (bus, TRUE);
224 gst_element_set_bus (vorbisdec, NULL);
225 gst_object_unref (GST_OBJECT (bus));
226 cleanup_vorbisdec (vorbisdec);
232 vorbisdec_suite (void)
234 Suite *s = suite_create ("vorbisdec");
235 TCase *tc_chain = tcase_create ("general");
237 suite_add_tcase (s, tc_chain);
238 tcase_add_test (tc_chain, test_empty_identification_header);
239 tcase_add_test (tc_chain, test_wrong_channels_identification_header);
240 tcase_add_test (tc_chain, test_identification_header);
246 main (int argc, char **argv)
250 Suite *s = vorbisdec_suite ();
251 SRunner *sr = srunner_create (s);
253 gst_check_init (&argc, &argv);
255 srunner_run_all (sr, CK_NORMAL);
256 nf = srunner_ntests_failed (sr);