2 * Copyright (C) 2005 Andy Wingo <wingo@pobox.com>
3 * Copyright (C) <2005> Thomas Vander Stichele <thomas at apestaart dot org>
5 * gstcaps.c: Unit test for GstCaps
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.
24 #include <gst/check/gstcheck.h>
25 #include <gst/gstcaps.h>
28 GST_START_TEST (test_from_string)
35 for (i = 0; i < G_N_ELEMENTS (caps_list); i++) {
36 caps = gst_caps_from_string (caps_list[i]);
37 fail_if (caps == NULL,
38 "Could not create caps from string %s\n", caps_list[i]);
39 to_str = gst_caps_to_string (caps);
40 fail_if (to_str == NULL,
41 "Could not convert caps back to string %s\n", caps_list[i]);
42 caps2 = gst_caps_from_string (caps_list[i]);
43 fail_if (caps2 == NULL, "Could not create caps from string %s\n", to_str);
45 fail_unless (gst_caps_is_equal (caps, caps));
46 fail_unless (gst_caps_is_equal (caps, caps2));
48 gst_caps_unref (caps);
49 gst_caps_unref (caps2);
56 GST_START_TEST (test_double_append)
61 c1 = gst_caps_new_any ();
62 s1 = gst_structure_from_string ("audio/x-raw-int,rate=44100", NULL);
63 gst_caps_append_structure (c1, s1);
64 ASSERT_CRITICAL (gst_caps_append_structure (c1, s1));
71 GST_START_TEST (test_mutability)
77 c1 = gst_caps_new_any ();
78 s1 = gst_structure_from_string ("audio/x-raw-int,rate=44100", NULL);
79 gst_structure_set (s1, "rate", G_TYPE_INT, 48000, NULL);
80 gst_caps_append_structure (c1, s1);
81 gst_structure_set (s1, "rate", G_TYPE_INT, 22500, NULL);
83 ASSERT_CRITICAL (gst_structure_set (s1, "rate", G_TYPE_INT, 11250, NULL));
84 fail_unless (gst_structure_get_int (s1, "rate", &ret));
85 fail_unless (ret == 22500);
86 ASSERT_CRITICAL (gst_caps_set_simple (c1, "rate", G_TYPE_INT, 11250, NULL));
87 fail_unless (gst_structure_get_int (s1, "rate", &ret));
88 fail_unless (ret == 22500);
90 gst_structure_set (s1, "rate", G_TYPE_INT, 11250, NULL);
91 fail_unless (gst_structure_get_int (s1, "rate", &ret));
92 fail_unless (ret == 11250);
93 gst_caps_set_simple (c1, "rate", G_TYPE_INT, 1, NULL);
94 fail_unless (gst_structure_get_int (s1, "rate", &ret));
95 fail_unless (ret == 1);
101 GST_START_TEST (test_static_caps)
103 static GstStaticCaps scaps = GST_STATIC_CAPS ("audio/x-raw-int,rate=44100");
108 caps1 = gst_static_caps_get (&scaps);
109 fail_unless (caps1 != NULL);
110 /* 1 refcount core, one from us */
111 fail_unless (GST_CAPS_REFCOUNT (caps1) == 2);
113 /* caps should be the same */
114 caps2 = gst_static_caps_get (&scaps);
115 fail_unless (caps2 != NULL);
116 /* 1 refcount core, two from us */
117 fail_unless (GST_CAPS_REFCOUNT (caps1) == 3);
118 /* caps must be equal */
119 fail_unless (caps1 == caps2);
121 gst_caps_unref (caps1);
122 gst_caps_unref (caps2);
127 static const gchar non_simple_caps_string[] =
128 "video/x-raw-yuv, format=(fourcc)I420, framerate=(fraction)[ 1/100, 100 ], "
129 "width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ]; video/x-raw-yuv, "
130 "format=(fourcc)YUY2, framerate=(fraction)[ 1/100, 100 ], width=(int)[ 16, 4096 ], "
131 "height=(int)[ 16, 4096 ]; video/x-raw-rgb, bpp=(int)8, depth=(int)8, "
132 "endianness=(int)1234, framerate=(fraction)[ 1/100, 100 ], width=(int)[ 16, 4096 ], "
133 "height=(int)[ 16, 4096 ]; video/x-raw-yuv, "
134 "format=(fourcc){ I420, YUY2, YV12 }, width=(int)[ 16, 4096 ], "
135 "height=(int)[ 16, 4096 ], framerate=(fraction)[ 1/100, 100 ]";
138 check_fourcc_list (const GValue * format_value)
140 const GValue *fourcc_value;
141 gboolean got_yv12 = FALSE;
142 gboolean got_i420 = FALSE;
143 gboolean got_yuy2 = FALSE;
146 fourcc_value = gst_value_list_get_value (format_value, 0);
147 fail_unless (fourcc_value != NULL);
148 fail_unless (GST_VALUE_HOLDS_FOURCC (fourcc_value));
149 fourcc = gst_value_get_fourcc (fourcc_value);
150 fail_unless (fourcc != 0);
151 got_i420 = got_i420 || (fourcc == GST_STR_FOURCC ("I420"));
152 got_yuy2 = got_yuy2 || (fourcc == GST_STR_FOURCC ("YUY2"));
153 got_yv12 = got_yv12 || (fourcc == GST_STR_FOURCC ("YV12"));
155 fourcc_value = gst_value_list_get_value (format_value, 1);
156 fail_unless (fourcc_value != NULL);
157 fail_unless (GST_VALUE_HOLDS_FOURCC (fourcc_value));
158 fourcc = gst_value_get_fourcc (fourcc_value);
159 fail_unless (fourcc != 0);
160 got_i420 = got_i420 || (fourcc == GST_STR_FOURCC ("I420"));
161 got_yuy2 = got_yuy2 || (fourcc == GST_STR_FOURCC ("YUY2"));
162 got_yv12 = got_yv12 || (fourcc == GST_STR_FOURCC ("YV12"));
164 fourcc_value = gst_value_list_get_value (format_value, 2);
165 fail_unless (fourcc_value != NULL);
166 fail_unless (GST_VALUE_HOLDS_FOURCC (fourcc_value));
167 fourcc = gst_value_get_fourcc (fourcc_value);
168 fail_unless (fourcc != 0);
169 got_i420 = got_i420 || (fourcc == GST_STR_FOURCC ("I420"));
170 got_yuy2 = got_yuy2 || (fourcc == GST_STR_FOURCC ("YUY2"));
171 got_yv12 = got_yv12 || (fourcc == GST_STR_FOURCC ("YV12"));
173 return (got_i420 && got_yuy2 && got_yv12);
176 GST_START_TEST (test_simplify)
178 GstStructure *s1, *s2;
179 gboolean did_simplify;
182 caps = gst_caps_from_string (non_simple_caps_string);
183 fail_unless (caps != NULL,
184 "gst_caps_from_string (non_simple_caps_string) failed");
186 did_simplify = gst_caps_do_simplify (caps);
187 fail_unless (did_simplify == TRUE,
188 "gst_caps_do_simplify() should have worked");
190 /* check simplified caps, should be:
192 * video/x-raw-rgb, bpp=(int)8, depth=(int)8, endianness=(int)1234,
193 * framerate=(fraction)[ 1/100, 100 ], width=(int)[ 16, 4096 ],
194 * height=(int)[ 16, 4096 ];
195 * video/x-raw-yuv, format=(fourcc){ YV12, YUY2, I420 },
196 * width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ],
197 * framerate=(fraction)[ 1/100, 100 ]
199 fail_unless (gst_caps_get_size (caps) == 2);
200 s1 = gst_caps_get_structure (caps, 0);
201 s2 = gst_caps_get_structure (caps, 1);
202 fail_unless (s1 != NULL);
203 fail_unless (s2 != NULL);
205 if (!gst_structure_has_name (s1, "video/x-raw-rgb")) {
213 fail_unless (gst_structure_has_name (s1, "video/x-raw-rgb"));
215 const GValue *framerate_value;
216 const GValue *width_value;
217 const GValue *height_value;
218 const GValue *val_fps;
219 GValue test_fps = { 0, };
220 gint bpp, depth, endianness;
221 gint min_width, max_width;
222 gint min_height, max_height;
224 fail_unless (gst_structure_get_int (s1, "bpp", &bpp));
225 fail_unless (bpp == 8);
227 fail_unless (gst_structure_get_int (s1, "depth", &depth));
228 fail_unless (depth == 8);
230 fail_unless (gst_structure_get_int (s1, "endianness", &endianness));
231 fail_unless (endianness == G_LITTLE_ENDIAN);
233 g_value_init (&test_fps, GST_TYPE_FRACTION);
234 framerate_value = gst_structure_get_value (s1, "framerate");
235 fail_unless (framerate_value != NULL);
236 fail_unless (GST_VALUE_HOLDS_FRACTION_RANGE (framerate_value));
238 val_fps = gst_value_get_fraction_range_min (framerate_value);
239 gst_value_set_fraction (&test_fps, 1, 100);
240 fail_unless (gst_value_compare (&test_fps, val_fps) == GST_VALUE_EQUAL);
242 val_fps = gst_value_get_fraction_range_max (framerate_value);
243 gst_value_set_fraction (&test_fps, 100, 1);
244 fail_unless (gst_value_compare (&test_fps, val_fps) == GST_VALUE_EQUAL);
246 g_value_unset (&test_fps);
248 width_value = gst_structure_get_value (s1, "width");
249 fail_unless (width_value != NULL);
250 fail_unless (GST_VALUE_HOLDS_INT_RANGE (width_value));
251 min_width = gst_value_get_int_range_min (width_value);
252 max_width = gst_value_get_int_range_max (width_value);
253 fail_unless (min_width == 16 && max_width == 4096);
255 height_value = gst_structure_get_value (s1, "height");
256 fail_unless (height_value != NULL);
257 fail_unless (GST_VALUE_HOLDS_INT_RANGE (height_value));
258 min_height = gst_value_get_int_range_min (height_value);
259 max_height = gst_value_get_int_range_max (height_value);
260 fail_unless (min_height == 16 && max_height == 4096);
263 fail_unless (gst_structure_has_name (s2, "video/x-raw-yuv"));
265 const GValue *framerate_value;
266 const GValue *format_value;
267 const GValue *width_value;
268 const GValue *height_value;
269 const GValue *val_fps;
270 GValue test_fps = { 0, };
271 gint min_width, max_width;
272 gint min_height, max_height;
274 format_value = gst_structure_get_value (s2, "format");
275 fail_unless (format_value != NULL);
276 fail_unless (GST_VALUE_HOLDS_LIST (format_value));
277 fail_unless (gst_value_list_get_size (format_value) == 3);
278 fail_unless (check_fourcc_list (format_value) == TRUE);
280 g_value_init (&test_fps, GST_TYPE_FRACTION);
281 framerate_value = gst_structure_get_value (s2, "framerate");
282 fail_unless (framerate_value != NULL);
283 fail_unless (GST_VALUE_HOLDS_FRACTION_RANGE (framerate_value));
285 val_fps = gst_value_get_fraction_range_min (framerate_value);
286 gst_value_set_fraction (&test_fps, 1, 100);
287 fail_unless (gst_value_compare (&test_fps, val_fps) == GST_VALUE_EQUAL);
289 val_fps = gst_value_get_fraction_range_max (framerate_value);
290 gst_value_set_fraction (&test_fps, 100, 1);
291 fail_unless (gst_value_compare (&test_fps, val_fps) == GST_VALUE_EQUAL);
293 g_value_unset (&test_fps);
295 width_value = gst_structure_get_value (s2, "width");
296 fail_unless (width_value != NULL);
297 fail_unless (GST_VALUE_HOLDS_INT_RANGE (width_value));
298 min_width = gst_value_get_int_range_min (width_value);
299 max_width = gst_value_get_int_range_max (width_value);
300 fail_unless (min_width == 16 && max_width == 4096);
302 height_value = gst_structure_get_value (s2, "height");
303 fail_unless (height_value != NULL);
304 fail_unless (GST_VALUE_HOLDS_INT_RANGE (height_value));
305 min_height = gst_value_get_int_range_min (height_value);
306 max_height = gst_value_get_int_range_max (height_value);
307 fail_unless (min_height == 16 && max_height == 4096);
310 gst_caps_unref (caps);
315 GST_START_TEST (test_truncate)
319 caps = gst_caps_from_string (non_simple_caps_string);
320 fail_unless (caps != NULL,
321 "gst_caps_from_string (non_simple_caps_string) failed");
322 fail_unless_equals_int (gst_caps_get_size (caps), 4);
323 gst_caps_truncate (caps);
324 fail_unless_equals_int (gst_caps_get_size (caps), 1);
325 gst_caps_unref (caps);
330 GST_START_TEST (test_subset)
334 c1 = gst_caps_from_string ("video/x-raw-yuv; video/x-raw-rgb");
335 c2 = gst_caps_from_string ("video/x-raw-yuv, format=(fourcc)YUY2");
336 fail_unless (gst_caps_is_subset (c2, c1));
337 fail_if (gst_caps_is_subset (c1, c2));
341 c1 = gst_caps_from_string
342 ("audio/x-raw-int, channels=(int)[ 1, 2 ], rate=(int)44100");
343 c2 = gst_caps_from_string
344 ("audio/x-raw-int, channels=(int)1, rate=(int)44100");
345 fail_unless (gst_caps_is_subset (c2, c1));
346 fail_if (gst_caps_is_subset (c1, c2));
350 c1 = gst_caps_from_string ("audio/x-raw-int, channels=(int) {1}");
351 c2 = gst_caps_from_string ("audio/x-raw-int, channels=(int)1");
352 fail_unless (gst_caps_is_subset (c2, c1));
353 fail_unless (gst_caps_is_subset (c1, c2));
354 fail_unless (gst_caps_is_equal (c1, c2));
358 c1 = gst_caps_from_string
359 ("audio/x-raw-int, rate=(int)44100, channels=(int)3, endianness=(int)1234, width=(int)16, depth=(int)16, signed=(boolean)false");
360 c2 = gst_caps_from_string
361 ("audio/x-raw-int, rate=(int)[ 1, 2147483647 ], channels=(int)[ 1, 2147483647 ], endianness=(int){ 1234, 4321 }, width=(int)16, depth=(int)[ 1, 16 ], signed=(boolean){ true, false }");
362 fail_unless (gst_caps_is_subset (c1, c2));
363 fail_if (gst_caps_is_subset (c2, c1));
370 GST_START_TEST (test_merge_fundamental)
374 /* ANY + specific = ANY */
375 c1 = gst_caps_from_string ("audio/x-raw-int,rate=44100");
376 c2 = gst_caps_new_any ();
377 gst_caps_merge (c2, c1);
378 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
379 fail_unless (gst_caps_get_size (c2) == 0, NULL);
380 fail_unless (gst_caps_is_any (c2), NULL);
383 /* specific + ANY = ANY */
384 c2 = gst_caps_from_string ("audio/x-raw-int,rate=44100");
385 c1 = gst_caps_new_any ();
386 gst_caps_merge (c2, c1);
387 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
388 fail_unless (gst_caps_get_size (c2) == 0, NULL);
389 fail_unless (gst_caps_is_any (c2), NULL);
392 /* EMPTY + specific = specific */
393 c1 = gst_caps_from_string ("audio/x-raw-int,rate=44100");
394 c2 = gst_caps_new_empty ();
395 gst_caps_merge (c2, c1);
396 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
397 fail_unless (gst_caps_get_size (c2) == 1, NULL);
398 fail_if (gst_caps_is_empty (c2), NULL);
401 /* specific + EMPTY = specific */
402 c2 = gst_caps_from_string ("audio/x-raw-int,rate=44100");
403 c1 = gst_caps_new_empty ();
404 gst_caps_merge (c2, c1);
405 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
406 fail_unless (gst_caps_get_size (c2) == 1, NULL);
407 fail_if (gst_caps_is_empty (c2), NULL);
413 GST_START_TEST (test_merge_same)
415 GstCaps *c1, *c2, *test;
417 /* this is the same */
418 c1 = gst_caps_from_string ("audio/x-raw-int,rate=44100,channels=1");
419 c2 = gst_caps_from_string ("audio/x-raw-int,rate=44100,channels=1");
420 gst_caps_merge (c2, c1);
421 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
422 fail_unless (gst_caps_get_size (c2) == 1, NULL);
423 test = gst_caps_from_string ("audio/x-raw-int,rate=44100,channels=1");
424 fail_unless (gst_caps_is_equal (c2, test));
425 gst_caps_unref (test);
429 c1 = gst_caps_from_string ("audio/x-raw-int,rate=44100,channels=1");
430 c2 = gst_caps_from_string ("audio/x-raw-int,channels=1,rate=44100");
431 gst_caps_merge (c2, c1);
432 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
433 fail_unless (gst_caps_get_size (c2) == 1, NULL);
436 c1 = gst_caps_from_string ("video/x-foo, data=(buffer)AA");
437 c2 = gst_caps_from_string ("video/x-foo, data=(buffer)AABB");
438 gst_caps_merge (c2, c1);
439 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
440 fail_unless (gst_caps_get_size (c2) == 2, NULL);
443 c1 = gst_caps_from_string ("video/x-foo, data=(buffer)AABB");
444 c2 = gst_caps_from_string ("video/x-foo, data=(buffer)AA");
445 gst_caps_merge (c2, c1);
446 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
447 fail_unless (gst_caps_get_size (c2) == 2, NULL);
450 c1 = gst_caps_from_string ("video/x-foo, data=(buffer)AA");
451 c2 = gst_caps_from_string ("video/x-foo, data=(buffer)AA");
452 gst_caps_merge (c2, c1);
453 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
454 fail_unless (gst_caps_get_size (c2) == 1, NULL);
457 c1 = gst_caps_from_string ("video/x-foo, data=(buffer)AA");
458 c2 = gst_caps_from_string ("video/x-bar, data=(buffer)AA");
459 gst_caps_merge (c2, c1);
460 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
461 fail_unless (gst_caps_get_size (c2) == 2, NULL);
467 GST_START_TEST (test_merge_subset)
469 GstCaps *c1, *c2, *test;
471 /* the 2nd is already covered */
472 c2 = gst_caps_from_string ("audio/x-raw-int,channels=[1,2]");
473 c1 = gst_caps_from_string ("audio/x-raw-int,channels=1");
474 gst_caps_merge (c2, c1);
475 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
476 fail_unless (gst_caps_get_size (c2) == 1, NULL);
477 test = gst_caps_from_string ("audio/x-raw-int,channels=[1,2]");
478 fail_unless (gst_caps_is_equal (c2, test));
480 gst_caps_unref (test);
483 c2 = gst_caps_from_string ("audio/x-raw-int,channels=1,rate=44100");
484 c1 = gst_caps_from_string ("audio/x-raw-int,channels=[1,2],rate=44100");
485 gst_caps_merge (c2, c1);
486 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
487 fail_unless (gst_caps_get_size (c2) == 2, NULL);
488 test = gst_caps_from_string ("audio/x-raw-int,channels=[1,2],rate=44100");
489 fail_unless (gst_caps_is_equal (c2, test));
491 gst_caps_unref (test);
493 /* second one was already contained in the first one */
494 c2 = gst_caps_from_string ("audio/x-raw-int,channels=[1,3]");
495 c1 = gst_caps_from_string ("audio/x-raw-int,channels=[1,2]");
496 gst_caps_merge (c2, c1);
497 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
498 fail_unless (gst_caps_get_size (c2) == 1, NULL);
499 test = gst_caps_from_string ("audio/x-raw-int,channels=[1,3]");
500 fail_unless (gst_caps_is_equal (c2, test));
502 gst_caps_unref (test);
504 /* second one was already contained in the first one */
505 c2 = gst_caps_from_string ("audio/x-raw-int,channels=[1,4]");
506 c1 = gst_caps_from_string ("audio/x-raw-int,channels=[1,2]");
507 gst_caps_merge (c2, c1);
508 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
509 fail_unless (gst_caps_get_size (c2) == 1, NULL);
510 test = gst_caps_from_string ("audio/x-raw-int,channels=[1,4]");
511 fail_unless (gst_caps_is_equal (c2, test));
513 gst_caps_unref (test);
515 /* second one was already contained in the first one */
516 c2 = gst_caps_from_string ("audio/x-raw-int,channels=[1,4]");
517 c1 = gst_caps_from_string ("audio/x-raw-int,channels=[2,4]");
518 gst_caps_merge (c2, c1);
519 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
520 fail_unless (gst_caps_get_size (c2) == 1, NULL);
521 test = gst_caps_from_string ("audio/x-raw-int,channels=[1,4]");
522 fail_unless (gst_caps_is_equal (c2, test));
524 gst_caps_unref (test);
526 /* second one was already contained in the first one */
527 c2 = gst_caps_from_string ("audio/x-raw-int,channels=[1,4]");
528 c1 = gst_caps_from_string ("audio/x-raw-int,channels=[2,3]");
529 gst_caps_merge (c2, c1);
530 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
531 fail_unless (gst_caps_get_size (c2) == 1, NULL);
532 test = gst_caps_from_string ("audio/x-raw-int,channels=[1,4]");
533 fail_unless (gst_caps_is_equal (c2, test));
535 gst_caps_unref (test);
537 /* these caps cannot be merged */
538 c2 = gst_caps_from_string ("audio/x-raw-int,channels=[2,3]");
539 c1 = gst_caps_from_string ("audio/x-raw-int,channels=[1,4]");
540 gst_caps_merge (c2, c1);
541 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
542 fail_unless (gst_caps_get_size (c2) == 2, NULL);
545 ("audio/x-raw-int,channels=[2,3];audio/x-raw-int,channels=[1,4]");
546 fail_unless (gst_caps_is_equal (c2, test));
548 gst_caps_unref (test);
550 /* these caps cannot be merged */
551 c2 = gst_caps_from_string ("audio/x-raw-int,channels=[1,2]");
552 c1 = gst_caps_from_string ("audio/x-raw-int,channels=[1,3]");
553 gst_caps_merge (c2, c1);
554 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
555 fail_unless (gst_caps_get_size (c2) == 2, NULL);
558 ("audio/x-raw-int,channels=[1,2];audio/x-raw-int,channels=[1,3]");
559 fail_unless (gst_caps_is_equal (c2, test));
561 gst_caps_unref (test);
563 c2 = gst_caps_from_string ("audio/x-raw-int,channels={1,2}");
564 c1 = gst_caps_from_string ("audio/x-raw-int,channels={1,2,3,4}");
565 gst_caps_merge (c2, c1);
566 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
567 fail_unless (gst_caps_get_size (c2) == 2, NULL);
568 test = gst_caps_from_string ("audio/x-raw-int,channels={1,2};"
569 "audio/x-raw-int,channels={1,2,3,4}");
570 fail_unless (gst_caps_is_equal (c2, test));
572 gst_caps_unref (test);
574 c2 = gst_caps_from_string ("audio/x-raw-int,channels={1,2}");
575 c1 = gst_caps_from_string ("audio/x-raw-int,channels={1,3}");
576 gst_caps_merge (c2, c1);
577 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
578 fail_unless (gst_caps_get_size (c2) == 2, NULL);
579 test = gst_caps_from_string ("audio/x-raw-int,channels={1,2};"
580 "audio/x-raw-int,channels={1,3}");
581 fail_unless (gst_caps_is_equal (c2, test));
583 gst_caps_unref (test);
585 c2 = gst_caps_from_string
586 ("video/x-raw-yuv, framerate=(fraction){ 15/2, 5/1 }");
587 c1 = gst_caps_from_string
588 ("video/x-raw-yuv, framerate=(fraction){ 15/1, 5/1 }");
589 test = gst_caps_copy (c1);
590 gst_caps_merge (c2, c1);
591 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
592 fail_unless (gst_caps_is_subset (test, c2));
593 gst_caps_unref (test);
596 c2 = gst_caps_from_string ("audio/x-raw-int");
597 c1 = gst_caps_from_string ("audio/x-raw-int,channels=1");
598 gst_caps_merge (c2, c1);
599 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
600 fail_unless (gst_caps_get_size (c2) == 1, NULL);
601 test = gst_caps_from_string ("audio/x-raw-int");
602 fail_unless (gst_caps_is_equal (c2, test));
604 gst_caps_unref (test);
606 c2 = gst_caps_from_string ("audio/x-raw-int,channels=1");
607 c1 = gst_caps_from_string ("audio/x-raw-int");
608 gst_caps_merge (c2, c1);
609 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
610 fail_unless (gst_caps_get_size (c2) == 2, NULL);
611 test = gst_caps_from_string ("audio/x-raw-int,channels=1; audio/x-raw-int");
612 fail_unless (gst_caps_is_equal (c2, test));
614 gst_caps_unref (test);
619 GST_START_TEST (test_intersect)
622 GstCaps *c1, *c2, *ci1, *ci2;
624 /* field not specified = any value possible, so the intersection
625 * should keep fields which are only part of one set of caps */
626 c2 = gst_caps_from_string ("video/x-raw-yuv,format=(fourcc)I420,width=20");
627 c1 = gst_caps_from_string ("video/x-raw-yuv,format=(fourcc)I420");
629 ci1 = gst_caps_intersect (c2, c1);
630 GST_DEBUG ("intersected: %" GST_PTR_FORMAT, ci1);
631 fail_unless (gst_caps_get_size (ci1) == 1, NULL);
632 s = gst_caps_get_structure (ci1, 0);
633 fail_unless (gst_structure_has_name (s, "video/x-raw-yuv"));
634 fail_unless (gst_structure_get_value (s, "format") != NULL);
635 fail_unless (gst_structure_get_value (s, "width") != NULL);
637 /* with changed order */
638 ci2 = gst_caps_intersect (c1, c2);
639 GST_DEBUG ("intersected: %" GST_PTR_FORMAT, ci2);
640 fail_unless (gst_caps_get_size (ci2) == 1, NULL);
641 s = gst_caps_get_structure (ci2, 0);
642 fail_unless (gst_structure_has_name (s, "video/x-raw-yuv"));
643 fail_unless (gst_structure_get_value (s, "format") != NULL);
644 fail_unless (gst_structure_get_value (s, "width") != NULL);
646 fail_unless (gst_caps_is_equal (ci1, ci2));
648 gst_caps_unref (ci1);
649 gst_caps_unref (ci2);
656 c2 = gst_caps_from_string ("video/x-raw-yuv,format=(fourcc)I420,width=20");
657 c1 = gst_caps_from_string ("video/x-raw-yuv,format=(fourcc)I420,width=30");
659 ci1 = gst_caps_intersect (c2, c1);
660 GST_DEBUG ("intersected: %" GST_PTR_FORMAT, ci1);
661 fail_unless (gst_caps_is_empty (ci1), NULL);
663 /* with changed order */
664 ci2 = gst_caps_intersect (c1, c2);
665 GST_DEBUG ("intersected: %" GST_PTR_FORMAT, ci2);
666 fail_unless (gst_caps_is_empty (ci2), NULL);
668 fail_unless (gst_caps_is_equal (ci1, ci2));
670 gst_caps_unref (ci1);
671 gst_caps_unref (ci2);
678 c2 = gst_caps_from_string ("video/x-raw-yuv,format=(fourcc)I420,width=20");
679 c1 = gst_caps_from_string ("video/x-raw-rgb,format=(fourcc)I420,width=20");
681 ci1 = gst_caps_intersect (c2, c1);
682 GST_DEBUG ("intersected: %" GST_PTR_FORMAT, ci1);
683 fail_unless (gst_caps_is_empty (ci1), NULL);
685 /* with changed order */
686 ci2 = gst_caps_intersect (c1, c2);
687 GST_DEBUG ("intersected: %" GST_PTR_FORMAT, ci2);
688 fail_unless (gst_caps_is_empty (ci2), NULL);
690 fail_unless (gst_caps_is_equal (ci1, ci2));
692 gst_caps_unref (ci1);
693 gst_caps_unref (ci2);
700 c2 = gst_caps_from_string ("video/x-raw-yuv,format=(fourcc)I420,width=20");
701 c1 = gst_caps_from_string ("video/x-raw-yuv,format=(fourcc)I420,height=30");
703 ci1 = gst_caps_intersect (c2, c1);
704 GST_DEBUG ("intersected: %" GST_PTR_FORMAT, ci1);
705 fail_unless (gst_caps_get_size (ci1) == 1, NULL);
706 s = gst_caps_get_structure (ci1, 0);
707 fail_unless (gst_structure_has_name (s, "video/x-raw-yuv"));
708 fail_unless (gst_structure_get_value (s, "format") != NULL);
709 fail_unless (gst_structure_get_value (s, "width") != NULL);
710 fail_unless (gst_structure_get_value (s, "height") != NULL);
712 /* with changed order */
713 ci2 = gst_caps_intersect (c1, c2);
714 GST_DEBUG ("intersected: %" GST_PTR_FORMAT, ci2);
715 fail_unless (gst_caps_get_size (ci2) == 1, NULL);
716 s = gst_caps_get_structure (ci2, 0);
717 fail_unless (gst_structure_has_name (s, "video/x-raw-yuv"));
718 fail_unless (gst_structure_get_value (s, "format") != NULL);
719 fail_unless (gst_structure_get_value (s, "height") != NULL);
720 fail_unless (gst_structure_get_value (s, "width") != NULL);
722 fail_unless (gst_caps_is_equal (ci1, ci2));
724 gst_caps_unref (ci1);
725 gst_caps_unref (ci2);
733 GST_START_TEST (test_intersect2)
735 GstCaps *caps1, *caps2, *icaps;
737 /* tests array subtraction */
738 caps1 = gst_caps_from_string ("audio/x-raw-float, "
739 "channel-positions=(int)< "
740 "{ 1, 2, 3, 4, 5, 6 }, "
741 "{ 1, 2, 3, 4, 5, 6 }, "
742 "{ 1, 2, 3, 4, 5, 6 }, "
743 "{ 1, 2, 3, 4, 5, 6 }, "
744 "{ 1, 2, 3, 4, 5, 6 }, " "{ 1, 2, 3, 4, 5, 6 }>");
745 caps2 = gst_caps_from_string ("audio/x-raw-float, "
746 "channel-positions=(int)< 1, 2, 3, 4, 5, 6 >");
747 icaps = gst_caps_intersect (caps1, caps2);
748 GST_LOG ("intersected caps: %" GST_PTR_FORMAT, icaps);
749 fail_if (gst_caps_is_empty (icaps));
750 fail_unless (gst_caps_is_equal (icaps, caps2));
751 gst_caps_unref (caps1);
752 gst_caps_unref (caps2);
753 gst_caps_unref (icaps);
757 caps1 = gst_caps_from_string ("some/type, foo=(int)< { 1, 2 }, { 3, 4} >");
758 caps2 = gst_caps_from_string ("some/type, foo=(int)< 1, 3 >");
759 icaps = gst_caps_intersect (caps1, caps2);
760 GST_LOG ("intersected caps: %" GST_PTR_FORMAT, icaps);
761 fail_if (gst_caps_is_empty (icaps));
762 fail_unless (gst_caps_is_equal (icaps, caps2));
763 gst_caps_unref (caps1);
764 gst_caps_unref (caps2);
765 gst_caps_unref (icaps);
771 GST_START_TEST (test_intersect_zigzag)
773 GstCaps *caps1, *caps2, *icaps, *result;
775 /* tests if caps order is maintained */
776 caps1 = gst_caps_from_string ("format/A; format/B; format/C; format/D");
777 caps2 = gst_caps_from_string ("format/D; format/A; format/B; format/C");
779 icaps = gst_caps_intersect_full (caps1, caps2, GST_CAPS_INTERSECT_ZIG_ZAG);
780 result = gst_caps_from_string ("format/B; format/A; format/D; format/C");
781 GST_LOG ("intersected caps: %" GST_PTR_FORMAT, icaps);
782 fail_if (gst_caps_is_empty (icaps));
783 fail_unless (gst_caps_is_equal (icaps, result));
784 gst_caps_unref (icaps);
785 gst_caps_unref (result);
787 icaps = gst_caps_intersect_full (caps2, caps1, GST_CAPS_INTERSECT_FIRST);
788 result = gst_caps_from_string ("format/A; format/B; format/D; format/C");
789 GST_LOG ("intersected caps: %" GST_PTR_FORMAT, icaps);
790 fail_if (gst_caps_is_empty (icaps));
791 fail_unless (gst_caps_is_equal (icaps, result));
792 gst_caps_unref (icaps);
793 gst_caps_unref (result);
795 gst_caps_unref (caps1);
796 gst_caps_unref (caps2);
802 GST_START_TEST (test_intersect_first)
804 GstCaps *caps1, *caps2, *icaps, *result;
806 /* tests if caps order is maintained */
807 caps1 = gst_caps_from_string ("format/A; format/B; format/C; format/D");
808 caps2 = gst_caps_from_string ("format/C; format/D; format/A");
809 icaps = gst_caps_intersect_full (caps1, caps2, GST_CAPS_INTERSECT_FIRST);
810 result = gst_caps_from_string ("format/A; format/C; format/D");
811 GST_LOG ("intersected caps: %" GST_PTR_FORMAT, icaps);
812 fail_if (gst_caps_is_empty (icaps));
813 fail_unless (gst_caps_is_equal (icaps, result));
814 gst_caps_unref (caps1);
815 gst_caps_unref (caps2);
816 gst_caps_unref (icaps);
817 gst_caps_unref (result);
823 GST_START_TEST (test_intersect_first2)
825 GstCaps *caps1, *caps2, *icaps, *result;
827 /* tests if caps order is maintained */
828 caps1 = gst_caps_from_string ("format/A; format/B; format/C; format/D");
829 caps2 = gst_caps_from_string ("format/D; format/A; format/B; format/C");
831 icaps = gst_caps_intersect_full (caps1, caps2, GST_CAPS_INTERSECT_FIRST);
832 result = gst_caps_from_string ("format/A; format/B; format/C; format/D");
833 GST_LOG ("intersected caps: %" GST_PTR_FORMAT, icaps);
834 fail_if (gst_caps_is_empty (icaps));
835 fail_unless (gst_caps_is_equal (icaps, result));
836 gst_caps_unref (icaps);
837 gst_caps_unref (result);
839 icaps = gst_caps_intersect_full (caps2, caps1, GST_CAPS_INTERSECT_FIRST);
840 result = gst_caps_from_string ("format/D; format/A; format/B; format/C");
841 GST_LOG ("intersected caps: %" GST_PTR_FORMAT, icaps);
842 fail_if (gst_caps_is_empty (icaps));
843 fail_unless (gst_caps_is_equal (icaps, result));
844 gst_caps_unref (icaps);
845 gst_caps_unref (result);
847 gst_caps_unref (caps1);
848 gst_caps_unref (caps2);
853 GST_START_TEST (test_intersect_duplication)
855 GstCaps *c1, *c2, *test;
857 c1 = gst_caps_from_string
858 ("audio/x-raw-int, endianness=(int)1234, signed=(boolean)true, width=(int)16, depth=(int)16, rate=(int)[ 1, 2147483647 ], channels=(int)[ 1, 2 ]");
859 c2 = gst_caps_from_string
860 ("audio/x-raw-int, width=(int)16, depth=(int)16, rate=(int)[ 1, 2147483647 ], channels=(int)[ 1, 2 ], endianness=(int){ 1234, 4321 }, signed=(boolean){ true, false }; audio/x-raw-int, width=(int)16, depth=(int)16, rate=(int)[ 1, 2147483647 ], channels=(int)[ 1, 11 ], endianness=(int){ 1234, 4321 }, signed=(boolean){ true, false }; audio/x-raw-int, width=(int)16, depth=(int)[ 1, 16 ], rate=(int)[ 1, 2147483647 ], channels=(int)[ 1, 11 ], endianness=(int){ 1234, 4321 }, signed=(boolean){ true, false }");
862 test = gst_caps_intersect_full (c1, c2, GST_CAPS_INTERSECT_FIRST);
863 fail_unless_equals_int (gst_caps_get_size (test), 1);
864 fail_unless (gst_caps_is_equal (c1, test));
867 gst_caps_unref (test);
873 _caps_is_fixed_foreach (GQuark field_id, const GValue * value, gpointer unused)
875 return gst_value_is_fixed (value);
879 GST_START_TEST (test_normalize)
881 GstCaps *in, *norm, *out;
884 in = gst_caps_from_string ("some/type, foo=(int){ 1 , 2 }");
885 out = gst_caps_from_string ("some/type, foo=(int) 1; some/type, foo=(int) 2");
886 norm = gst_caps_normalize (in);
887 fail_if (gst_caps_is_empty (norm));
888 fail_unless (gst_caps_is_equal (norm, out));
889 for (i = 0; i < gst_caps_get_size (norm); i++) {
890 GstStructure *st = gst_caps_get_structure (norm, i);
891 /* Make sure all fields of all structures are fixed */
892 fail_unless (gst_structure_foreach (st, _caps_is_fixed_foreach, NULL));
896 gst_caps_unref (out);
897 gst_caps_unref (norm);
899 in = gst_caps_from_string
900 ("some/type, foo=(int){ 1 , 2 }, bar=(int){ 3, 4 }");
903 ("some/type, foo=(int) 1, bar=(int) 3; some/type, foo=(int) 2, bar=(int) 3;"
904 "some/type, foo=(int) 1, bar=(int) 4; some/type, foo=(int) 2, bar=(int) 4;");
905 norm = gst_caps_normalize (in);
906 fail_if (gst_caps_is_empty (norm));
907 fail_unless (gst_caps_is_equal (norm, out));
908 for (i = 0; i < gst_caps_get_size (norm); i++) {
909 GstStructure *st = gst_caps_get_structure (norm, i);
910 /* Make sure all fields of all structures are fixed */
911 fail_unless (gst_structure_foreach (st, _caps_is_fixed_foreach, NULL));
915 gst_caps_unref (out);
916 gst_caps_unref (norm);
918 in = gst_caps_from_string
919 ("some/type, foo=(string){ 1 , 2 }, bar=(string) { 3 }");
922 ("some/type, foo=(string) 1, bar=(string) 3; some/type, foo=(string) 2, bar=(string) 3");
923 norm = gst_caps_normalize (in);
924 fail_if (gst_caps_is_empty (norm));
925 fail_unless (gst_caps_is_equal (norm, out));
926 for (i = 0; i < gst_caps_get_size (norm); i++) {
927 GstStructure *st = gst_caps_get_structure (norm, i);
928 /* Make sure all fields of all structures are fixed */
929 fail_unless (gst_structure_foreach (st, _caps_is_fixed_foreach, NULL));
933 gst_caps_unref (out);
934 gst_caps_unref (norm);
939 GST_START_TEST (test_broken)
943 /* NULL is not valid for media_type */
944 ASSERT_CRITICAL (c1 =
945 gst_caps_new_simple (NULL, "field", G_TYPE_INT, 1, NULL));
948 #ifndef G_DISABLE_CHECKS
949 /* such a name is not valid, see gst_structure_validate_name() */
950 ASSERT_CRITICAL (c1 =
951 gst_caps_new_simple ("1#@abc", "field", G_TYPE_INT, 1, NULL));
960 gst_caps_suite (void)
962 Suite *s = suite_create ("GstCaps");
963 TCase *tc_chain = tcase_create ("operations");
965 suite_add_tcase (s, tc_chain);
966 tcase_add_test (tc_chain, test_from_string);
967 tcase_add_test (tc_chain, test_double_append);
968 tcase_add_test (tc_chain, test_mutability);
969 tcase_add_test (tc_chain, test_static_caps);
970 tcase_add_test (tc_chain, test_simplify);
971 tcase_add_test (tc_chain, test_truncate);
972 tcase_add_test (tc_chain, test_subset);
973 tcase_add_test (tc_chain, test_merge_fundamental);
974 tcase_add_test (tc_chain, test_merge_same);
975 tcase_add_test (tc_chain, test_merge_subset);
976 tcase_add_test (tc_chain, test_intersect);
977 tcase_add_test (tc_chain, test_intersect2);
978 tcase_add_test (tc_chain, test_intersect_zigzag);
979 tcase_add_test (tc_chain, test_intersect_first);
980 tcase_add_test (tc_chain, test_intersect_first2);
981 tcase_add_test (tc_chain, test_intersect_duplication);
982 tcase_add_test (tc_chain, test_normalize);
983 tcase_add_test (tc_chain, test_broken);
988 GST_CHECK_MAIN (gst_caps);