3 * unit test for wavpackdec
5 * Copyright (c) 2006 Sebastian Dröge <slomo@circular-chaos.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 /* For ease of programming we use globals to keep refs for our floating
28 * src and sink pads we create; otherwise we always have to do get_pad,
29 * get_peer, and then remove references in every test function */
30 static GstPad *mysrcpad, *mysinkpad;
32 guint8 test_frame[] = {
33 0x77, 0x76, 0x70, 0x6B, /* "wvpk" */
34 0x2E, 0x00, 0x00, 0x00, /* ckSize */
35 0x04, 0x04, /* version */
38 0x00, 0x64, 0x00, 0x00, /* total_samples */
39 0x00, 0x00, 0x00, 0x00, /* block_index */
40 0x00, 0x64, 0x00, 0x00, /* block_samples */
41 0x05, 0x18, 0x80, 0x04, /* flags */
42 0xFF, 0xAF, 0x80, 0x60, /* crc */
43 0x02, 0x00, 0x03, 0x00, /* data */
44 0x04, 0x00, 0x05, 0x03,
45 0x00, 0x00, 0x00, 0x00,
46 0x00, 0x00, 0x8A, 0x02,
47 0x00, 0x00, 0xFF, 0x7F,
51 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
54 GST_STATIC_CAPS ("audio/x-raw-int, "
57 "channels = (int) 1, "
58 "rate = (int) 44100, "
59 "endianness = (int) BYTE_ORDER, " "signed = (boolean) true")
61 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
64 GST_STATIC_CAPS ("audio/x-wavpack, "
66 "channels = (int) 1, " "rate = (int) 44100, " "framed = (boolean) true")
70 setup_wavpackdec (void)
72 GstElement *wavpackdec;
74 GST_DEBUG ("setup_wavpackdec");
75 wavpackdec = gst_check_setup_element ("wavpackdec");
76 mysrcpad = gst_check_setup_src_pad (wavpackdec, &srctemplate, NULL);
77 mysinkpad = gst_check_setup_sink_pad (wavpackdec, &sinktemplate, NULL);
78 gst_pad_set_active (mysrcpad, TRUE);
79 gst_pad_set_active (mysinkpad, TRUE);
85 cleanup_wavpackdec (GstElement * wavpackdec)
87 GST_DEBUG ("cleanup_wavpackdec");
88 gst_element_set_state (wavpackdec, GST_STATE_NULL);
90 gst_pad_set_active (mysrcpad, FALSE);
91 gst_pad_set_active (mysinkpad, FALSE);
92 gst_check_teardown_src_pad (wavpackdec);
93 gst_check_teardown_sink_pad (wavpackdec);
94 gst_check_teardown_element (wavpackdec);
97 GST_START_TEST (test_decode_frame)
99 GstElement *wavpackdec;
100 GstBuffer *inbuffer, *outbuffer;
104 wavpackdec = setup_wavpackdec ();
106 fail_unless (gst_element_set_state (wavpackdec,
107 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
108 "could not set to playing");
109 bus = gst_bus_new ();
111 inbuffer = gst_buffer_new_and_alloc (sizeof (test_frame));
112 memcpy (GST_BUFFER_DATA (inbuffer), test_frame, sizeof (test_frame));
113 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
114 GST_BUFFER_TIMESTAMP (inbuffer) = 0;
115 gst_buffer_ref (inbuffer);
117 gst_element_set_bus (wavpackdec, bus);
119 /* should decode the buffer without problems */
120 fail_unless_equals_int (gst_pad_push (mysrcpad, inbuffer), GST_FLOW_OK);
121 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
122 gst_buffer_unref (inbuffer);
124 outbuffer = GST_BUFFER (buffers->data);
126 fail_if (outbuffer == NULL);
127 /* uncompressed data should be 102400 bytes */
128 fail_unless_equals_int (GST_BUFFER_SIZE (outbuffer), 102400);
130 /* and all 102400 bytes must be 0, i.e. silence */
131 for (i = 0; i < 102400; i++)
132 fail_unless_equals_int (GST_BUFFER_DATA (outbuffer)[i], 0);
134 ASSERT_BUFFER_REFCOUNT (outbuffer, "outbuffer", 1);
135 gst_buffer_unref (outbuffer);
138 g_list_free (buffers);
141 gst_bus_set_flushing (bus, TRUE);
142 gst_element_set_bus (wavpackdec, NULL);
143 gst_object_unref (GST_OBJECT (bus));
144 cleanup_wavpackdec (wavpackdec);
149 GST_START_TEST (test_decode_frame_with_broken_header)
151 GstElement *wavpackdec;
156 wavpackdec = setup_wavpackdec ();
158 fail_unless (gst_element_set_state (wavpackdec,
159 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
160 "could not set to playing");
161 bus = gst_bus_new ();
163 inbuffer = gst_buffer_new_and_alloc (sizeof (test_frame));
164 memcpy (GST_BUFFER_DATA (inbuffer), test_frame, sizeof (test_frame));
166 GST_BUFFER_DATA (inbuffer)[2] = 'e';
167 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
168 GST_BUFFER_TIMESTAMP (inbuffer) = 0;
169 gst_buffer_ref (inbuffer);
171 gst_element_set_bus (wavpackdec, bus);
173 /* should fail gracefully */
174 fail_unless_equals_int (gst_pad_push (mysrcpad, inbuffer), GST_FLOW_ERROR);
175 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
176 gst_buffer_unref (inbuffer);
178 fail_if ((message = gst_bus_pop (bus)) == NULL);
179 fail_unless_message_error (message, STREAM, DECODE);
180 gst_message_unref (message);
182 gst_element_set_bus (wavpackdec, NULL);
183 gst_object_unref (GST_OBJECT (bus));
184 cleanup_wavpackdec (wavpackdec);
189 GST_START_TEST (test_decode_frame_with_incomplete_frame)
191 GstElement *wavpackdec;
196 wavpackdec = setup_wavpackdec ();
198 fail_unless (gst_element_set_state (wavpackdec,
199 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
200 "could not set to playing");
201 bus = gst_bus_new ();
203 inbuffer = gst_buffer_new_and_alloc (sizeof (test_frame) - 2);
204 memcpy (GST_BUFFER_DATA (inbuffer), test_frame, sizeof (test_frame) - 2);
205 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
206 GST_BUFFER_TIMESTAMP (inbuffer) = 0;
207 gst_buffer_ref (inbuffer);
209 gst_element_set_bus (wavpackdec, bus);
211 /* should fail gracefully */
212 fail_unless_equals_int (gst_pad_push (mysrcpad, inbuffer), GST_FLOW_ERROR);
213 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
214 gst_buffer_unref (inbuffer);
216 fail_if ((message = gst_bus_pop (bus)) == NULL);
217 fail_unless_message_error (message, STREAM, DECODE);
218 gst_message_unref (message);
221 gst_element_set_bus (wavpackdec, NULL);
222 gst_object_unref (GST_OBJECT (bus));
223 cleanup_wavpackdec (wavpackdec);
229 wavpackdec_suite (void)
231 Suite *s = suite_create ("wavpackdec");
232 TCase *tc_chain = tcase_create ("general");
234 suite_add_tcase (s, tc_chain);
235 tcase_add_test (tc_chain, test_decode_frame);
236 tcase_add_test (tc_chain, test_decode_frame_with_broken_header);
237 tcase_add_test (tc_chain, test_decode_frame_with_incomplete_frame);
243 main (int argc, char **argv)
247 Suite *s = wavpackdec_suite ();
248 SRunner *sr = srunner_create (s);
250 gst_check_init (&argc, &argv);
252 srunner_run_all (sr, CK_NORMAL);
253 nf = srunner_ntests_failed (sr);