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_buffer)
61 buffer = gst_buffer_new_and_alloc (1000);
62 c1 = gst_caps_new_simple ("audio/x-raw-int",
63 "buffer", GST_TYPE_BUFFER, buffer, NULL);
65 GST_DEBUG ("caps: %" GST_PTR_FORMAT, c1);
66 gst_buffer_unref (buffer);
68 buffer = gst_buffer_new_and_alloc (1000);
69 gst_buffer_set_caps (buffer, c1); /* doesn't give away our c1 ref */
72 gst_buffer_unref (buffer); /* Should now drop both references */
77 GST_START_TEST (test_double_append)
82 c1 = gst_caps_new_any ();
83 s1 = gst_structure_from_string ("audio/x-raw-int,rate=44100", NULL);
84 gst_caps_append_structure (c1, s1);
85 ASSERT_CRITICAL (gst_caps_append_structure (c1, s1));
92 GST_START_TEST (test_mutability)
98 c1 = gst_caps_new_any ();
99 s1 = gst_structure_from_string ("audio/x-raw-int,rate=44100", NULL);
100 gst_structure_set (s1, "rate", G_TYPE_INT, 48000, NULL);
101 gst_caps_append_structure (c1, s1);
102 gst_structure_set (s1, "rate", G_TYPE_INT, 22500, NULL);
104 ASSERT_CRITICAL (gst_structure_set (s1, "rate", G_TYPE_INT, 11250, NULL));
105 fail_unless (gst_structure_get_int (s1, "rate", &ret));
106 fail_unless (ret == 22500);
107 ASSERT_CRITICAL (gst_caps_set_simple (c1, "rate", G_TYPE_INT, 11250, NULL));
108 fail_unless (gst_structure_get_int (s1, "rate", &ret));
109 fail_unless (ret == 22500);
111 gst_structure_set (s1, "rate", G_TYPE_INT, 11250, NULL);
112 fail_unless (gst_structure_get_int (s1, "rate", &ret));
113 fail_unless (ret == 11250);
114 gst_caps_set_simple (c1, "rate", G_TYPE_INT, 1, NULL);
115 fail_unless (gst_structure_get_int (s1, "rate", &ret));
116 fail_unless (ret == 1);
122 GST_START_TEST (test_static_caps)
124 static GstStaticCaps scaps = GST_STATIC_CAPS ("audio/x-raw-int,rate=44100");
129 caps1 = gst_static_caps_get (&scaps);
130 fail_unless (caps1 != NULL);
131 /* 1 refcount core, one from us */
132 fail_unless (GST_CAPS_REFCOUNT (caps1) == 2);
134 /* caps should be the same */
135 caps2 = gst_static_caps_get (&scaps);
136 fail_unless (caps2 != NULL);
137 /* 1 refcount core, two from us */
138 fail_unless (GST_CAPS_REFCOUNT (caps1) == 3);
139 /* caps must be equal */
140 fail_unless (caps1 == caps2);
142 gst_caps_unref (caps1);
143 gst_caps_unref (caps2);
148 static const gchar non_simple_caps_string[] =
149 "video/x-raw-yuv, format=(fourcc)I420, framerate=(fraction)[ 1/100, 100 ], "
150 "width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ]; video/x-raw-yuv, "
151 "format=(fourcc)YUY2, framerate=(fraction)[ 1/100, 100 ], width=(int)[ 16, 4096 ], "
152 "height=(int)[ 16, 4096 ]; video/x-raw-rgb, bpp=(int)8, depth=(int)8, "
153 "endianness=(int)1234, framerate=(fraction)[ 1/100, 100 ], width=(int)[ 16, 4096 ], "
154 "height=(int)[ 16, 4096 ]; video/x-raw-yuv, "
155 "format=(fourcc){ I420, YUY2, YV12 }, width=(int)[ 16, 4096 ], "
156 "height=(int)[ 16, 4096 ], framerate=(fraction)[ 1/100, 100 ]";
159 check_fourcc_list (const GValue * format_value)
161 const GValue *fourcc_value;
162 gboolean got_yv12 = FALSE;
163 gboolean got_i420 = FALSE;
164 gboolean got_yuy2 = FALSE;
167 fourcc_value = gst_value_list_get_value (format_value, 0);
168 fail_unless (fourcc_value != NULL);
169 fail_unless (GST_VALUE_HOLDS_FOURCC (fourcc_value));
170 fourcc = gst_value_get_fourcc (fourcc_value);
171 fail_unless (fourcc != 0);
172 got_i420 = got_i420 || (fourcc == GST_STR_FOURCC ("I420"));
173 got_yuy2 = got_yuy2 || (fourcc == GST_STR_FOURCC ("YUY2"));
174 got_yv12 = got_yv12 || (fourcc == GST_STR_FOURCC ("YV12"));
176 fourcc_value = gst_value_list_get_value (format_value, 1);
177 fail_unless (fourcc_value != NULL);
178 fail_unless (GST_VALUE_HOLDS_FOURCC (fourcc_value));
179 fourcc = gst_value_get_fourcc (fourcc_value);
180 fail_unless (fourcc != 0);
181 got_i420 = got_i420 || (fourcc == GST_STR_FOURCC ("I420"));
182 got_yuy2 = got_yuy2 || (fourcc == GST_STR_FOURCC ("YUY2"));
183 got_yv12 = got_yv12 || (fourcc == GST_STR_FOURCC ("YV12"));
185 fourcc_value = gst_value_list_get_value (format_value, 2);
186 fail_unless (fourcc_value != NULL);
187 fail_unless (GST_VALUE_HOLDS_FOURCC (fourcc_value));
188 fourcc = gst_value_get_fourcc (fourcc_value);
189 fail_unless (fourcc != 0);
190 got_i420 = got_i420 || (fourcc == GST_STR_FOURCC ("I420"));
191 got_yuy2 = got_yuy2 || (fourcc == GST_STR_FOURCC ("YUY2"));
192 got_yv12 = got_yv12 || (fourcc == GST_STR_FOURCC ("YV12"));
194 return (got_i420 && got_yuy2 && got_yv12);
197 GST_START_TEST (test_simplify)
199 GstStructure *s1, *s2;
200 gboolean did_simplify;
203 caps = gst_caps_from_string (non_simple_caps_string);
204 fail_unless (caps != NULL,
205 "gst_caps_from_string (non_simple_caps_string) failed");
207 did_simplify = gst_caps_do_simplify (caps);
208 fail_unless (did_simplify == TRUE,
209 "gst_caps_do_simplify() should have worked");
211 /* check simplified caps, should be:
213 * video/x-raw-rgb, bpp=(int)8, depth=(int)8, endianness=(int)1234,
214 * framerate=(fraction)[ 1/100, 100 ], width=(int)[ 16, 4096 ],
215 * height=(int)[ 16, 4096 ];
216 * video/x-raw-yuv, format=(fourcc){ YV12, YUY2, I420 },
217 * width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ],
218 * framerate=(fraction)[ 1/100, 100 ]
220 fail_unless (gst_caps_get_size (caps) == 2);
221 s1 = gst_caps_get_structure (caps, 0);
222 s2 = gst_caps_get_structure (caps, 1);
223 fail_unless (s1 != NULL);
224 fail_unless (s2 != NULL);
226 if (!gst_structure_has_name (s1, "video/x-raw-rgb")) {
234 fail_unless (gst_structure_has_name (s1, "video/x-raw-rgb"));
236 const GValue *framerate_value;
237 const GValue *width_value;
238 const GValue *height_value;
239 const GValue *val_fps;
240 GValue test_fps = { 0, };
241 gint bpp, depth, endianness;
242 gint min_width, max_width;
243 gint min_height, max_height;
245 fail_unless (gst_structure_get_int (s1, "bpp", &bpp));
246 fail_unless (bpp == 8);
248 fail_unless (gst_structure_get_int (s1, "depth", &depth));
249 fail_unless (depth == 8);
251 fail_unless (gst_structure_get_int (s1, "endianness", &endianness));
252 fail_unless (endianness == G_LITTLE_ENDIAN);
254 g_value_init (&test_fps, GST_TYPE_FRACTION);
255 framerate_value = gst_structure_get_value (s1, "framerate");
256 fail_unless (framerate_value != NULL);
257 fail_unless (GST_VALUE_HOLDS_FRACTION_RANGE (framerate_value));
259 val_fps = gst_value_get_fraction_range_min (framerate_value);
260 gst_value_set_fraction (&test_fps, 1, 100);
261 fail_unless (gst_value_compare (&test_fps, val_fps) == GST_VALUE_EQUAL);
263 val_fps = gst_value_get_fraction_range_max (framerate_value);
264 gst_value_set_fraction (&test_fps, 100, 1);
265 fail_unless (gst_value_compare (&test_fps, val_fps) == GST_VALUE_EQUAL);
267 g_value_unset (&test_fps);
269 width_value = gst_structure_get_value (s1, "width");
270 fail_unless (width_value != NULL);
271 fail_unless (GST_VALUE_HOLDS_INT_RANGE (width_value));
272 min_width = gst_value_get_int_range_min (width_value);
273 max_width = gst_value_get_int_range_max (width_value);
274 fail_unless (min_width == 16 && max_width == 4096);
276 height_value = gst_structure_get_value (s1, "height");
277 fail_unless (height_value != NULL);
278 fail_unless (GST_VALUE_HOLDS_INT_RANGE (height_value));
279 min_height = gst_value_get_int_range_min (height_value);
280 max_height = gst_value_get_int_range_max (height_value);
281 fail_unless (min_height == 16 && max_height == 4096);
284 fail_unless (gst_structure_has_name (s2, "video/x-raw-yuv"));
286 const GValue *framerate_value;
287 const GValue *format_value;
288 const GValue *width_value;
289 const GValue *height_value;
290 const GValue *val_fps;
291 GValue test_fps = { 0, };
292 gint min_width, max_width;
293 gint min_height, max_height;
295 format_value = gst_structure_get_value (s2, "format");
296 fail_unless (format_value != NULL);
297 fail_unless (GST_VALUE_HOLDS_LIST (format_value));
298 fail_unless (gst_value_list_get_size (format_value) == 3);
299 fail_unless (check_fourcc_list (format_value) == TRUE);
301 g_value_init (&test_fps, GST_TYPE_FRACTION);
302 framerate_value = gst_structure_get_value (s2, "framerate");
303 fail_unless (framerate_value != NULL);
304 fail_unless (GST_VALUE_HOLDS_FRACTION_RANGE (framerate_value));
306 val_fps = gst_value_get_fraction_range_min (framerate_value);
307 gst_value_set_fraction (&test_fps, 1, 100);
308 fail_unless (gst_value_compare (&test_fps, val_fps) == GST_VALUE_EQUAL);
310 val_fps = gst_value_get_fraction_range_max (framerate_value);
311 gst_value_set_fraction (&test_fps, 100, 1);
312 fail_unless (gst_value_compare (&test_fps, val_fps) == GST_VALUE_EQUAL);
314 g_value_unset (&test_fps);
316 width_value = gst_structure_get_value (s2, "width");
317 fail_unless (width_value != NULL);
318 fail_unless (GST_VALUE_HOLDS_INT_RANGE (width_value));
319 min_width = gst_value_get_int_range_min (width_value);
320 max_width = gst_value_get_int_range_max (width_value);
321 fail_unless (min_width == 16 && max_width == 4096);
323 height_value = gst_structure_get_value (s2, "height");
324 fail_unless (height_value != NULL);
325 fail_unless (GST_VALUE_HOLDS_INT_RANGE (height_value));
326 min_height = gst_value_get_int_range_min (height_value);
327 max_height = gst_value_get_int_range_max (height_value);
328 fail_unless (min_height == 16 && max_height == 4096);
331 gst_caps_unref (caps);
336 GST_START_TEST (test_truncate)
340 caps = gst_caps_from_string (non_simple_caps_string);
341 fail_unless (caps != NULL,
342 "gst_caps_from_string (non_simple_caps_string) failed");
343 fail_unless_equals_int (gst_caps_get_size (caps), 4);
344 gst_caps_truncate (caps);
345 fail_unless_equals_int (gst_caps_get_size (caps), 1);
346 gst_caps_unref (caps);
351 GST_START_TEST (test_merge_fundamental)
355 /* ANY + specific = ANY */
356 c1 = gst_caps_from_string ("audio/x-raw-int,rate=44100");
357 c2 = gst_caps_new_any ();
358 gst_caps_merge (c2, c1);
359 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
360 fail_unless (gst_caps_get_size (c2) == 0, NULL);
361 fail_unless (gst_caps_is_any (c2), NULL);
364 /* specific + ANY = ANY */
365 c2 = gst_caps_from_string ("audio/x-raw-int,rate=44100");
366 c1 = gst_caps_new_any ();
367 gst_caps_merge (c2, c1);
368 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
369 fail_unless (gst_caps_get_size (c2) == 0, NULL);
370 fail_unless (gst_caps_is_any (c2), NULL);
373 /* EMPTY + specific = specific */
374 c1 = gst_caps_from_string ("audio/x-raw-int,rate=44100");
375 c2 = gst_caps_new_empty ();
376 gst_caps_merge (c2, c1);
377 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
378 fail_unless (gst_caps_get_size (c2) == 1, NULL);
379 fail_if (gst_caps_is_empty (c2), NULL);
382 /* specific + EMPTY = specific */
383 c2 = gst_caps_from_string ("audio/x-raw-int,rate=44100");
384 c1 = gst_caps_new_empty ();
385 gst_caps_merge (c2, c1);
386 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
387 fail_unless (gst_caps_get_size (c2) == 1, NULL);
388 fail_if (gst_caps_is_empty (c2), NULL);
394 GST_START_TEST (test_merge_same)
396 GstCaps *c1, *c2, *test;
398 /* this is the same */
399 c1 = gst_caps_from_string ("audio/x-raw-int,rate=44100,channels=1");
400 c2 = gst_caps_from_string ("audio/x-raw-int,rate=44100,channels=1");
401 gst_caps_merge (c2, c1);
402 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
403 fail_unless (gst_caps_get_size (c2) == 1, NULL);
404 test = gst_caps_from_string ("audio/x-raw-int,rate=44100,channels=1");
405 fail_unless (gst_caps_is_equal (c2, test));
406 gst_caps_unref (test);
410 c1 = gst_caps_from_string ("audio/x-raw-int,rate=44100,channels=1");
411 c2 = gst_caps_from_string ("audio/x-raw-int,channels=1,rate=44100");
412 gst_caps_merge (c2, c1);
413 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
414 fail_unless (gst_caps_get_size (c2) == 1, NULL);
417 c1 = gst_caps_from_string ("video/x-foo, data=(buffer)AA");
418 c2 = gst_caps_from_string ("video/x-foo, data=(buffer)AABB");
419 gst_caps_merge (c2, c1);
420 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
421 fail_unless (gst_caps_get_size (c2) == 2, NULL);
424 c1 = gst_caps_from_string ("video/x-foo, data=(buffer)AABB");
425 c2 = gst_caps_from_string ("video/x-foo, data=(buffer)AA");
426 gst_caps_merge (c2, c1);
427 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
428 fail_unless (gst_caps_get_size (c2) == 2, NULL);
431 c1 = gst_caps_from_string ("video/x-foo, data=(buffer)AA");
432 c2 = gst_caps_from_string ("video/x-foo, data=(buffer)AA");
433 gst_caps_merge (c2, c1);
434 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
435 fail_unless (gst_caps_get_size (c2) == 1, NULL);
438 c1 = gst_caps_from_string ("video/x-foo, data=(buffer)AA");
439 c2 = gst_caps_from_string ("video/x-bar, data=(buffer)AA");
440 gst_caps_merge (c2, c1);
441 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
442 fail_unless (gst_caps_get_size (c2) == 2, NULL);
448 GST_START_TEST (test_merge_subset)
450 GstCaps *c1, *c2, *test;
452 /* the 2nd is already covered */
453 c2 = gst_caps_from_string ("audio/x-raw-int,channels=[1,2]");
454 c1 = gst_caps_from_string ("audio/x-raw-int,channels=1");
455 gst_caps_merge (c2, c1);
456 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
457 fail_unless (gst_caps_get_size (c2) == 1, NULL);
458 test = gst_caps_from_string ("audio/x-raw-int,channels=[1,2]");
459 fail_unless (gst_caps_is_equal (c2, test));
461 gst_caps_unref (test);
464 c2 = gst_caps_from_string ("audio/x-raw-int,channels=1,rate=44100");
465 c1 = gst_caps_from_string ("audio/x-raw-int,channels=[1,2],rate=44100");
466 gst_caps_merge (c2, c1);
467 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
468 fail_unless (gst_caps_get_size (c2) == 2, NULL);
469 test = gst_caps_from_string ("audio/x-raw-int,channels=[1,2],rate=44100");
470 fail_unless (gst_caps_is_equal (c2, test));
472 gst_caps_unref (test);
474 /* second one was already contained in the first one */
475 c2 = gst_caps_from_string ("audio/x-raw-int,channels=[1,3]");
476 c1 = gst_caps_from_string ("audio/x-raw-int,channels=[1,2]");
477 gst_caps_merge (c2, c1);
478 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
479 fail_unless (gst_caps_get_size (c2) == 1, NULL);
480 test = gst_caps_from_string ("audio/x-raw-int,channels=[1,3]");
481 fail_unless (gst_caps_is_equal (c2, test));
483 gst_caps_unref (test);
485 /* second one was already contained in the first one */
486 c2 = gst_caps_from_string ("audio/x-raw-int,channels=[1,4]");
487 c1 = gst_caps_from_string ("audio/x-raw-int,channels=[1,2]");
488 gst_caps_merge (c2, c1);
489 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
490 fail_unless (gst_caps_get_size (c2) == 1, NULL);
491 test = gst_caps_from_string ("audio/x-raw-int,channels=[1,4]");
492 fail_unless (gst_caps_is_equal (c2, test));
494 gst_caps_unref (test);
496 /* second one was already contained in the first one */
497 c2 = gst_caps_from_string ("audio/x-raw-int,channels=[1,4]");
498 c1 = gst_caps_from_string ("audio/x-raw-int,channels=[2,4]");
499 gst_caps_merge (c2, c1);
500 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
501 fail_unless (gst_caps_get_size (c2) == 1, NULL);
502 test = gst_caps_from_string ("audio/x-raw-int,channels=[1,4]");
503 fail_unless (gst_caps_is_equal (c2, test));
505 gst_caps_unref (test);
507 /* second one was already contained in the first one */
508 c2 = gst_caps_from_string ("audio/x-raw-int,channels=[1,4]");
509 c1 = gst_caps_from_string ("audio/x-raw-int,channels=[2,3]");
510 gst_caps_merge (c2, c1);
511 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
512 fail_unless (gst_caps_get_size (c2) == 1, NULL);
513 test = gst_caps_from_string ("audio/x-raw-int,channels=[1,4]");
514 fail_unless (gst_caps_is_equal (c2, test));
516 gst_caps_unref (test);
518 /* these caps cannot be merged */
519 c2 = gst_caps_from_string ("audio/x-raw-int,channels=[2,3]");
520 c1 = gst_caps_from_string ("audio/x-raw-int,channels=[1,4]");
521 gst_caps_merge (c2, c1);
522 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
523 fail_unless (gst_caps_get_size (c2) == 2, NULL);
526 ("audio/x-raw-int,channels=[2,3];audio/x-raw-int,channels=[1,4]");
527 fail_unless (gst_caps_is_equal (c2, test));
529 gst_caps_unref (test);
531 /* these caps cannot be merged */
532 c2 = gst_caps_from_string ("audio/x-raw-int,channels=[1,2]");
533 c1 = gst_caps_from_string ("audio/x-raw-int,channels=[1,3]");
534 gst_caps_merge (c2, c1);
535 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
536 fail_unless (gst_caps_get_size (c2) == 2, NULL);
539 ("audio/x-raw-int,channels=[1,2];audio/x-raw-int,channels=[1,3]");
540 fail_unless (gst_caps_is_equal (c2, test));
542 gst_caps_unref (test);
544 c2 = gst_caps_from_string ("audio/x-raw-int,channels={1,2}");
545 c1 = gst_caps_from_string ("audio/x-raw-int,channels={1,2,3,4}");
546 gst_caps_merge (c2, c1);
547 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
548 fail_unless (gst_caps_get_size (c2) == 2, NULL);
549 test = gst_caps_from_string ("audio/x-raw-int,channels={1,2};"
550 "audio/x-raw-int,channels={1,2,3,4}");
551 fail_unless (gst_caps_is_equal (c2, test));
553 gst_caps_unref (test);
555 c2 = gst_caps_from_string ("audio/x-raw-int,channels={1,2}");
556 c1 = gst_caps_from_string ("audio/x-raw-int,channels={1,3}");
557 gst_caps_merge (c2, c1);
558 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
559 fail_unless (gst_caps_get_size (c2) == 2, NULL);
560 test = gst_caps_from_string ("audio/x-raw-int,channels={1,2};"
561 "audio/x-raw-int,channels={1,3}");
562 fail_unless (gst_caps_is_equal (c2, test));
564 gst_caps_unref (test);
566 c2 = gst_caps_from_string
567 ("video/x-raw-yuv, framerate=(fraction){ 15/2, 5/1 }");
568 c1 = gst_caps_from_string
569 ("video/x-raw-yuv, framerate=(fraction){ 15/1, 5/1 }");
570 test = gst_caps_copy (c1);
571 gst_caps_merge (c2, c1);
572 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
573 fail_unless (gst_caps_is_subset (test, c2));
574 gst_caps_unref (test);
580 GST_START_TEST (test_intersect)
583 GstCaps *c1, *c2, *ci1, *ci2;
585 /* field not specified = any value possible, so the intersection
586 * should keep fields which are only part of one set of caps */
587 c2 = gst_caps_from_string ("video/x-raw-yuv,format=(fourcc)I420,width=20");
588 c1 = gst_caps_from_string ("video/x-raw-yuv,format=(fourcc)I420");
590 ci1 = gst_caps_intersect (c2, c1);
591 GST_DEBUG ("intersected: %" GST_PTR_FORMAT, ci1);
592 fail_unless (gst_caps_get_size (ci1) == 1, NULL);
593 s = gst_caps_get_structure (ci1, 0);
594 fail_unless (gst_structure_has_name (s, "video/x-raw-yuv"));
595 fail_unless (gst_structure_get_value (s, "format") != NULL);
596 fail_unless (gst_structure_get_value (s, "width") != NULL);
598 /* with changed order */
599 ci2 = gst_caps_intersect (c1, c2);
600 GST_DEBUG ("intersected: %" GST_PTR_FORMAT, ci2);
601 fail_unless (gst_caps_get_size (ci2) == 1, NULL);
602 s = gst_caps_get_structure (ci2, 0);
603 fail_unless (gst_structure_has_name (s, "video/x-raw-yuv"));
604 fail_unless (gst_structure_get_value (s, "format") != NULL);
605 fail_unless (gst_structure_get_value (s, "width") != NULL);
607 fail_unless (gst_caps_is_equal (ci1, ci2));
609 gst_caps_unref (ci1);
610 gst_caps_unref (ci2);
617 c2 = gst_caps_from_string ("video/x-raw-yuv,format=(fourcc)I420,width=20");
618 c1 = gst_caps_from_string ("video/x-raw-yuv,format=(fourcc)I420,width=30");
620 ci1 = gst_caps_intersect (c2, c1);
621 GST_DEBUG ("intersected: %" GST_PTR_FORMAT, ci1);
622 fail_unless (gst_caps_is_empty (ci1), NULL);
624 /* with changed order */
625 ci2 = gst_caps_intersect (c1, c2);
626 GST_DEBUG ("intersected: %" GST_PTR_FORMAT, ci2);
627 fail_unless (gst_caps_is_empty (ci2), NULL);
629 fail_unless (gst_caps_is_equal (ci1, ci2));
631 gst_caps_unref (ci1);
632 gst_caps_unref (ci2);
639 c2 = gst_caps_from_string ("video/x-raw-yuv,format=(fourcc)I420,width=20");
640 c1 = gst_caps_from_string ("video/x-raw-rgb,format=(fourcc)I420,width=20");
642 ci1 = gst_caps_intersect (c2, c1);
643 GST_DEBUG ("intersected: %" GST_PTR_FORMAT, ci1);
644 fail_unless (gst_caps_is_empty (ci1), NULL);
646 /* with changed order */
647 ci2 = gst_caps_intersect (c1, c2);
648 GST_DEBUG ("intersected: %" GST_PTR_FORMAT, ci2);
649 fail_unless (gst_caps_is_empty (ci2), NULL);
651 fail_unless (gst_caps_is_equal (ci1, ci2));
653 gst_caps_unref (ci1);
654 gst_caps_unref (ci2);
661 c2 = gst_caps_from_string ("video/x-raw-yuv,format=(fourcc)I420,width=20");
662 c1 = gst_caps_from_string ("video/x-raw-yuv,format=(fourcc)I420,height=30");
664 ci1 = gst_caps_intersect (c2, c1);
665 GST_DEBUG ("intersected: %" GST_PTR_FORMAT, ci1);
666 fail_unless (gst_caps_get_size (ci1) == 1, NULL);
667 s = gst_caps_get_structure (ci1, 0);
668 fail_unless (gst_structure_has_name (s, "video/x-raw-yuv"));
669 fail_unless (gst_structure_get_value (s, "format") != NULL);
670 fail_unless (gst_structure_get_value (s, "width") != NULL);
671 fail_unless (gst_structure_get_value (s, "height") != NULL);
673 /* with changed order */
674 ci2 = gst_caps_intersect (c1, c2);
675 GST_DEBUG ("intersected: %" GST_PTR_FORMAT, ci2);
676 fail_unless (gst_caps_get_size (ci2) == 1, NULL);
677 s = gst_caps_get_structure (ci2, 0);
678 fail_unless (gst_structure_has_name (s, "video/x-raw-yuv"));
679 fail_unless (gst_structure_get_value (s, "format") != NULL);
680 fail_unless (gst_structure_get_value (s, "height") != NULL);
681 fail_unless (gst_structure_get_value (s, "width") != NULL);
683 fail_unless (gst_caps_is_equal (ci1, ci2));
685 gst_caps_unref (ci1);
686 gst_caps_unref (ci2);
694 GST_START_TEST (test_intersect2)
696 GstCaps *caps1, *caps2, *icaps;
698 /* tests array subtraction */
699 caps1 = gst_caps_from_string ("audio/x-raw-float, "
700 "channel-positions=(int)< "
701 "{ 1, 2, 3, 4, 5, 6 }, "
702 "{ 1, 2, 3, 4, 5, 6 }, "
703 "{ 1, 2, 3, 4, 5, 6 }, "
704 "{ 1, 2, 3, 4, 5, 6 }, "
705 "{ 1, 2, 3, 4, 5, 6 }, " "{ 1, 2, 3, 4, 5, 6 }>");
706 caps2 = gst_caps_from_string ("audio/x-raw-float, "
707 "channel-positions=(int)< 1, 2, 3, 4, 5, 6 >");
708 icaps = gst_caps_intersect (caps1, caps2);
709 GST_LOG ("intersected caps: %" GST_PTR_FORMAT, icaps);
710 fail_if (gst_caps_is_empty (icaps));
711 fail_unless (gst_caps_is_equal (icaps, caps2));
712 gst_caps_unref (caps1);
713 gst_caps_unref (caps2);
714 gst_caps_unref (icaps);
718 caps1 = gst_caps_from_string ("some/type, foo=(int)< { 1, 2 }, { 3, 4} >");
719 caps2 = gst_caps_from_string ("some/type, foo=(int)< 1, 3 >");
720 icaps = gst_caps_intersect (caps1, caps2);
721 GST_LOG ("intersected caps: %" GST_PTR_FORMAT, icaps);
722 fail_if (gst_caps_is_empty (icaps));
723 fail_unless (gst_caps_is_equal (icaps, caps2));
724 gst_caps_unref (caps1);
725 gst_caps_unref (caps2);
726 gst_caps_unref (icaps);
732 GST_START_TEST (test_intersect_zigzag)
734 GstCaps *caps1, *caps2, *icaps, *result;
736 /* tests if caps order is maintained */
737 caps1 = gst_caps_from_string ("format/A; format/B; format/C; format/D");
738 caps2 = gst_caps_from_string ("format/D; format/A; format/B; format/C");
740 icaps = gst_caps_intersect_full (caps1, caps2, GST_CAPS_INTERSECT_ZIG_ZAG);
741 result = gst_caps_from_string ("format/B; format/A; format/D; format/C");
742 GST_LOG ("intersected caps: %" GST_PTR_FORMAT, icaps);
743 fail_if (gst_caps_is_empty (icaps));
744 fail_unless (gst_caps_is_equal (icaps, result));
745 gst_caps_unref (icaps);
746 gst_caps_unref (result);
748 icaps = gst_caps_intersect_full (caps2, caps1, GST_CAPS_INTERSECT_FIRST);
749 result = gst_caps_from_string ("format/A; format/B; format/D; format/C");
750 GST_LOG ("intersected caps: %" GST_PTR_FORMAT, icaps);
751 fail_if (gst_caps_is_empty (icaps));
752 fail_unless (gst_caps_is_equal (icaps, result));
753 gst_caps_unref (icaps);
754 gst_caps_unref (result);
756 gst_caps_unref (caps1);
757 gst_caps_unref (caps2);
763 GST_START_TEST (test_intersect_first)
765 GstCaps *caps1, *caps2, *icaps, *result;
767 /* tests if caps order is maintained */
768 caps1 = gst_caps_from_string ("format/A; format/B; format/C; format/D");
769 caps2 = gst_caps_from_string ("format/C; format/D; format/A");
770 icaps = gst_caps_intersect_full (caps1, caps2, GST_CAPS_INTERSECT_FIRST);
771 result = gst_caps_from_string ("format/A; format/C; format/D");
772 GST_LOG ("intersected caps: %" GST_PTR_FORMAT, icaps);
773 fail_if (gst_caps_is_empty (icaps));
774 fail_unless (gst_caps_is_equal (icaps, result));
775 gst_caps_unref (caps1);
776 gst_caps_unref (caps2);
777 gst_caps_unref (icaps);
778 gst_caps_unref (result);
784 GST_START_TEST (test_intersect_first2)
786 GstCaps *caps1, *caps2, *icaps, *result;
788 /* tests if caps order is maintained */
789 caps1 = gst_caps_from_string ("format/A; format/B; format/C; format/D");
790 caps2 = gst_caps_from_string ("format/D; format/A; format/B; format/C");
792 icaps = gst_caps_intersect_full (caps1, caps2, GST_CAPS_INTERSECT_FIRST);
793 result = gst_caps_from_string ("format/A; format/B; format/C; format/D");
794 GST_LOG ("intersected caps: %" GST_PTR_FORMAT, icaps);
795 fail_if (gst_caps_is_empty (icaps));
796 fail_unless (gst_caps_is_equal (icaps, result));
797 gst_caps_unref (icaps);
798 gst_caps_unref (result);
800 icaps = gst_caps_intersect_full (caps2, caps1, GST_CAPS_INTERSECT_FIRST);
801 result = gst_caps_from_string ("format/D; format/A; format/B; format/C");
802 GST_LOG ("intersected caps: %" GST_PTR_FORMAT, icaps);
803 fail_if (gst_caps_is_empty (icaps));
804 fail_unless (gst_caps_is_equal (icaps, result));
805 gst_caps_unref (icaps);
806 gst_caps_unref (result);
808 gst_caps_unref (caps1);
809 gst_caps_unref (caps2);
814 GST_START_TEST (test_intersect_duplication)
816 GstCaps *c1, *c2, *test;
818 c1 = gst_caps_from_string
819 ("audio/x-raw-int, endianness=(int)1234, signed=(boolean)true, width=(int)16, depth=(int)16, rate=(int)[ 1, 2147483647 ], channels=(int)[ 1, 2 ]");
820 c2 = gst_caps_from_string
821 ("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 }");
823 test = gst_caps_intersect_full (c1, c2, GST_CAPS_INTERSECT_FIRST);
824 fail_unless_equals_int (gst_caps_get_size (test), 1);
825 fail_unless (gst_caps_is_equal (c1, test));
828 gst_caps_unref (test);
834 _caps_is_fixed_foreach (GQuark field_id, const GValue * value, gpointer unused)
836 return gst_value_is_fixed (value);
840 GST_START_TEST (test_normalize)
842 GstCaps *in, *norm, *out;
845 in = gst_caps_from_string ("some/type, foo=(int){ 1 , 2 }");
846 out = gst_caps_from_string ("some/type, foo=(int) 1; some/type, foo=(int) 2");
847 norm = gst_caps_normalize (in);
848 fail_if (gst_caps_is_empty (norm));
849 fail_unless (gst_caps_is_equal (norm, out));
850 for (i = 0; i < gst_caps_get_size (norm); i++) {
851 GstStructure *st = gst_caps_get_structure (norm, i);
852 /* Make sure all fields of all structures are fixed */
853 fail_unless (gst_structure_foreach (st, _caps_is_fixed_foreach, NULL));
857 gst_caps_unref (out);
858 gst_caps_unref (norm);
860 in = gst_caps_from_string
861 ("some/type, foo=(int){ 1 , 2 }, bar=(int){ 3, 4 }");
864 ("some/type, foo=(int) 1, bar=(int) 3; some/type, foo=(int) 2, bar=(int) 3;"
865 "some/type, foo=(int) 1, bar=(int) 4; some/type, foo=(int) 2, bar=(int) 4;");
866 norm = gst_caps_normalize (in);
867 fail_if (gst_caps_is_empty (norm));
868 fail_unless (gst_caps_is_equal (norm, out));
869 for (i = 0; i < gst_caps_get_size (norm); i++) {
870 GstStructure *st = gst_caps_get_structure (norm, i);
871 /* Make sure all fields of all structures are fixed */
872 fail_unless (gst_structure_foreach (st, _caps_is_fixed_foreach, NULL));
876 gst_caps_unref (out);
877 gst_caps_unref (norm);
879 in = gst_caps_from_string
880 ("some/type, foo=(string){ 1 , 2 }, bar=(string) { 3 }");
883 ("some/type, foo=(string) 1, bar=(string) 3; some/type, foo=(string) 2, bar=(string) 3");
884 norm = gst_caps_normalize (in);
885 fail_if (gst_caps_is_empty (norm));
886 fail_unless (gst_caps_is_equal (norm, out));
887 for (i = 0; i < gst_caps_get_size (norm); i++) {
888 GstStructure *st = gst_caps_get_structure (norm, i);
889 /* Make sure all fields of all structures are fixed */
890 fail_unless (gst_structure_foreach (st, _caps_is_fixed_foreach, NULL));
894 gst_caps_unref (out);
895 gst_caps_unref (norm);
900 GST_START_TEST (test_broken)
904 /* NULL is not valid for media_type */
905 ASSERT_CRITICAL (c1 =
906 gst_caps_new_simple (NULL, "field", G_TYPE_INT, 1, NULL));
909 #ifndef G_DISABLE_CHECKS
910 /* such a name is not valid, see gst_structure_validate_name() */
911 ASSERT_CRITICAL (c1 =
912 gst_caps_new_simple ("1#@abc", "field", G_TYPE_INT, 1, NULL));
921 gst_caps_suite (void)
923 Suite *s = suite_create ("GstCaps");
924 TCase *tc_chain = tcase_create ("operations");
926 suite_add_tcase (s, tc_chain);
927 tcase_add_test (tc_chain, test_from_string);
928 tcase_add_test (tc_chain, test_double_append);
929 tcase_add_test (tc_chain, test_mutability);
930 tcase_add_test (tc_chain, test_buffer);
931 tcase_add_test (tc_chain, test_static_caps);
932 tcase_add_test (tc_chain, test_simplify);
933 tcase_add_test (tc_chain, test_truncate);
934 tcase_add_test (tc_chain, test_merge_fundamental);
935 tcase_add_test (tc_chain, test_merge_same);
936 tcase_add_test (tc_chain, test_merge_subset);
937 tcase_add_test (tc_chain, test_intersect);
938 tcase_add_test (tc_chain, test_intersect2);
939 tcase_add_test (tc_chain, test_intersect_zigzag);
940 tcase_add_test (tc_chain, test_intersect_first);
941 tcase_add_test (tc_chain, test_intersect_first2);
942 tcase_add_test (tc_chain, test_intersect_duplication);
943 tcase_add_test (tc_chain, test_normalize);
944 tcase_add_test (tc_chain, test_broken);
949 GST_CHECK_MAIN (gst_caps);