3 * unit test for audiopanorama
5 * Copyright (C) 2006 Stefan Kost <ensonic@users.sf.net>
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/base/gstbasetransform.h>
26 #include <gst/check/gstcheck.h>
28 gboolean have_eos = FALSE;
30 /* For ease of programming we use globals to keep refs for our floating
31 * src and sink pads we create; otherwise we always have to do get_pad,
32 * get_peer, and then remove references in every test function */
33 GstPad *mysrcpad, *mysinkpad;
36 #define PANORAMA_MONO_CAPS_STRING \
38 "channels = (int) 1, " \
39 "rate = (int) 44100, " \
40 "endianness = (int) BYTE_ORDER, " \
41 "width = (int) 16, " \
42 "depth = (int) 16, " \
43 "signed = (bool) TRUE"
45 #define PANORAMA_STEREO_CAPS_STRING \
47 "channels = (int) 2, " \
48 "rate = (int) 44100, " \
49 "endianness = (int) BYTE_ORDER, " \
50 "width = (int) 16, " \
51 "depth = (int) 16, " \
52 "signed = (bool) TRUE"
54 #define PANORAMA_WRONG_CAPS_STRING \
56 "channels = (int) 5, " \
57 "rate = (int) 44100, " \
58 "endianness = (int) BYTE_ORDER, " \
59 "width = (int) 16, " \
60 "depth = (int) 16, " \
61 "signed = (bool) FALSE"
64 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
67 GST_STATIC_CAPS ("audio/x-raw-int, "
68 "channels = (int) 2, "
69 "rate = (int) [ 1, MAX ], "
70 "endianness = (int) BYTE_ORDER, "
71 "width = (int) 16, " "depth = (int) 16, " "signed = (bool) TRUE")
73 static GstStaticPadTemplate msrctemplate = GST_STATIC_PAD_TEMPLATE ("src",
76 GST_STATIC_CAPS ("audio/x-raw-int, "
77 "channels = (int) 1, "
78 "rate = (int) [ 1, MAX ], "
79 "endianness = (int) BYTE_ORDER, "
80 "width = (int) 16, " "depth = (int) 16, " "signed = (bool) TRUE")
82 static GstStaticPadTemplate ssrctemplate = GST_STATIC_PAD_TEMPLATE ("src",
85 GST_STATIC_CAPS ("audio/x-raw-int, "
86 "channels = (int) 2, "
87 "rate = (int) [ 1, MAX ], "
88 "endianness = (int) BYTE_ORDER, "
89 "width = (int) 16, " "depth = (int) 16, " "signed = (bool) TRUE")
93 setup_panorama_m (void)
97 GST_DEBUG ("setup_panorama");
98 panorama = gst_check_setup_element ("audiopanorama");
99 mysrcpad = gst_check_setup_src_pad (panorama, &msrctemplate, NULL);
100 mysinkpad = gst_check_setup_sink_pad (panorama, &sinktemplate, NULL);
101 gst_pad_set_active (mysrcpad, TRUE);
102 gst_pad_set_active (mysinkpad, TRUE);
108 setup_panorama_s (void)
110 GstElement *panorama;
112 GST_DEBUG ("setup_panorama");
113 panorama = gst_check_setup_element ("audiopanorama");
114 mysrcpad = gst_check_setup_src_pad (panorama, &ssrctemplate, NULL);
115 mysinkpad = gst_check_setup_sink_pad (panorama, &sinktemplate, NULL);
116 gst_pad_set_active (mysrcpad, TRUE);
117 gst_pad_set_active (mysinkpad, TRUE);
123 cleanup_panorama (GstElement * panorama)
125 GST_DEBUG ("cleanup_panorama");
127 g_list_foreach (buffers, (GFunc) gst_mini_object_unref, NULL);
128 g_list_free (buffers);
131 gst_pad_set_active (mysrcpad, FALSE);
132 gst_pad_set_active (mysinkpad, FALSE);
133 gst_check_teardown_src_pad (panorama);
134 gst_check_teardown_sink_pad (panorama);
135 gst_check_teardown_element (panorama);
138 GST_START_TEST (test_mono_middle)
140 GstElement *panorama;
141 GstBuffer *inbuffer, *outbuffer;
143 gint16 in[2] = { 16384, -256 };
144 gint16 out[4] = { 8192, 8192, -128, -128 };
147 panorama = setup_panorama_m ();
148 fail_unless (gst_element_set_state (panorama,
149 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
150 "could not set to playing");
152 inbuffer = gst_buffer_new_and_alloc (4);
153 memcpy (GST_BUFFER_DATA (inbuffer), in, 4);
154 caps = gst_caps_from_string (PANORAMA_MONO_CAPS_STRING);
155 gst_buffer_set_caps (inbuffer, caps);
156 gst_caps_unref (caps);
157 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
159 /* pushing gives away my reference ... */
160 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
161 /* ... but it ends up being collected on the global buffer list */
162 fail_unless_equals_int (g_list_length (buffers), 1);
163 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
165 res = (gint16 *) GST_BUFFER_DATA (outbuffer);
166 GST_INFO ("expected %+5d %+5d %+5d %+5d real %+5d %+5d %+5d %+5d",
167 out[0], out[1], out[2], out[3], res[0], res[1], res[2], res[3]);
168 fail_unless (memcmp (GST_BUFFER_DATA (outbuffer), out, 8) == 0);
171 cleanup_panorama (panorama);
176 GST_START_TEST (test_mono_left)
178 GstElement *panorama;
179 GstBuffer *inbuffer, *outbuffer;
181 gint16 in[2] = { 16384, -256 };
182 gint16 out[4] = { 16384, 0, -256, 0 };
185 panorama = setup_panorama_m ();
186 g_object_set (G_OBJECT (panorama), "panorama", -1.0, NULL);
187 fail_unless (gst_element_set_state (panorama,
188 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
189 "could not set to playing");
191 inbuffer = gst_buffer_new_and_alloc (4);
192 memcpy (GST_BUFFER_DATA (inbuffer), in, 4);
193 fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 4) == 0);
194 caps = gst_caps_from_string (PANORAMA_MONO_CAPS_STRING);
195 gst_buffer_set_caps (inbuffer, caps);
196 gst_caps_unref (caps);
197 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
199 /* pushing gives away my reference ... */
200 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
201 /* ... and puts a new buffer on the global list */
202 fail_unless_equals_int (g_list_length (buffers), 1);
203 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
205 res = (gint16 *) GST_BUFFER_DATA (outbuffer);
206 GST_INFO ("expected %+5d %+5d %+5d %+5d real %+5d %+5d %+5d %+5d",
207 out[0], out[1], out[2], out[3], res[0], res[1], res[2], res[3]);
208 fail_unless (memcmp (GST_BUFFER_DATA (outbuffer), out, 8) == 0);
211 cleanup_panorama (panorama);
216 GST_START_TEST (test_mono_right)
218 GstElement *panorama;
219 GstBuffer *inbuffer, *outbuffer;
221 gint16 in[2] = { 16384, -256 };
222 gint16 out[4] = { 0, 16384, 0, -256 };
225 panorama = setup_panorama_m ();
226 g_object_set (G_OBJECT (panorama), "panorama", 1.0, NULL);
227 fail_unless (gst_element_set_state (panorama,
228 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
229 "could not set to playing");
231 inbuffer = gst_buffer_new_and_alloc (4);
232 memcpy (GST_BUFFER_DATA (inbuffer), in, 4);
233 fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 4) == 0);
234 caps = gst_caps_from_string (PANORAMA_MONO_CAPS_STRING);
235 gst_buffer_set_caps (inbuffer, caps);
236 gst_caps_unref (caps);
237 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
239 /* pushing gives away my reference ... */
240 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
241 /* ... and puts a new buffer on the global list */
242 fail_unless_equals_int (g_list_length (buffers), 1);
243 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
245 res = (gint16 *) GST_BUFFER_DATA (outbuffer);
246 GST_INFO ("expected %+5d %+5d %+5d %+5d real %+5d %+5d %+5d %+5d",
247 out[0], out[1], out[2], out[3], res[0], res[1], res[2], res[3]);
248 fail_unless (memcmp (GST_BUFFER_DATA (outbuffer), out, 8) == 0);
251 cleanup_panorama (panorama);
256 GST_START_TEST (test_stereo_middle)
258 GstElement *panorama;
259 GstBuffer *inbuffer, *outbuffer;
261 gint16 in[4] = { 16384, -256, 8192, 128 };
264 panorama = setup_panorama_s ();
265 fail_unless (gst_element_set_state (panorama,
266 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
267 "could not set to playing");
269 inbuffer = gst_buffer_new_and_alloc (8);
270 memcpy (GST_BUFFER_DATA (inbuffer), in, 8);
271 caps = gst_caps_from_string (PANORAMA_STEREO_CAPS_STRING);
272 gst_buffer_set_caps (inbuffer, caps);
273 gst_caps_unref (caps);
274 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
276 /* pushing gives away my reference ... so keep an extra one */
277 gst_buffer_ref (inbuffer);
279 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
280 /* ... but it ends up being collected on the global buffer list */
281 fail_unless_equals_int (g_list_length (buffers), 1);
282 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
284 res = (gint16 *) GST_BUFFER_DATA (inbuffer);
285 GST_INFO ("expected %+5d %+5d %+5d %+5d real %+5d %+5d %+5d %+5d",
286 in[0], in[1], in[2], in[3], res[0], res[1], res[2], res[3]);
287 fail_unless (memcmp (GST_BUFFER_DATA (outbuffer), in, 8) == 0);
290 gst_buffer_unref (inbuffer);
291 cleanup_panorama (panorama);
296 GST_START_TEST (test_stereo_left)
298 GstElement *panorama;
299 GstBuffer *inbuffer, *outbuffer;
301 gint16 in[4] = { 16384, -256, 8192, 128 };
302 gint16 out[4] = { 16384 - 256, 0, 8192 + 128, 0 };
305 panorama = setup_panorama_s ();
306 g_object_set (G_OBJECT (panorama), "panorama", -1.0, NULL);
307 fail_unless (gst_element_set_state (panorama,
308 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
309 "could not set to playing");
311 inbuffer = gst_buffer_new_and_alloc (8);
312 memcpy (GST_BUFFER_DATA (inbuffer), in, 8);
313 fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 8) == 0);
314 caps = gst_caps_from_string (PANORAMA_STEREO_CAPS_STRING);
315 gst_buffer_set_caps (inbuffer, caps);
316 gst_caps_unref (caps);
317 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
319 /* pushing gives away my reference ... */
320 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
321 /* ... and puts a new buffer on the global list */
322 fail_unless_equals_int (g_list_length (buffers), 1);
323 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
325 res = (gint16 *) GST_BUFFER_DATA (outbuffer);
326 GST_INFO ("expected %+5d %+5d %+5d %+5d real %+5d %+5d %+5d %+5d",
327 out[0], out[1], out[2], out[3], res[0], res[1], res[2], res[3]);
328 fail_unless (memcmp (GST_BUFFER_DATA (outbuffer), out, 8) == 0);
331 cleanup_panorama (panorama);
336 GST_START_TEST (test_stereo_right)
338 GstElement *panorama;
339 GstBuffer *inbuffer, *outbuffer;
341 gint16 in[4] = { 16384, -256, 8192, 128 };
342 gint16 out[4] = { 0, -256 + 16384, 0, 128 + 8192 };
345 panorama = setup_panorama_s ();
346 g_object_set (G_OBJECT (panorama), "panorama", 1.0, NULL);
347 fail_unless (gst_element_set_state (panorama,
348 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
349 "could not set to playing");
351 inbuffer = gst_buffer_new_and_alloc (8);
352 memcpy (GST_BUFFER_DATA (inbuffer), in, 8);
353 fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 8) == 0);
354 caps = gst_caps_from_string (PANORAMA_STEREO_CAPS_STRING);
355 gst_buffer_set_caps (inbuffer, caps);
356 gst_caps_unref (caps);
357 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
359 /* pushing gives away my reference ... */
360 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
361 /* ... and puts a new buffer on the global list */
362 fail_unless_equals_int (g_list_length (buffers), 1);
363 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
365 res = (gint16 *) GST_BUFFER_DATA (outbuffer);
366 GST_INFO ("expected %+5d %+5d %+5d %+5d real %+5d %+5d %+5d %+5d",
367 out[0], out[1], out[2], out[3], res[0], res[1], res[2], res[3]);
368 fail_unless (memcmp (GST_BUFFER_DATA (outbuffer), out, 8) == 0);
371 cleanup_panorama (panorama);
376 GST_START_TEST (test_mono_middle_simple)
378 GstElement *panorama;
379 GstBuffer *inbuffer, *outbuffer;
381 gint16 in[2] = { 16384, -256 };
382 gint16 out[4] = { 16384, 16384, -256, -256 };
385 panorama = setup_panorama_m ();
386 g_object_set (G_OBJECT (panorama), "method", 1, NULL);
387 fail_unless (gst_element_set_state (panorama,
388 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
389 "could not set to playing");
391 inbuffer = gst_buffer_new_and_alloc (4);
392 memcpy (GST_BUFFER_DATA (inbuffer), in, 4);
393 caps = gst_caps_from_string (PANORAMA_MONO_CAPS_STRING);
394 gst_buffer_set_caps (inbuffer, caps);
395 gst_caps_unref (caps);
396 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
398 /* pushing gives away my reference ... */
399 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
400 /* ... but it ends up being collected on the global buffer list */
401 fail_unless_equals_int (g_list_length (buffers), 1);
402 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
404 res = (gint16 *) GST_BUFFER_DATA (outbuffer);
405 GST_INFO ("expected %+5d %+5d %+5d %+5d real %+5d %+5d %+5d %+5d",
406 out[0], out[1], out[2], out[3], res[0], res[1], res[2], res[3]);
407 fail_unless (memcmp (GST_BUFFER_DATA (outbuffer), out, 8) == 0);
410 cleanup_panorama (panorama);
415 GST_START_TEST (test_mono_left_simple)
417 GstElement *panorama;
418 GstBuffer *inbuffer, *outbuffer;
420 gint16 in[2] = { 16384, -256 };
421 gint16 out[4] = { 16384, 0, -256, 0 };
424 panorama = setup_panorama_m ();
425 g_object_set (G_OBJECT (panorama), "method", 1, NULL);
426 g_object_set (G_OBJECT (panorama), "panorama", -1.0, NULL);
427 fail_unless (gst_element_set_state (panorama,
428 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
429 "could not set to playing");
431 inbuffer = gst_buffer_new_and_alloc (4);
432 memcpy (GST_BUFFER_DATA (inbuffer), in, 4);
433 fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 4) == 0);
434 caps = gst_caps_from_string (PANORAMA_MONO_CAPS_STRING);
435 gst_buffer_set_caps (inbuffer, caps);
436 gst_caps_unref (caps);
437 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
439 /* pushing gives away my reference ... */
440 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
441 /* ... and puts a new buffer on the global list */
442 fail_unless_equals_int (g_list_length (buffers), 1);
443 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
445 res = (gint16 *) GST_BUFFER_DATA (outbuffer);
446 GST_INFO ("expected %+5d %+5d %+5d %+5d real %+5d %+5d %+5d %+5d",
447 out[0], out[1], out[2], out[3], res[0], res[1], res[2], res[3]);
448 fail_unless (memcmp (GST_BUFFER_DATA (outbuffer), out, 8) == 0);
451 cleanup_panorama (panorama);
456 GST_START_TEST (test_mono_right_simple)
458 GstElement *panorama;
459 GstBuffer *inbuffer, *outbuffer;
461 gint16 in[2] = { 16384, -256 };
462 gint16 out[4] = { 0, 16384, 0, -256 };
465 panorama = setup_panorama_m ();
466 g_object_set (G_OBJECT (panorama), "method", 1, NULL);
467 g_object_set (G_OBJECT (panorama), "panorama", 1.0, NULL);
468 fail_unless (gst_element_set_state (panorama,
469 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
470 "could not set to playing");
472 inbuffer = gst_buffer_new_and_alloc (4);
473 memcpy (GST_BUFFER_DATA (inbuffer), in, 4);
474 fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 4) == 0);
475 caps = gst_caps_from_string (PANORAMA_MONO_CAPS_STRING);
476 gst_buffer_set_caps (inbuffer, caps);
477 gst_caps_unref (caps);
478 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
480 /* pushing gives away my reference ... */
481 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
482 /* ... and puts a new buffer on the global list */
483 fail_unless_equals_int (g_list_length (buffers), 1);
484 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
486 res = (gint16 *) GST_BUFFER_DATA (outbuffer);
487 GST_INFO ("expected %+5d %+5d %+5d %+5d real %+5d %+5d %+5d %+5d",
488 out[0], out[1], out[2], out[3], res[0], res[1], res[2], res[3]);
489 fail_unless (memcmp (GST_BUFFER_DATA (outbuffer), out, 8) == 0);
492 cleanup_panorama (panorama);
497 GST_START_TEST (test_stereo_middle_simple)
499 GstElement *panorama;
500 GstBuffer *inbuffer, *outbuffer;
502 gint16 in[4] = { 16384, -256, 8192, 128 };
505 panorama = setup_panorama_s ();
506 g_object_set (G_OBJECT (panorama), "method", 1, NULL);
507 fail_unless (gst_element_set_state (panorama,
508 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
509 "could not set to playing");
511 inbuffer = gst_buffer_new_and_alloc (8);
512 memcpy (GST_BUFFER_DATA (inbuffer), in, 8);
513 caps = gst_caps_from_string (PANORAMA_STEREO_CAPS_STRING);
514 gst_buffer_set_caps (inbuffer, caps);
515 gst_caps_unref (caps);
516 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
518 /* pushing gives away my reference ... so keep an extra one */
519 gst_buffer_ref (inbuffer);
521 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
522 /* ... but it ends up being collected on the global buffer list */
523 fail_unless_equals_int (g_list_length (buffers), 1);
524 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
526 res = (gint16 *) GST_BUFFER_DATA (inbuffer);
527 GST_INFO ("expected %+5d %+5d %+5d %+5d real %+5d %+5d %+5d %+5d",
528 in[0], in[1], in[2], in[3], res[0], res[1], res[2], res[3]);
529 fail_unless (memcmp (GST_BUFFER_DATA (outbuffer), in, 8) == 0);
532 gst_buffer_unref (inbuffer);
533 cleanup_panorama (panorama);
538 GST_START_TEST (test_stereo_left_simple)
540 GstElement *panorama;
541 GstBuffer *inbuffer, *outbuffer;
543 gint16 in[4] = { 16384, -256, 8192, 128 };
544 gint16 out[4] = { 16384, 0, 8192, 0 };
547 panorama = setup_panorama_s ();
548 g_object_set (G_OBJECT (panorama), "method", 1, NULL);
549 g_object_set (G_OBJECT (panorama), "panorama", -1.0, NULL);
550 fail_unless (gst_element_set_state (panorama,
551 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
552 "could not set to playing");
554 inbuffer = gst_buffer_new_and_alloc (8);
555 memcpy (GST_BUFFER_DATA (inbuffer), in, 8);
556 fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 8) == 0);
557 caps = gst_caps_from_string (PANORAMA_STEREO_CAPS_STRING);
558 gst_buffer_set_caps (inbuffer, caps);
559 gst_caps_unref (caps);
560 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
562 /* pushing gives away my reference ... */
563 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
564 /* ... and puts a new buffer on the global list */
565 fail_unless_equals_int (g_list_length (buffers), 1);
566 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
568 res = (gint16 *) GST_BUFFER_DATA (outbuffer);
569 GST_INFO ("expected %+5d %+5d %+5d %+5d real %+5d %+5d %+5d %+5d",
570 out[0], out[1], out[2], out[3], res[0], res[1], res[2], res[3]);
571 fail_unless (memcmp (GST_BUFFER_DATA (outbuffer), out, 8) == 0);
574 cleanup_panorama (panorama);
579 GST_START_TEST (test_stereo_right_simple)
581 GstElement *panorama;
582 GstBuffer *inbuffer, *outbuffer;
584 gint16 in[4] = { 16384, -256, 8192, 128 };
585 gint16 out[4] = { 0, -256, 0, 128 };
588 panorama = setup_panorama_s ();
589 g_object_set (G_OBJECT (panorama), "method", 1, NULL);
590 g_object_set (G_OBJECT (panorama), "panorama", 1.0, NULL);
591 fail_unless (gst_element_set_state (panorama,
592 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
593 "could not set to playing");
595 inbuffer = gst_buffer_new_and_alloc (8);
596 memcpy (GST_BUFFER_DATA (inbuffer), in, 8);
597 fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 8) == 0);
598 caps = gst_caps_from_string (PANORAMA_STEREO_CAPS_STRING);
599 gst_buffer_set_caps (inbuffer, caps);
600 gst_caps_unref (caps);
601 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
603 /* pushing gives away my reference ... */
604 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
605 /* ... and puts a new buffer on the global list */
606 fail_unless_equals_int (g_list_length (buffers), 1);
607 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
609 res = (gint16 *) GST_BUFFER_DATA (outbuffer);
610 GST_INFO ("expected %+5d %+5d %+5d %+5d real %+5d %+5d %+5d %+5d",
611 out[0], out[1], out[2], out[3], res[0], res[1], res[2], res[3]);
612 fail_unless (memcmp (GST_BUFFER_DATA (outbuffer), out, 8) == 0);
615 cleanup_panorama (panorama);
620 GST_START_TEST (test_wrong_caps)
622 GstElement *panorama;
624 gint16 in[2] = { 16384, -256 };
629 panorama = setup_panorama_m ();
630 bus = gst_bus_new ();
632 fail_unless (gst_element_set_state (panorama,
633 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
634 "could not set to playing");
636 inbuffer = gst_buffer_new_and_alloc (4);
637 memcpy (GST_BUFFER_DATA (inbuffer), in, 4);
638 caps = gst_caps_from_string (PANORAMA_WRONG_CAPS_STRING);
639 gst_buffer_set_caps (inbuffer, caps);
640 gst_caps_unref (caps);
641 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
642 gst_buffer_ref (inbuffer);
644 /* set a bus here so we avoid getting state change messages */
645 gst_element_set_bus (panorama, bus);
647 /* pushing gives an error because it can't negotiate with wrong caps */
648 fail_unless_equals_int (gst_pad_push (mysrcpad, inbuffer),
649 GST_FLOW_NOT_NEGOTIATED);
650 /* ... and the buffer would have been lost if we didn't ref it ourselves */
651 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
652 gst_buffer_unref (inbuffer);
653 fail_unless_equals_int (g_list_length (buffers), 0);
655 /* panorama_set_caps should not have been called since basetransform caught
656 * the negotiation problem */
657 fail_if ((message = gst_bus_pop (bus)) != NULL);
660 gst_element_set_bus (panorama, NULL);
661 gst_object_unref (GST_OBJECT (bus));
662 cleanup_panorama (panorama);
669 panorama_suite (void)
671 Suite *s = suite_create ("panorama");
672 TCase *tc_chain = tcase_create ("general");
674 suite_add_tcase (s, tc_chain);
675 tcase_add_test (tc_chain, test_mono_middle);
676 tcase_add_test (tc_chain, test_mono_left);
677 tcase_add_test (tc_chain, test_mono_right);
678 tcase_add_test (tc_chain, test_stereo_middle);
679 tcase_add_test (tc_chain, test_stereo_left);
680 tcase_add_test (tc_chain, test_stereo_right);
681 tcase_add_test (tc_chain, test_mono_middle_simple);
682 tcase_add_test (tc_chain, test_mono_left_simple);
683 tcase_add_test (tc_chain, test_mono_right_simple);
684 tcase_add_test (tc_chain, test_stereo_middle_simple);
685 tcase_add_test (tc_chain, test_stereo_left_simple);
686 tcase_add_test (tc_chain, test_stereo_right_simple);
687 tcase_add_test (tc_chain, test_wrong_caps);
693 main (int argc, char **argv)
697 Suite *s = panorama_suite ();
698 SRunner *sr = srunner_create (s);
700 gst_check_init (&argc, &argv);
702 srunner_run_all (sr, CK_NORMAL);
703 nf = srunner_ntests_failed (sr);