Tizen 2.0 Release
[framework/multimedia/gst-plugins-good0.10.git] / tests / check / elements / audiopanorama.c
1 /* GStreamer
2  *
3  * unit test for audiopanorama
4  *
5  * Copyright (C) 2006 Stefan Kost <ensonic@users.sf.net>
6  *
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.
11  *
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.
16  *
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.
21  */
22
23 #include <unistd.h>
24
25 #include <gst/base/gstbasetransform.h>
26 #include <gst/check/gstcheck.h>
27
28 gboolean have_eos = FALSE;
29
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;
34
35
36 #define PANORAMA_MONO_CAPS_STRING    \
37     "audio/x-raw-int, "                 \
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"
44
45 #define PANORAMA_STEREO_CAPS_STRING  \
46     "audio/x-raw-int, "                 \
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"
53
54 #define PANORAMA_WRONG_CAPS_STRING  \
55     "audio/x-raw-int, "                 \
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"
62
63
64 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
65     GST_PAD_SINK,
66     GST_PAD_ALWAYS,
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")
72     );
73 static GstStaticPadTemplate msrctemplate = GST_STATIC_PAD_TEMPLATE ("src",
74     GST_PAD_SRC,
75     GST_PAD_ALWAYS,
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")
81     );
82 static GstStaticPadTemplate ssrctemplate = GST_STATIC_PAD_TEMPLATE ("src",
83     GST_PAD_SRC,
84     GST_PAD_ALWAYS,
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")
90     );
91
92 static GstElement *
93 setup_panorama_m (void)
94 {
95   GstElement *panorama;
96
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);
103
104   return panorama;
105 }
106
107 static GstElement *
108 setup_panorama_s (void)
109 {
110   GstElement *panorama;
111
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);
118
119   return panorama;
120 }
121
122 static void
123 cleanup_panorama (GstElement * panorama)
124 {
125   GST_DEBUG ("cleanup_panorama");
126
127   g_list_foreach (buffers, (GFunc) gst_mini_object_unref, NULL);
128   g_list_free (buffers);
129   buffers = NULL;
130
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);
136 }
137
138 GST_START_TEST (test_mono_middle)
139 {
140   GstElement *panorama;
141   GstBuffer *inbuffer, *outbuffer;
142   GstCaps *caps;
143   gint16 in[2] = { 16384, -256 };
144   gint16 out[4] = { 8192, 8192, -128, -128 };
145   gint16 *res;
146
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");
151
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);
158
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);
164
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);
169
170   /* cleanup */
171   cleanup_panorama (panorama);
172 }
173
174 GST_END_TEST;
175
176 GST_START_TEST (test_mono_left)
177 {
178   GstElement *panorama;
179   GstBuffer *inbuffer, *outbuffer;
180   GstCaps *caps;
181   gint16 in[2] = { 16384, -256 };
182   gint16 out[4] = { 16384, 0, -256, 0 };
183   gint16 *res;
184
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");
190
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);
198
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);
204
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);
209
210   /* cleanup */
211   cleanup_panorama (panorama);
212 }
213
214 GST_END_TEST;
215
216 GST_START_TEST (test_mono_right)
217 {
218   GstElement *panorama;
219   GstBuffer *inbuffer, *outbuffer;
220   GstCaps *caps;
221   gint16 in[2] = { 16384, -256 };
222   gint16 out[4] = { 0, 16384, 0, -256 };
223   gint16 *res;
224
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");
230
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);
238
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);
244
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);
249
250   /* cleanup */
251   cleanup_panorama (panorama);
252 }
253
254 GST_END_TEST;
255
256 GST_START_TEST (test_stereo_middle)
257 {
258   GstElement *panorama;
259   GstBuffer *inbuffer, *outbuffer;
260   GstCaps *caps;
261   gint16 in[4] = { 16384, -256, 8192, 128 };
262   gint16 *res;
263
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");
268
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);
275
276   /* pushing gives away my reference ... so keep an extra one */
277   gst_buffer_ref (inbuffer);
278
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);
283
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);
288
289   /* cleanup */
290   gst_buffer_unref (inbuffer);
291   cleanup_panorama (panorama);
292 }
293
294 GST_END_TEST;
295
296 GST_START_TEST (test_stereo_left)
297 {
298   GstElement *panorama;
299   GstBuffer *inbuffer, *outbuffer;
300   GstCaps *caps;
301   gint16 in[4] = { 16384, -256, 8192, 128 };
302   gint16 out[4] = { 16384 - 256, 0, 8192 + 128, 0 };
303   gint16 *res;
304
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");
310
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);
318
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);
324
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);
329
330   /* cleanup */
331   cleanup_panorama (panorama);
332 }
333
334 GST_END_TEST;
335
336 GST_START_TEST (test_stereo_right)
337 {
338   GstElement *panorama;
339   GstBuffer *inbuffer, *outbuffer;
340   GstCaps *caps;
341   gint16 in[4] = { 16384, -256, 8192, 128 };
342   gint16 out[4] = { 0, -256 + 16384, 0, 128 + 8192 };
343   gint16 *res;
344
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");
350
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);
358
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);
364
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);
369
370   /* cleanup */
371   cleanup_panorama (panorama);
372 }
373
374 GST_END_TEST;
375
376 GST_START_TEST (test_mono_middle_simple)
377 {
378   GstElement *panorama;
379   GstBuffer *inbuffer, *outbuffer;
380   GstCaps *caps;
381   gint16 in[2] = { 16384, -256 };
382   gint16 out[4] = { 16384, 16384, -256, -256 };
383   gint16 *res;
384
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");
390
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);
397
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);
403
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);
408
409   /* cleanup */
410   cleanup_panorama (panorama);
411 }
412
413 GST_END_TEST;
414
415 GST_START_TEST (test_mono_left_simple)
416 {
417   GstElement *panorama;
418   GstBuffer *inbuffer, *outbuffer;
419   GstCaps *caps;
420   gint16 in[2] = { 16384, -256 };
421   gint16 out[4] = { 16384, 0, -256, 0 };
422   gint16 *res;
423
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");
430
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);
438
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);
444
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);
449
450   /* cleanup */
451   cleanup_panorama (panorama);
452 }
453
454 GST_END_TEST;
455
456 GST_START_TEST (test_mono_right_simple)
457 {
458   GstElement *panorama;
459   GstBuffer *inbuffer, *outbuffer;
460   GstCaps *caps;
461   gint16 in[2] = { 16384, -256 };
462   gint16 out[4] = { 0, 16384, 0, -256 };
463   gint16 *res;
464
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");
471
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);
479
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);
485
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);
490
491   /* cleanup */
492   cleanup_panorama (panorama);
493 }
494
495 GST_END_TEST;
496
497 GST_START_TEST (test_stereo_middle_simple)
498 {
499   GstElement *panorama;
500   GstBuffer *inbuffer, *outbuffer;
501   GstCaps *caps;
502   gint16 in[4] = { 16384, -256, 8192, 128 };
503   gint16 *res;
504
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");
510
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);
517
518   /* pushing gives away my reference ... so keep an extra one */
519   gst_buffer_ref (inbuffer);
520
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);
525
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);
530
531   /* cleanup */
532   gst_buffer_unref (inbuffer);
533   cleanup_panorama (panorama);
534 }
535
536 GST_END_TEST;
537
538 GST_START_TEST (test_stereo_left_simple)
539 {
540   GstElement *panorama;
541   GstBuffer *inbuffer, *outbuffer;
542   GstCaps *caps;
543   gint16 in[4] = { 16384, -256, 8192, 128 };
544   gint16 out[4] = { 16384, 0, 8192, 0 };
545   gint16 *res;
546
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");
553
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);
561
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);
567
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);
572
573   /* cleanup */
574   cleanup_panorama (panorama);
575 }
576
577 GST_END_TEST;
578
579 GST_START_TEST (test_stereo_right_simple)
580 {
581   GstElement *panorama;
582   GstBuffer *inbuffer, *outbuffer;
583   GstCaps *caps;
584   gint16 in[4] = { 16384, -256, 8192, 128 };
585   gint16 out[4] = { 0, -256, 0, 128 };
586   gint16 *res;
587
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");
594
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);
602
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);
608
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);
613
614   /* cleanup */
615   cleanup_panorama (panorama);
616 }
617
618 GST_END_TEST;
619
620 GST_START_TEST (test_wrong_caps)
621 {
622   GstElement *panorama;
623   GstBuffer *inbuffer;
624   gint16 in[2] = { 16384, -256 };
625   GstBus *bus;
626   GstMessage *message;
627   GstCaps *caps;
628
629   panorama = setup_panorama_m ();
630   bus = gst_bus_new ();
631
632   fail_unless (gst_element_set_state (panorama,
633           GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
634       "could not set to playing");
635
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);
643
644   /* set a bus here so we avoid getting state change messages */
645   gst_element_set_bus (panorama, bus);
646
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);
654
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);
658
659   /* cleanup */
660   gst_element_set_bus (panorama, NULL);
661   gst_object_unref (GST_OBJECT (bus));
662   cleanup_panorama (panorama);
663 }
664
665 GST_END_TEST;
666
667
668 static Suite *
669 panorama_suite (void)
670 {
671   Suite *s = suite_create ("panorama");
672   TCase *tc_chain = tcase_create ("general");
673
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);
688
689   return s;
690 }
691
692 int
693 main (int argc, char **argv)
694 {
695   int nf;
696
697   Suite *s = panorama_suite ();
698   SRunner *sr = srunner_create (s);
699
700   gst_check_init (&argc, &argv);
701
702   srunner_run_all (sr, CK_NORMAL);
703   nf = srunner_ntests_failed (sr);
704   srunner_free (sr);
705
706   return nf;
707 }