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., 51 Franklin St, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
26 #include <gst/check/gstcheck.h>
27 #include <gst/gstcaps.h>
30 GST_START_TEST (test_from_string)
37 for (i = 0; i < G_N_ELEMENTS (caps_list); i++) {
38 caps = gst_caps_from_string (caps_list[i]);
39 fail_if (caps == NULL,
40 "Could not create caps from string %s\n", caps_list[i]);
41 to_str = gst_caps_to_string (caps);
42 fail_if (to_str == NULL,
43 "Could not convert caps back to string %s\n", caps_list[i]);
44 caps2 = gst_caps_from_string (to_str);
45 fail_if (caps2 == NULL, "Could not create caps from string %s\n", to_str);
48 fail_unless (gst_caps_is_equal (caps, caps));
49 fail_unless (gst_caps_is_equal (caps, caps2));
50 gst_caps_unref (caps2);
52 to_str = gst_caps_serialize (caps, GST_SERIALIZE_FLAG_NONE);
53 fail_if (to_str == NULL,
54 "Could not convert caps back to string %s\n", caps_list[i]);
55 caps2 = gst_caps_from_string (to_str);
56 fail_unless (gst_caps_is_equal (caps, caps));
57 fail_unless (gst_caps_is_equal (caps, caps2));
59 gst_caps_unref (caps);
60 gst_caps_unref (caps2);
67 GST_START_TEST (test_double_append)
72 c1 = gst_caps_new_empty ();
73 s1 = gst_structure_from_string ("audio/x-raw,rate=44100", NULL);
74 gst_caps_append_structure (c1, s1);
75 ASSERT_CRITICAL (gst_caps_append_structure (c1, s1));
82 GST_START_TEST (test_mutability)
88 c1 = gst_caps_new_empty ();
89 s1 = gst_structure_from_string ("audio/x-raw,rate=44100", NULL);
90 gst_structure_set (s1, "rate", G_TYPE_INT, 48000, NULL);
91 gst_caps_append_structure (c1, s1);
92 gst_structure_set (s1, "rate", G_TYPE_INT, 22500, NULL);
94 ASSERT_CRITICAL (gst_structure_set (s1, "rate", G_TYPE_INT, 11250, NULL));
95 fail_unless (gst_structure_get_int (s1, "rate", &ret));
96 fail_unless (ret == 22500);
97 ASSERT_CRITICAL (gst_caps_set_simple (c1, "rate", G_TYPE_INT, 11250, NULL));
98 fail_unless (gst_structure_get_int (s1, "rate", &ret));
99 fail_unless (ret == 22500);
101 gst_structure_set (s1, "rate", G_TYPE_INT, 11250, NULL);
102 fail_unless (gst_structure_get_int (s1, "rate", &ret));
103 fail_unless (ret == 11250);
104 gst_caps_set_simple (c1, "rate", G_TYPE_INT, 1, NULL);
105 fail_unless (gst_structure_get_int (s1, "rate", &ret));
106 fail_unless (ret == 1);
112 GST_START_TEST (test_static_caps)
114 static GstStaticCaps scaps = GST_STATIC_CAPS ("audio/x-raw,rate=44100");
117 static GstStaticCaps sany = GST_STATIC_CAPS_ANY;
118 static GstStaticCaps snone = GST_STATIC_CAPS_NONE;
121 caps1 = gst_static_caps_get (&scaps);
122 fail_unless (caps1 != NULL);
123 /* 1 refcount core, one from us */
124 fail_unless (GST_CAPS_REFCOUNT (caps1) == 2);
126 /* caps should be the same */
127 caps2 = gst_static_caps_get (&scaps);
128 fail_unless (caps2 != NULL);
129 /* 1 refcount core, two from us */
130 fail_unless (GST_CAPS_REFCOUNT (caps1) == 3);
131 /* caps must be equal */
132 fail_unless (caps1 == caps2);
134 gst_caps_unref (caps1);
135 gst_caps_unref (caps2);
137 caps1 = gst_static_caps_get (&sany);
138 fail_unless (gst_caps_is_equal (caps1, GST_CAPS_ANY));
139 caps2 = gst_static_caps_get (&snone);
140 fail_unless (gst_caps_is_equal (caps2, GST_CAPS_NONE));
141 fail_if (gst_caps_is_equal (caps1, caps2));
142 gst_caps_unref (caps1);
143 gst_caps_unref (caps2);
148 static const gchar non_simple_caps_string[] =
149 "video/x-raw, format=(string)I420, framerate=(fraction)[ 1/100, 100 ], "
150 "width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ]; video/x-raw, "
151 "format=(string)YUY2, framerate=(fraction)[ 1/100, 100 ], width=(int)[ 16, 4096 ], "
152 "height=(int)[ 16, 4096 ]; video/x-raw, format=(string)RGB8_PALETTED, "
153 "framerate=(fraction)[ 1/100, 100 ], width=(int)[ 16, 4096 ], "
154 "height=(int)[ 16, 4096 ]; video/x-raw, "
155 "format=(string){ I420, YUY2, YV12 }, width=(int)[ 16, 4096 ], "
156 "height=(int)[ 16, 4096 ], framerate=(fraction)[ 1/100, 100 ]";
159 check_string_list (const GValue * format_value)
161 const GValue *string_value;
162 gboolean got_rgb8 = FALSE;
163 gboolean got_yv12 = FALSE;
164 gboolean got_i420 = FALSE;
165 gboolean got_yuy2 = FALSE;
168 string_value = gst_value_list_get_value (format_value, 0);
169 fail_unless (string_value != NULL);
170 fail_unless (G_VALUE_HOLDS_STRING (string_value));
171 string = g_value_get_string (string_value);
172 fail_unless (string != NULL);
173 got_rgb8 = got_rgb8 || (g_str_equal (string, "RGB8_PALETTED"));
174 got_i420 = got_i420 || (g_str_equal (string, "I420"));
175 got_yuy2 = got_yuy2 || (g_str_equal (string, "YUY2"));
176 got_yv12 = got_yv12 || (g_str_equal (string, "YV12"));
178 string_value = gst_value_list_get_value (format_value, 1);
179 fail_unless (string_value != NULL);
180 fail_unless (G_VALUE_HOLDS_STRING (string_value));
181 string = g_value_get_string (string_value);
182 fail_unless (string != NULL);
183 got_rgb8 = got_rgb8 || (g_str_equal (string, "RGB8_PALETTED"));
184 got_i420 = got_i420 || (g_str_equal (string, "I420"));
185 got_yuy2 = got_yuy2 || (g_str_equal (string, "YUY2"));
186 got_yv12 = got_yv12 || (g_str_equal (string, "YV12"));
188 string_value = gst_value_list_get_value (format_value, 2);
189 fail_unless (string_value != NULL);
190 fail_unless (G_VALUE_HOLDS_STRING (string_value));
191 string = g_value_get_string (string_value);
192 fail_unless (string != NULL);
193 got_rgb8 = got_rgb8 || (g_str_equal (string, "RGB8_PALETTED"));
194 got_i420 = got_i420 || (g_str_equal (string, "I420"));
195 got_yuy2 = got_yuy2 || (g_str_equal (string, "YUY2"));
196 got_yv12 = got_yv12 || (g_str_equal (string, "YV12"));
198 string_value = gst_value_list_get_value (format_value, 3);
199 fail_unless (string_value != NULL);
200 fail_unless (G_VALUE_HOLDS_STRING (string_value));
201 string = g_value_get_string (string_value);
202 fail_unless (string != NULL);
203 got_rgb8 = got_rgb8 || (g_str_equal (string, "RGB8_PALETTED"));
204 got_i420 = got_i420 || (g_str_equal (string, "I420"));
205 got_yuy2 = got_yuy2 || (g_str_equal (string, "YUY2"));
206 got_yv12 = got_yv12 || (g_str_equal (string, "YV12"));
208 return (got_rgb8 && got_i420 && got_yuy2 && got_yv12);
211 GST_START_TEST (test_simplify)
216 caps = gst_caps_from_string (non_simple_caps_string);
217 fail_unless (caps != NULL,
218 "gst_caps_from_string (non_simple_caps_string) failed");
220 caps = gst_caps_simplify (caps);
221 fail_unless (caps != NULL, "gst_caps_simplify() should have worked");
223 /* check simplified caps, should be:
225 * video/x-raw, format=(string){ RGB8_PALETTED, YV12, YUY2, I420 },
226 * width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ],
227 * framerate=(fraction)[ 1/100, 100 ]
229 GST_DEBUG ("simplyfied %" GST_PTR_FORMAT, caps);
230 fail_unless (gst_caps_get_size (caps) == 1);
231 s1 = gst_caps_get_structure (caps, 0);
232 fail_unless (s1 != NULL);
234 fail_unless (gst_structure_has_name (s1, "video/x-raw"));
236 const GValue *framerate_value;
237 const GValue *format_value;
238 const GValue *width_value;
239 const GValue *height_value;
240 const GValue *val_fps;
241 GValue test_fps = { 0, };
242 gint min_width, max_width;
243 gint min_height, max_height;
245 format_value = gst_structure_get_value (s1, "format");
246 fail_unless (format_value != NULL);
247 fail_unless (GST_VALUE_HOLDS_LIST (format_value));
248 fail_unless (gst_value_list_get_size (format_value) == 4);
249 fail_unless (check_string_list (format_value) == TRUE);
251 g_value_init (&test_fps, GST_TYPE_FRACTION);
252 framerate_value = gst_structure_get_value (s1, "framerate");
253 fail_unless (framerate_value != NULL);
254 fail_unless (GST_VALUE_HOLDS_FRACTION_RANGE (framerate_value));
256 val_fps = gst_value_get_fraction_range_min (framerate_value);
257 gst_value_set_fraction (&test_fps, 1, 100);
258 fail_unless (gst_value_compare (&test_fps, val_fps) == GST_VALUE_EQUAL);
260 val_fps = gst_value_get_fraction_range_max (framerate_value);
261 gst_value_set_fraction (&test_fps, 100, 1);
262 fail_unless (gst_value_compare (&test_fps, val_fps) == GST_VALUE_EQUAL);
264 g_value_unset (&test_fps);
266 width_value = gst_structure_get_value (s1, "width");
267 fail_unless (width_value != NULL);
268 fail_unless (GST_VALUE_HOLDS_INT_RANGE (width_value));
269 min_width = gst_value_get_int_range_min (width_value);
270 max_width = gst_value_get_int_range_max (width_value);
271 fail_unless (min_width == 16 && max_width == 4096);
273 height_value = gst_structure_get_value (s1, "height");
274 fail_unless (height_value != NULL);
275 fail_unless (GST_VALUE_HOLDS_INT_RANGE (height_value));
276 min_height = gst_value_get_int_range_min (height_value);
277 max_height = gst_value_get_int_range_max (height_value);
278 fail_unless (min_height == 16 && max_height == 4096);
281 gst_caps_unref (caps);
283 caps = gst_caps_new_empty ();
284 caps = gst_caps_simplify (caps);
285 fail_unless (gst_caps_is_empty (caps));
286 gst_caps_unref (caps);
288 caps = gst_caps_new_any ();
289 caps = gst_caps_simplify (caps);
290 fail_unless (gst_caps_is_any (caps));
291 gst_caps_unref (caps);
296 GST_START_TEST (test_truncate)
300 caps = gst_caps_from_string (non_simple_caps_string);
301 fail_unless (caps != NULL,
302 "gst_caps_from_string (non_simple_caps_string) failed");
303 fail_unless_equals_int (gst_caps_get_size (caps), 4);
304 caps = gst_caps_truncate (caps);
305 fail_unless_equals_int (gst_caps_get_size (caps), 1);
306 gst_caps_unref (caps);
308 caps = gst_caps_new_empty ();
309 caps = gst_caps_truncate (caps);
310 fail_if (caps == NULL);
311 fail_unless (gst_caps_is_empty (caps));
312 gst_caps_unref (caps);
314 caps = gst_caps_new_any ();
315 caps = gst_caps_truncate (caps);
316 fail_if (caps == NULL);
317 fail_unless (gst_caps_is_any (caps));
318 gst_caps_unref (caps);
323 GST_START_TEST (test_fixate)
325 GstCaps *caps, *expected;
327 caps = gst_caps_from_string (non_simple_caps_string);
328 fail_unless (caps != NULL,
329 "gst_caps_from_string (non_simple_caps_string) failed");
330 fail_unless_equals_int (gst_caps_get_size (caps), 4);
331 caps = gst_caps_fixate (caps);
332 fail_unless_equals_int (gst_caps_get_size (caps), 1);
335 ("video/x-raw, format=(string)I420, framerate=(fraction)1/100, "
336 "width=(int)16, height=(int)16");
337 fail_unless (gst_caps_is_equal (caps, expected));
338 gst_caps_unref (caps);
339 gst_caps_unref (expected);
341 caps = gst_caps_new_empty ();
342 caps = gst_caps_fixate (caps);
343 fail_if (caps == NULL);
344 fail_unless (gst_caps_is_empty (caps));
345 gst_caps_unref (caps);
350 GST_START_TEST (test_subset)
354 c1 = gst_caps_from_string ("video/x-raw; video/x-raw");
355 c2 = gst_caps_from_string ("video/x-raw, format=(string)YUY2");
356 fail_unless (gst_caps_is_subset (c2, c1));
357 fail_if (gst_caps_is_subset (c1, c2));
361 c1 = gst_caps_from_string
362 ("audio/x-raw, channels=(int)[ 1, 2 ], rate=(int)44100");
363 c2 = gst_caps_from_string ("audio/x-raw, channels=(int)1, rate=(int)44100");
364 fail_unless (gst_caps_is_subset (c2, c1));
365 fail_if (gst_caps_is_subset (c1, c2));
369 c1 = gst_caps_from_string ("audio/x-raw, channels=(int) {1}");
370 c2 = gst_caps_from_string ("audio/x-raw, channels=(int)1");
371 fail_unless (gst_caps_is_subset (c2, c1));
372 fail_unless (gst_caps_is_subset (c1, c2));
373 fail_unless (gst_caps_is_equal (c1, c2));
377 c1 = gst_caps_from_string
378 ("audio/x-raw, rate=(int)44100, channels=(int)3, format=(string)U16_LE");
379 c2 = gst_caps_from_string
380 ("audio/x-raw, rate=(int)[ 1, 2147483647 ], channels=(int)[ 1, 2147483647 ], format=(string){ S16_LE, U16_LE }");
381 fail_unless (gst_caps_is_subset (c1, c2));
382 fail_if (gst_caps_is_subset (c2, c1));
386 c1 = gst_caps_from_string ("video/x-h264, parsed=(boolean)true");
387 c2 = gst_caps_from_string
388 ("video/x-h264, stream-format=(string)byte-stream, alignment=(string)nal");
389 fail_if (gst_caps_is_subset (c2, c1));
390 fail_if (gst_caps_is_subset (c1, c2));
391 fail_if (gst_caps_is_equal (c1, c2));
395 c1 = gst_caps_from_string ("video/x-h264, parsed=(boolean)true");
396 c2 = gst_caps_new_empty ();
397 fail_unless (gst_caps_is_subset (c2, c1));
398 fail_if (gst_caps_is_subset (c1, c2));
399 fail_if (gst_caps_is_equal (c1, c2));
403 c1 = gst_caps_from_string ("video/x-h264, parsed=(boolean)true");
404 c2 = gst_caps_new_any ();
405 fail_if (gst_caps_is_subset (c2, c1));
406 fail_unless (gst_caps_is_subset (c1, c2));
407 fail_if (gst_caps_is_equal (c1, c2));
414 GST_START_TEST (test_subset_duplication)
418 c1 = gst_caps_from_string ("audio/x-raw, format=(string)F32LE");
419 c2 = gst_caps_from_string ("audio/x-raw, format=(string)F32LE");
421 fail_unless (gst_caps_is_subset (c1, c2));
422 fail_unless (gst_caps_is_subset (c2, c1));
425 c2 = gst_caps_from_string ("audio/x-raw, format=(string){ F32LE }");
427 fail_unless (gst_caps_is_subset (c1, c2));
428 fail_unless (gst_caps_is_subset (c2, c1));
431 c2 = gst_caps_from_string ("audio/x-raw, format=(string){ F32LE, F32LE }");
433 fail_unless (gst_caps_is_subset (c1, c2));
434 fail_unless (gst_caps_is_subset (c2, c1));
437 c2 = gst_caps_from_string
438 ("audio/x-raw, format=(string){ F32LE, F32LE, F32LE }");
440 fail_unless (gst_caps_is_subset (c1, c2));
441 fail_unless (gst_caps_is_subset (c2, c1));
449 GST_START_TEST (test_merge_fundamental)
453 /* ANY + specific = ANY */
454 c1 = gst_caps_from_string ("audio/x-raw,rate=44100");
455 c2 = gst_caps_new_any ();
456 c2 = gst_caps_merge (c2, c1);
457 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
458 fail_unless (gst_caps_get_size (c2) == 0, NULL);
459 fail_unless (gst_caps_is_any (c2), NULL);
462 /* specific + ANY = ANY */
463 c2 = gst_caps_from_string ("audio/x-raw,rate=44100");
464 c1 = gst_caps_new_any ();
465 c2 = gst_caps_merge (c2, c1);
466 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
467 fail_unless (gst_caps_get_size (c2) == 0, NULL);
468 fail_unless (gst_caps_is_any (c2), NULL);
471 /* EMPTY + specific = specific */
472 c1 = gst_caps_from_string ("audio/x-raw,rate=44100");
473 c2 = gst_caps_new_empty ();
474 c2 = 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 fail_if (gst_caps_is_empty (c2), NULL);
480 /* specific + EMPTY = specific */
481 c2 = gst_caps_from_string ("audio/x-raw,rate=44100");
482 c1 = gst_caps_new_empty ();
483 c2 = gst_caps_merge (c2, c1);
484 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
485 fail_unless (gst_caps_get_size (c2) == 1, NULL);
486 fail_if (gst_caps_is_empty (c2), NULL);
492 GST_START_TEST (test_merge_same)
494 GstCaps *c1, *c2, *test;
496 /* this is the same */
497 c1 = gst_caps_from_string ("audio/x-raw,rate=44100,channels=1");
498 c2 = gst_caps_from_string ("audio/x-raw,rate=44100,channels=1");
499 c2 = 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,rate=44100,channels=1");
503 fail_unless (gst_caps_is_equal (c2, test));
504 gst_caps_unref (test);
508 c1 = gst_caps_from_string ("audio/x-raw,rate=44100,channels=1");
509 c2 = gst_caps_from_string ("audio/x-raw,channels=1,rate=44100");
510 c2 = 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);
515 c1 = gst_caps_from_string ("video/x-foo, data=(buffer)AA");
516 c2 = gst_caps_from_string ("video/x-foo, data=(buffer)AABB");
517 c2 = gst_caps_merge (c2, c1);
518 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
519 fail_unless (gst_caps_get_size (c2) == 2, NULL);
522 c1 = gst_caps_from_string ("video/x-foo, data=(buffer)AABB");
523 c2 = gst_caps_from_string ("video/x-foo, data=(buffer)AA");
524 c2 = gst_caps_merge (c2, c1);
525 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
526 fail_unless (gst_caps_get_size (c2) == 2, NULL);
529 c1 = gst_caps_from_string ("video/x-foo, data=(buffer)AA");
530 c2 = gst_caps_from_string ("video/x-foo, data=(buffer)AA");
531 c2 = gst_caps_merge (c2, c1);
532 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
533 fail_unless (gst_caps_get_size (c2) == 1, NULL);
536 c1 = gst_caps_from_string ("video/x-foo, data=(buffer)AA");
537 c2 = gst_caps_from_string ("video/x-bar, data=(buffer)AA");
538 c2 = gst_caps_merge (c2, c1);
539 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
540 fail_unless (gst_caps_get_size (c2) == 2, NULL);
546 GST_START_TEST (test_merge_subset)
548 GstCaps *c1, *c2, *test;
550 /* the 2nd is already covered */
551 c2 = gst_caps_from_string ("audio/x-raw,channels=[1,2]");
552 c1 = gst_caps_from_string ("audio/x-raw,channels=1");
553 c2 = 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) == 1, NULL);
556 test = gst_caps_from_string ("audio/x-raw,channels=[1,2]");
557 fail_unless (gst_caps_is_equal (c2, test));
559 gst_caps_unref (test);
562 c2 = gst_caps_from_string ("audio/x-raw,channels=1,rate=44100");
563 c1 = gst_caps_from_string ("audio/x-raw,channels=[1,2],rate=44100");
564 c2 = gst_caps_merge (c2, c1);
565 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
566 fail_unless (gst_caps_get_size (c2) == 2, NULL);
567 test = gst_caps_from_string ("audio/x-raw,channels=[1,2],rate=44100");
568 fail_unless (gst_caps_is_equal (c2, test));
570 gst_caps_unref (test);
572 /* second one was already contained in the first one */
573 c2 = gst_caps_from_string ("audio/x-raw,channels=[1,3]");
574 c1 = gst_caps_from_string ("audio/x-raw,channels=[1,2]");
575 c2 = gst_caps_merge (c2, c1);
576 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
577 fail_unless (gst_caps_get_size (c2) == 1, NULL);
578 test = gst_caps_from_string ("audio/x-raw,channels=[1,3]");
579 fail_unless (gst_caps_is_equal (c2, test));
581 gst_caps_unref (test);
583 /* second one was already contained in the first one */
584 c2 = gst_caps_from_string ("audio/x-raw,channels=[1,4]");
585 c1 = gst_caps_from_string ("audio/x-raw,channels=[1,2]");
586 c2 = gst_caps_merge (c2, c1);
587 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
588 fail_unless (gst_caps_get_size (c2) == 1, NULL);
589 test = gst_caps_from_string ("audio/x-raw,channels=[1,4]");
590 fail_unless (gst_caps_is_equal (c2, test));
592 gst_caps_unref (test);
594 /* second one was already contained in the first one */
595 c2 = gst_caps_from_string ("audio/x-raw,channels=[1,4]");
596 c1 = gst_caps_from_string ("audio/x-raw,channels=[2,4]");
597 c2 = gst_caps_merge (c2, c1);
598 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
599 fail_unless (gst_caps_get_size (c2) == 1, NULL);
600 test = gst_caps_from_string ("audio/x-raw,channels=[1,4]");
601 fail_unless (gst_caps_is_equal (c2, test));
603 gst_caps_unref (test);
605 /* second one was already contained in the first one */
606 c2 = gst_caps_from_string ("audio/x-raw,channels=[1,4]");
607 c1 = gst_caps_from_string ("audio/x-raw,channels=[2,3]");
608 c2 = 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) == 1, NULL);
611 test = gst_caps_from_string ("audio/x-raw,channels=[1,4]");
612 fail_unless (gst_caps_is_equal (c2, test));
614 gst_caps_unref (test);
616 /* these caps cannot be merged */
617 c2 = gst_caps_from_string ("audio/x-raw,channels=[2,3]");
618 c1 = gst_caps_from_string ("audio/x-raw,channels=[1,4]");
619 c2 = gst_caps_merge (c2, c1);
620 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
621 fail_unless (gst_caps_get_size (c2) == 2, NULL);
624 ("audio/x-raw,channels=[2,3];audio/x-raw,channels=[1,4]");
625 fail_unless (gst_caps_is_equal (c2, test));
627 gst_caps_unref (test);
629 /* these caps cannot be merged */
630 c2 = gst_caps_from_string ("audio/x-raw,channels=[1,2]");
631 c1 = gst_caps_from_string ("audio/x-raw,channels=[1,3]");
632 c2 = gst_caps_merge (c2, c1);
633 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
634 fail_unless (gst_caps_get_size (c2) == 2, NULL);
637 ("audio/x-raw,channels=[1,2];audio/x-raw,channels=[1,3]");
638 fail_unless (gst_caps_is_equal (c2, test));
640 gst_caps_unref (test);
642 c2 = gst_caps_from_string ("audio/x-raw,channels={1,2}");
643 c1 = gst_caps_from_string ("audio/x-raw,channels={1,2,3,4}");
644 c2 = gst_caps_merge (c2, c1);
645 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
646 fail_unless (gst_caps_get_size (c2) == 2, NULL);
647 test = gst_caps_from_string ("audio/x-raw,channels={1,2};"
648 "audio/x-raw,channels={1,2,3,4}");
649 fail_unless (gst_caps_is_equal (c2, test));
651 gst_caps_unref (test);
653 c2 = gst_caps_from_string ("audio/x-raw,channels={1,2}");
654 c1 = gst_caps_from_string ("audio/x-raw,channels={1,3}");
655 c2 = gst_caps_merge (c2, c1);
656 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
657 fail_unless (gst_caps_get_size (c2) == 2, NULL);
658 test = gst_caps_from_string ("audio/x-raw,channels={1,2};"
659 "audio/x-raw,channels={1,3}");
660 fail_unless (gst_caps_is_equal (c2, test));
662 gst_caps_unref (test);
664 c2 = gst_caps_from_string ("video/x-raw, framerate=(fraction){ 15/2, 5/1 }");
665 c1 = gst_caps_from_string ("video/x-raw, framerate=(fraction){ 15/1, 5/1 }");
666 test = gst_caps_copy (c1);
667 c2 = gst_caps_merge (c2, c1);
668 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
669 fail_unless (gst_caps_is_subset (test, c2));
670 gst_caps_unref (test);
673 c2 = gst_caps_from_string ("audio/x-raw");
674 c1 = gst_caps_from_string ("audio/x-raw,channels=1");
675 c2 = gst_caps_merge (c2, c1);
676 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
677 fail_unless (gst_caps_get_size (c2) == 1, NULL);
678 test = gst_caps_from_string ("audio/x-raw");
679 fail_unless (gst_caps_is_equal (c2, test));
681 gst_caps_unref (test);
683 c2 = gst_caps_from_string ("audio/x-raw,channels=1");
684 c1 = gst_caps_from_string ("audio/x-raw");
685 c2 = gst_caps_merge (c2, c1);
686 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
687 fail_unless (gst_caps_get_size (c2) == 2, NULL);
688 test = gst_caps_from_string ("audio/x-raw,channels=1; audio/x-raw");
689 fail_unless (gst_caps_is_equal (c2, test));
691 gst_caps_unref (test);
696 GST_START_TEST (test_intersect)
699 GstCaps *c1, *c2, *ci1, *ci2;
701 /* field not specified = any value possible, so the intersection
702 * should keep fields which are only part of one set of caps */
703 c2 = gst_caps_from_string ("video/x-raw,format=(string)I420,width=20");
704 c1 = gst_caps_from_string ("video/x-raw,format=(string)I420");
706 ci1 = gst_caps_intersect (c2, c1);
707 GST_DEBUG ("intersected: %" GST_PTR_FORMAT, ci1);
708 fail_unless (gst_caps_get_size (ci1) == 1, NULL);
709 s = gst_caps_get_structure (ci1, 0);
710 fail_unless (gst_structure_has_name (s, "video/x-raw"));
711 fail_unless (gst_structure_get_value (s, "format") != NULL);
712 fail_unless (gst_structure_get_value (s, "width") != NULL);
714 /* with changed order */
715 ci2 = gst_caps_intersect (c1, c2);
716 GST_DEBUG ("intersected: %" GST_PTR_FORMAT, ci2);
717 fail_unless (gst_caps_get_size (ci2) == 1, NULL);
718 s = gst_caps_get_structure (ci2, 0);
719 fail_unless (gst_structure_has_name (s, "video/x-raw"));
720 fail_unless (gst_structure_get_value (s, "format") != NULL);
721 fail_unless (gst_structure_get_value (s, "width") != NULL);
723 fail_unless (gst_caps_is_equal (ci1, ci2));
725 gst_caps_unref (ci1);
726 gst_caps_unref (ci2);
733 c2 = gst_caps_from_string ("video/x-raw,format=(string)I420,width=20");
734 c1 = gst_caps_from_string ("video/x-raw,format=(string)I420,width=30");
736 ci1 = gst_caps_intersect (c2, c1);
737 GST_DEBUG ("intersected: %" GST_PTR_FORMAT, ci1);
738 fail_unless (gst_caps_is_empty (ci1), NULL);
740 /* with changed order */
741 ci2 = gst_caps_intersect (c1, c2);
742 GST_DEBUG ("intersected: %" GST_PTR_FORMAT, ci2);
743 fail_unless (gst_caps_is_empty (ci2), NULL);
745 fail_unless (gst_caps_is_equal (ci1, ci2));
747 gst_caps_unref (ci1);
748 gst_caps_unref (ci2);
755 c2 = gst_caps_from_string ("video/x-raw,format=(string)I420,width=20");
756 c1 = gst_caps_from_string ("video/x-raw2,format=(string)I420,width=20");
758 ci1 = gst_caps_intersect (c2, c1);
759 GST_DEBUG ("intersected: %" GST_PTR_FORMAT, ci1);
760 fail_unless (gst_caps_is_empty (ci1), NULL);
762 /* with changed order */
763 ci2 = gst_caps_intersect (c1, c2);
764 GST_DEBUG ("intersected: %" GST_PTR_FORMAT, ci2);
765 fail_unless (gst_caps_is_empty (ci2), NULL);
767 fail_unless (gst_caps_is_equal (ci1, ci2));
769 gst_caps_unref (ci1);
770 gst_caps_unref (ci2);
777 c2 = gst_caps_from_string ("video/x-raw,format=(string)I420,width=20");
778 c1 = gst_caps_from_string ("video/x-raw,format=(string)I420,height=30");
780 ci1 = gst_caps_intersect (c2, c1);
781 GST_DEBUG ("intersected: %" GST_PTR_FORMAT, ci1);
782 fail_unless (gst_caps_get_size (ci1) == 1, NULL);
783 s = gst_caps_get_structure (ci1, 0);
784 fail_unless (gst_structure_has_name (s, "video/x-raw"));
785 fail_unless (gst_structure_get_value (s, "format") != NULL);
786 fail_unless (gst_structure_get_value (s, "width") != NULL);
787 fail_unless (gst_structure_get_value (s, "height") != NULL);
789 /* with changed order */
790 ci2 = gst_caps_intersect (c1, c2);
791 GST_DEBUG ("intersected: %" GST_PTR_FORMAT, ci2);
792 fail_unless (gst_caps_get_size (ci2) == 1, NULL);
793 s = gst_caps_get_structure (ci2, 0);
794 fail_unless (gst_structure_has_name (s, "video/x-raw"));
795 fail_unless (gst_structure_get_value (s, "format") != NULL);
796 fail_unless (gst_structure_get_value (s, "height") != NULL);
797 fail_unless (gst_structure_get_value (s, "width") != NULL);
799 fail_unless (gst_caps_is_equal (ci1, ci2));
801 gst_caps_unref (ci1);
802 gst_caps_unref (ci2);
809 c1 = gst_caps_from_string ("video/x-raw,format=(string)I420,width=20");
810 c2 = gst_caps_new_empty ();
812 ci1 = gst_caps_intersect (c1, c2);
813 GST_DEBUG ("intersected: %" GST_PTR_FORMAT, ci1);
815 fail_unless (gst_caps_is_empty (ci1));
816 fail_unless (gst_caps_get_size (ci1) == 0);
818 ci2 = gst_caps_intersect (c2, c1);
819 GST_DEBUG ("intersected: %" GST_PTR_FORMAT, ci2);
821 fail_unless (gst_caps_is_empty (ci2));
822 fail_unless (gst_caps_get_size (ci2) == 0);
824 fail_unless (gst_caps_is_equal (ci1, ci2));
826 gst_caps_unref (ci1);
827 gst_caps_unref (ci2);
835 c1 = gst_caps_from_string ("video/x-raw,format=(string)I420,width=20");
836 c2 = gst_caps_new_any ();
838 ci1 = gst_caps_intersect (c1, c2);
839 GST_DEBUG ("intersected: %" GST_PTR_FORMAT, ci1);
841 fail_unless (gst_caps_is_equal (ci1, c1));
843 ci2 = gst_caps_intersect (c2, c1);
844 GST_DEBUG ("intersected: %" GST_PTR_FORMAT, ci2);
846 fail_unless (gst_caps_is_equal (ci2, c1));
848 fail_unless (gst_caps_is_equal (ci1, ci2));
850 gst_caps_unref (ci1);
851 gst_caps_unref (ci2);
859 GST_START_TEST (test_intersect2)
861 GstCaps *caps1, *caps2, *icaps;
863 /* tests array subtraction */
864 caps1 = gst_caps_from_string ("audio/x-raw, "
865 "channel-positions=(int)< "
866 "{ 1, 2, 3, 4, 5, 6 }, "
867 "{ 1, 2, 3, 4, 5, 6 }, "
868 "{ 1, 2, 3, 4, 5, 6 }, "
869 "{ 1, 2, 3, 4, 5, 6 }, "
870 "{ 1, 2, 3, 4, 5, 6 }, " "{ 1, 2, 3, 4, 5, 6 }>");
871 caps2 = gst_caps_from_string ("audio/x-raw, "
872 "channel-positions=(int)< 1, 2, 3, 4, 5, 6 >");
873 icaps = gst_caps_intersect (caps1, caps2);
874 GST_LOG ("intersected caps: %" GST_PTR_FORMAT, icaps);
875 fail_if (gst_caps_is_empty (icaps));
876 fail_unless (gst_caps_is_equal (icaps, caps2));
877 gst_caps_unref (caps1);
878 gst_caps_unref (caps2);
879 gst_caps_unref (icaps);
883 caps1 = gst_caps_from_string ("some/type, foo=(int)< { 1, 2 }, { 3, 4} >");
884 caps2 = gst_caps_from_string ("some/type, foo=(int)< 1, 3 >");
885 icaps = gst_caps_intersect (caps1, caps2);
886 GST_LOG ("intersected caps: %" GST_PTR_FORMAT, icaps);
887 fail_if (gst_caps_is_empty (icaps));
888 fail_unless (gst_caps_is_equal (icaps, caps2));
889 gst_caps_unref (caps1);
890 gst_caps_unref (caps2);
891 gst_caps_unref (icaps);
896 GST_START_TEST (test_intersect_list_duplicate)
898 GstCaps *caps1, *caps2, *icaps;
900 /* make sure we don't take too long to intersect these.. */
901 caps1 = gst_caps_from_string ("video/x-raw, format=(string)YV12; "
902 "video/x-raw, format=(string)I420; video/x-raw, format=(string)YUY2; "
903 "video/x-raw, format=(string)UYVY; "
904 "video/x-raw, format=(string){ I420, YV12, YUY2, UYVY, AYUV, RGBx, BGRx,"
905 " xRGB, xBGR, { RGBA, RGBA, { RGBA, RGBA }, "
906 "{ RGBA, RGBA, { RGBA, RGBA } }, { RGBA, RGBA, { RGBA, RGBA }, "
907 "{ RGBA, RGBA, { RGBA, RGBA } } }, { RGBA, RGBA, { RGBA, RGBA }, "
908 "{ RGBA, RGBA, { RGBA, RGBA } }, { RGBA, RGBA, { RGBA, RGBA }, "
909 "{ RGBA, RGBA, { RGBA, RGBA } } } }, { RGBA, RGBA, { RGBA, RGBA }, "
910 "{ RGBA, RGBA, { RGBA, RGBA } }, { RGBA, RGBA, { RGBA, RGBA }, "
911 "{ RGBA, RGBA, { RGBA, RGBA } } }, { RGBA, RGBA, { RGBA, RGBA }, "
912 "{ RGBA, RGBA, { RGBA, RGBA } }, { RGBA, RGBA, { RGBA, RGBA }, "
913 "{ RGBA, RGBA, { RGBA, RGBA } } } } } }, BGRA, ARGB, { ABGR, ABGR, "
914 "{ ABGR, ABGR }, { ABGR, ABGR, { ABGR, ABGR } }, "
915 "{ ABGR, ABGR, { ABGR, ABGR }, { ABGR, ABGR, { ABGR, ABGR } } }, "
916 "{ ABGR, ABGR, { ABGR, ABGR }, { ABGR, ABGR, { ABGR, ABGR } }, "
917 "{ ABGR, ABGR, { ABGR, ABGR }, { ABGR, ABGR, { ABGR, ABGR } } } }, "
918 "{ ABGR, ABGR, { ABGR, ABGR }, { ABGR, ABGR, { ABGR, ABGR } }, "
919 "{ ABGR, ABGR, { ABGR, ABGR }, { ABGR, ABGR, { ABGR, ABGR } } }, "
920 "{ ABGR, ABGR, { ABGR, ABGR }, { ABGR, ABGR, { ABGR, ABGR } }, "
921 "{ ABGR, ABGR, { ABGR, ABGR }, { ABGR, ABGR, { ABGR, ABGR } } } } } }, "
922 "RGB, BGR, Y41B, Y42B, YVYU, Y444 }; "
923 "video/x-raw, format=(string){ I420, YV12, YUY2, UYVY, AYUV, RGBx, BGRx, "
924 "xRGB, xBGR, { RGBA, RGBA, { RGBA, RGBA }, "
925 "{ RGBA, RGBA, { RGBA, RGBA } }, { RGBA, RGBA, { RGBA, RGBA }, "
926 "{ RGBA, RGBA, { RGBA, RGBA } } }, { RGBA, RGBA, { RGBA, RGBA }, "
927 "{ RGBA, RGBA, { RGBA, RGBA } }, { RGBA, RGBA, { RGBA, RGBA }, "
928 "{ RGBA, RGBA, { RGBA, RGBA } } } }, { RGBA, RGBA, { RGBA, RGBA }, "
929 "{ RGBA, RGBA, { RGBA, RGBA } }, { RGBA, RGBA, { RGBA, RGBA }, "
930 "{ RGBA, RGBA, { RGBA, RGBA } } }, { RGBA, RGBA, { RGBA, RGBA }, "
931 "{ RGBA, RGBA, { RGBA, RGBA } }, { RGBA, RGBA, { RGBA, RGBA }, "
932 "{ RGBA, RGBA, { RGBA, RGBA } } } } } }, BGRA, ARGB, "
933 "{ ABGR, ABGR, { ABGR, ABGR }, { ABGR, ABGR, { ABGR, ABGR } }, "
934 "{ ABGR, ABGR, { ABGR, ABGR }, { ABGR, ABGR, { ABGR, ABGR } } }, "
935 "{ ABGR, ABGR, { ABGR, ABGR }, { ABGR, ABGR, { ABGR, ABGR } }, "
936 "{ ABGR, ABGR, { ABGR, ABGR }, { ABGR, ABGR, { ABGR, ABGR } } } }, "
937 "{ ABGR, ABGR, { ABGR, ABGR }, { ABGR, ABGR, { ABGR, ABGR } }, "
938 "{ ABGR, ABGR, { ABGR, ABGR }, { ABGR, ABGR, { ABGR, ABGR } } }, "
939 "{ ABGR, ABGR, { ABGR, ABGR }, { ABGR, ABGR, { ABGR, ABGR } }, "
940 "{ ABGR, ABGR, { ABGR, ABGR }, { ABGR, ABGR, { ABGR, ABGR } } } } } }, "
941 "RGB, BGR, Y41B, Y42B, YVYU, Y444, NV12, NV21 }; "
942 "video/x-raw, format=(string){ I420, YV12, YUY2, UYVY, AYUV, RGBx, "
943 "BGRx, xRGB, xBGR, { RGBA, RGBA, { RGBA, RGBA }, "
944 "{ RGBA, RGBA, { RGBA, RGBA } }, { RGBA, RGBA, { RGBA, RGBA }, "
945 "{ RGBA, RGBA, { RGBA, RGBA } } } }, BGRA, ARGB, "
946 "{ ABGR, ABGR, { ABGR, ABGR }, { ABGR, ABGR, { ABGR, ABGR } }, "
947 "{ ABGR, ABGR, { ABGR, ABGR }, { ABGR, ABGR, { ABGR, ABGR } } } }, "
948 "RGB, BGR, Y41B, Y42B, YVYU, Y444, NV12, NV21 }");
950 caps2 = gst_caps_copy (caps1);
952 icaps = gst_caps_intersect (caps1, caps2);
954 gst_caps_unref (caps1);
955 gst_caps_unref (caps2);
956 gst_caps_unref (icaps);
961 GST_START_TEST (test_intersect_zigzag)
963 GstCaps *caps1, *caps2, *icaps, *result;
965 /* tests if caps order is maintained */
966 caps1 = gst_caps_from_string ("format/A; format/B; format/C; format/D");
967 caps2 = gst_caps_from_string ("format/D; format/A; format/B; format/C");
969 icaps = gst_caps_intersect_full (caps1, caps2, GST_CAPS_INTERSECT_ZIG_ZAG);
970 result = gst_caps_from_string ("format/B; format/A; format/D; format/C");
971 GST_LOG ("intersected caps: %" GST_PTR_FORMAT, icaps);
972 fail_if (gst_caps_is_empty (icaps));
973 fail_unless (gst_caps_is_equal (icaps, result));
974 gst_caps_unref (icaps);
975 gst_caps_unref (result);
977 icaps = gst_caps_intersect_full (caps2, caps1, GST_CAPS_INTERSECT_FIRST);
978 result = gst_caps_from_string ("format/A; format/B; format/D; format/C");
979 GST_LOG ("intersected caps: %" GST_PTR_FORMAT, icaps);
980 fail_if (gst_caps_is_empty (icaps));
981 fail_unless (gst_caps_is_equal (icaps, result));
982 gst_caps_unref (icaps);
983 gst_caps_unref (result);
985 gst_caps_unref (caps1);
986 gst_caps_unref (caps2);
992 GST_START_TEST (test_intersect_first)
994 GstCaps *caps1, *caps2, *icaps, *result;
996 /* tests if caps order is maintained */
997 caps1 = gst_caps_from_string ("format/A; format/B; format/C; format/D");
998 caps2 = gst_caps_from_string ("format/C; format/D; format/A");
999 icaps = gst_caps_intersect_full (caps1, caps2, GST_CAPS_INTERSECT_FIRST);
1000 result = gst_caps_from_string ("format/A; format/C; format/D");
1001 GST_LOG ("intersected caps: %" GST_PTR_FORMAT, icaps);
1002 fail_if (gst_caps_is_empty (icaps));
1003 fail_unless (gst_caps_is_equal (icaps, result));
1004 gst_caps_unref (caps1);
1005 gst_caps_unref (caps2);
1006 gst_caps_unref (icaps);
1007 gst_caps_unref (result);
1013 GST_START_TEST (test_intersect_first2)
1015 GstCaps *caps1, *caps2, *icaps, *result;
1017 /* tests if caps order is maintained */
1018 caps1 = gst_caps_from_string ("format/A; format/B; format/C; format/D");
1019 caps2 = gst_caps_from_string ("format/D; format/A; format/B; format/C");
1021 icaps = gst_caps_intersect_full (caps1, caps2, GST_CAPS_INTERSECT_FIRST);
1022 result = gst_caps_from_string ("format/A; format/B; format/C; format/D");
1023 GST_LOG ("intersected caps: %" GST_PTR_FORMAT, icaps);
1024 fail_if (gst_caps_is_empty (icaps));
1025 fail_unless (gst_caps_is_equal (icaps, result));
1026 gst_caps_unref (icaps);
1027 gst_caps_unref (result);
1029 icaps = gst_caps_intersect_full (caps2, caps1, GST_CAPS_INTERSECT_FIRST);
1030 result = gst_caps_from_string ("format/D; format/A; format/B; format/C");
1031 GST_LOG ("intersected caps: %" GST_PTR_FORMAT, icaps);
1032 fail_if (gst_caps_is_empty (icaps));
1033 fail_unless (gst_caps_is_equal (icaps, result));
1034 gst_caps_unref (icaps);
1035 gst_caps_unref (result);
1037 gst_caps_unref (caps1);
1038 gst_caps_unref (caps2);
1043 GST_START_TEST (test_intersect_duplication)
1045 GstCaps *c1, *c2, *test;
1047 c1 = gst_caps_from_string
1048 ("audio/x-raw, format=(string)S16_LE, rate=(int)[ 1, 2147483647 ], channels=(int)[ 1, 2 ]");
1049 c2 = gst_caps_from_string
1050 ("audio/x-raw, format=(string) { S16_LE, S16_BE, U16_LE, U16_BE }, rate=(int)[ 1, 2147483647 ], channels=(int)[ 1, 2 ]; audio/x-raw, format=(string) { S16_LE, S16_BE, U16_LE, U16_BE }, rate=(int)[ 1, 2147483647 ], channels=(int)[ 1, 11 ]; audio/x-raw, format=(string) { S16_LE, S16_BE, U16_LE, U16_BE }, rate=(int)[ 1, 2147483647 ], channels=(int)[ 1, 11 ]");
1052 test = gst_caps_intersect_full (c1, c2, GST_CAPS_INTERSECT_FIRST);
1053 fail_unless_equals_int (gst_caps_get_size (test), 1);
1054 fail_unless (gst_caps_is_equal (c1, test));
1055 gst_caps_unref (c1);
1056 gst_caps_unref (c2);
1057 gst_caps_unref (test);
1062 GST_START_TEST (test_intersect_flagset)
1064 GstCaps *c1, *c2, *test;
1065 GType test_flagset_type;
1066 GstSeekFlags test_flags, test_mask;
1069 /* Test that matching bits inside the mask intersect,
1070 * and bits outside the mask don't matter */
1071 c1 = gst_caps_from_string ("test/x-caps,field=ffd81d:fffff0");
1072 c2 = gst_caps_from_string ("test/x-caps,field=0fd81f:0ffff0");
1074 test = gst_caps_intersect_full (c1, c2, GST_CAPS_INTERSECT_FIRST);
1075 fail_unless_equals_int (gst_caps_get_size (test), 1);
1076 fail_unless (gst_caps_is_equal (c1, test));
1077 gst_caps_unref (c1);
1078 gst_caps_unref (c2);
1079 gst_caps_unref (test);
1081 /* Test that non-matching bits in the mask don't intersect */
1082 c1 = gst_caps_from_string ("test/x-caps,field=ff001d:0ffff0");
1083 c2 = gst_caps_from_string ("test/x-caps,field=0fd81f:0ffff0");
1085 test = gst_caps_intersect_full (c1, c2, GST_CAPS_INTERSECT_FIRST);
1086 fail_unless (gst_caps_is_empty (test));
1087 gst_caps_unref (c1);
1088 gst_caps_unref (c2);
1089 gst_caps_unref (test);
1091 /* Check custom flags type serialisation and de-serialisation */
1092 test_flagset_type = gst_flagset_register (GST_TYPE_SEEK_FLAGS);
1093 fail_unless (g_type_is_a (test_flagset_type, GST_TYPE_FLAG_SET));
1096 GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_TRICKMODE |
1097 GST_SEEK_FLAG_TRICKMODE_KEY_UNITS;
1099 GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_TRICKMODE |
1100 GST_SEEK_FLAG_TRICKMODE_NO_AUDIO;
1102 c1 = gst_caps_new_simple ("test/x-caps", "field", test_flagset_type,
1103 test_flags, test_mask, NULL);
1105 test_string = gst_caps_to_string (c1);
1106 fail_if (test_string == NULL);
1108 GST_DEBUG ("Serialised caps to %s", test_string);
1109 c2 = gst_caps_from_string (test_string);
1110 g_free (test_string);
1112 fail_unless (gst_caps_is_equal (c1, c2), "Caps %s != %s",
1113 gst_caps_to_string (c1), gst_caps_to_string (c2));
1115 gst_caps_unref (c1);
1116 gst_caps_unref (c2);
1121 GST_START_TEST (test_union)
1123 GstCaps *c1, *c2, *test, *expect;
1125 /* Test that matching bits inside the masks union OK, */
1126 c1 = gst_caps_from_string ("test/x-caps,field=ffd81d:0ffff0");
1127 c2 = gst_caps_from_string ("test/x-caps,field=0fd81f:0ffff0");
1129 test = gst_caps_merge (c1, c2);
1130 test = gst_caps_simplify (test);
1131 /* c1, c2 now invalid */
1132 fail_unless_equals_int (gst_caps_get_size (test), 1);
1133 gst_caps_unref (test);
1135 /* Test that non-intersecting sets of masked bits are OK */
1136 c1 = gst_caps_from_string ("test/x-caps,field=ff001d:0ffff0");
1137 c2 = gst_caps_from_string ("test/x-caps,field=4fd81f:f00000");
1138 expect = gst_caps_from_string ("test/x-caps,field=4f001d:fffff0");
1139 test = gst_caps_simplify (gst_caps_merge (c1, c2));
1140 /* c1, c2 now invalid */
1141 GST_LOG ("Expected caps %" GST_PTR_FORMAT " got %" GST_PTR_FORMAT "\n",
1143 fail_unless (gst_caps_is_equal (test, expect));
1144 gst_caps_unref (test);
1145 gst_caps_unref (expect);
1147 /* Test that partially-intersecting sets of masked bits that match are OK */
1148 c1 = gst_caps_from_string ("test/x-caps,field=ff001d:0ffff0");
1149 c2 = gst_caps_from_string ("test/x-caps,field=4fd81f:ff0000");
1150 expect = gst_caps_from_string ("test/x-caps,field=4f001d:fffff0");
1151 test = gst_caps_simplify (gst_caps_merge (c1, c2));
1152 /* c1, c2 now invalid */
1153 GST_LOG ("Expected caps %" GST_PTR_FORMAT " got %" GST_PTR_FORMAT "\n",
1155 fail_unless (gst_caps_is_equal (test, expect));
1156 gst_caps_unref (test);
1157 gst_caps_unref (expect);
1163 _caps_is_fixed_foreach (GQuark field_id, const GValue * value, gpointer unused)
1165 return gst_value_is_fixed (value);
1169 GST_START_TEST (test_normalize)
1171 GstCaps *in, *norm, *out;
1174 in = gst_caps_from_string ("some/type, foo=(int){ 1 , 2 }");
1175 out = gst_caps_from_string ("some/type, foo=(int) 1; some/type, foo=(int) 2");
1176 norm = gst_caps_normalize (in);
1177 fail_if (gst_caps_is_empty (norm));
1178 fail_unless (gst_caps_is_equal (norm, out));
1179 for (i = 0; i < gst_caps_get_size (norm); i++) {
1180 GstStructure *st = gst_caps_get_structure (norm, i);
1181 /* Make sure all fields of all structures are fixed */
1182 fail_unless (gst_structure_foreach (st, _caps_is_fixed_foreach, NULL));
1185 gst_caps_unref (out);
1186 gst_caps_unref (norm);
1188 in = gst_caps_from_string
1189 ("some/type, foo=(int){ 1 , 2 }, bar=(int){ 3, 4 }");
1191 gst_caps_from_string
1192 ("some/type, foo=(int) 1, bar=(int) 3; some/type, foo=(int) 2, bar=(int) 3;"
1193 "some/type, foo=(int) 1, bar=(int) 4; some/type, foo=(int) 2, bar=(int) 4;");
1194 norm = gst_caps_normalize (in);
1195 fail_if (gst_caps_is_empty (norm));
1196 fail_unless (gst_caps_is_equal (norm, out));
1197 for (i = 0; i < gst_caps_get_size (norm); i++) {
1198 GstStructure *st = gst_caps_get_structure (norm, i);
1199 /* Make sure all fields of all structures are fixed */
1200 fail_unless (gst_structure_foreach (st, _caps_is_fixed_foreach, NULL));
1203 gst_caps_unref (out);
1204 gst_caps_unref (norm);
1206 in = gst_caps_from_string
1207 ("some/type, foo=(string){ 1 , 2 }, bar=(string) { 3 }");
1209 gst_caps_from_string
1210 ("some/type, foo=(string) 1, bar=(string) 3; some/type, foo=(string) 2, bar=(string) 3");
1211 norm = gst_caps_normalize (in);
1212 fail_if (gst_caps_is_empty (norm));
1213 fail_unless (gst_caps_is_equal (norm, out));
1214 for (i = 0; i < gst_caps_get_size (norm); i++) {
1215 GstStructure *st = gst_caps_get_structure (norm, i);
1216 /* Make sure all fields of all structures are fixed */
1217 fail_unless (gst_structure_foreach (st, _caps_is_fixed_foreach, NULL));
1220 gst_caps_unref (out);
1221 gst_caps_unref (norm);
1226 GST_START_TEST (test_broken)
1230 /* NULL is not valid for media_type */
1231 ASSERT_CRITICAL (c1 =
1232 gst_caps_new_simple (NULL, "field", G_TYPE_INT, 1, NULL));
1235 /* such a name is not valid, see gst_structure_validate_name() */
1236 ASSERT_CRITICAL (c1 =
1237 gst_caps_new_simple ("1#@abc", "field", G_TYPE_INT, 1, NULL));
1240 c1 = gst_caps_new_empty_simple ("test/broken-fraction");
1242 /* denominator must be non-zero value */
1243 ASSERT_CRITICAL (gst_caps_set_simple (c1, "foo", GST_TYPE_FRACTION, 1, 0,
1245 gst_caps_unref (c1);
1250 GST_START_TEST (test_features)
1252 GstCaps *c1, *c2, *c3;
1253 GstStructure *s1, *s2;
1254 GstCapsFeatures *f1, *f2;
1256 static GstStaticCaps scaps =
1258 ("video/x-raw(memory:EGLImage), width=320, height=[ 240, 260 ]");
1260 c1 = gst_caps_new_empty ();
1261 fail_unless (c1 != NULL);
1262 s1 = gst_structure_new ("video/x-raw", "width", G_TYPE_INT, 320, "height",
1263 GST_TYPE_INT_RANGE, 240, 260, NULL);
1264 fail_unless (s1 != NULL);
1265 f1 = gst_caps_features_new ("memory:EGLImage", NULL);
1266 fail_unless (f1 != NULL);
1268 gst_caps_append_structure_full (c1, s1, f1);
1269 s2 = gst_caps_get_structure (c1, 0);
1270 fail_unless (s1 == s2);
1271 f2 = gst_caps_get_features (c1, 0);
1272 fail_unless (f1 == f2);
1274 str1 = gst_caps_to_string (c1);
1275 fail_unless (str1 != NULL);
1276 c2 = gst_caps_from_string (str1);
1277 fail_unless (c2 != NULL);
1280 fail_unless (gst_caps_is_equal (c1, c2));
1281 fail_unless (gst_caps_is_subset (c1, c2));
1282 fail_unless (gst_caps_is_subset (c2, c1));
1283 fail_unless (gst_caps_can_intersect (c1, c2));
1285 gst_caps_unref (c2);
1287 c2 = gst_caps_new_empty ();
1288 fail_unless (c2 != NULL);
1289 s2 = gst_structure_new ("video/x-raw", "width", G_TYPE_INT, 320, "height",
1290 GST_TYPE_INT_RANGE, 240, 260, NULL);
1291 fail_unless (s2 != NULL);
1292 f2 = gst_caps_features_new ("memory:VASurface", "meta:VAMeta", NULL);
1293 fail_unless (f2 != NULL);
1294 gst_caps_append_structure_full (c2, s2, f2);
1296 fail_if (gst_caps_is_equal (c1, c2));
1297 fail_if (gst_caps_is_subset (c1, c2));
1298 fail_if (gst_caps_is_subset (c2, c1));
1299 fail_if (gst_caps_can_intersect (c1, c2));
1301 str1 = gst_caps_to_string (c2);
1302 fail_unless (str1 != NULL);
1303 c3 = gst_caps_from_string (str1);
1304 fail_unless (c3 != NULL);
1307 fail_unless (gst_caps_is_equal (c2, c3));
1308 fail_unless (gst_caps_is_subset (c2, c3));
1309 fail_unless (gst_caps_is_subset (c3, c2));
1310 fail_unless (gst_caps_can_intersect (c2, c3));
1312 f1 = gst_caps_get_features (c3, 0);
1313 fail_unless (f1 != NULL);
1315 gst_caps_features_contains (f1, "memory:VASurface");
1316 gst_caps_features_remove (f1, "memory:VASurface");
1317 fail_if (gst_caps_is_equal (c2, c3));
1318 fail_if (gst_caps_is_subset (c2, c3));
1319 fail_if (gst_caps_is_subset (c3, c2));
1320 fail_if (gst_caps_can_intersect (c2, c3));
1322 gst_caps_unref (c3);
1323 gst_caps_unref (c2);
1325 c2 = gst_static_caps_get (&scaps);
1326 fail_unless (c2 != NULL);
1327 fail_unless (gst_caps_is_equal (c1, c2));
1328 fail_unless (gst_caps_is_subset (c1, c2));
1329 fail_unless (gst_caps_is_subset (c2, c1));
1330 fail_unless (gst_caps_can_intersect (c1, c2));
1331 gst_caps_unref (c2);
1333 c2 = gst_caps_from_string
1334 ("video/x-raw(ANY), width=320, height=[ 240, 260 ]");
1335 fail_unless (c2 != NULL);
1336 fail_if (gst_caps_is_equal (c1, c2));
1337 fail_unless (gst_caps_is_subset (c1, c2));
1338 fail_if (gst_caps_is_subset (c2, c1));
1339 fail_unless (gst_caps_can_intersect (c1, c2));
1341 c3 = gst_caps_intersect (c1, c2);
1342 fail_unless (gst_caps_is_equal (c3, c1));
1344 gst_caps_unref (c3);
1345 gst_caps_unref (c2);
1346 gst_caps_unref (c1);
1348 c1 = gst_caps_from_string ("video/x-raw");
1349 c2 = gst_caps_from_string ("video/x-raw");
1351 f1 = gst_caps_get_features (c1, 0);
1352 gst_caps_features_add (f1, "memory:VASurface");
1354 fail_unless (gst_caps_features_is_equal (f1, gst_caps_get_features (c1, 0)));
1355 fail_if (gst_caps_can_intersect (c1, c2));
1357 f2 = gst_caps_get_features (c2, 0);
1358 fail_unless (gst_caps_features_is_equal
1359 (GST_CAPS_FEATURES_MEMORY_SYSTEM_MEMORY, f2));
1361 gst_caps_unref (c2);
1362 gst_caps_unref (c1);
1364 c1 = gst_caps_from_string ("video/x-raw");
1365 f1 = gst_caps_get_features (c1, 0);
1366 f2 = gst_caps_features_new ("memory:dmabuf", NULL);
1367 gst_caps_set_features (c1, 0, f2);
1369 gst_caps_unref (c1);
1371 /* gst_caps_set_features_simple() */
1372 c1 = gst_caps_from_string
1373 ("video/x-raw, format=NV12; video/x-raw, format=NV16");
1374 fail_unless_equals_int (gst_caps_get_size (c1), 2);
1376 f1 = gst_caps_features_new ("memory:EGLImage", NULL);
1377 gst_caps_set_features_simple (c1, f1);
1379 f2 = gst_caps_get_features (c1, 0);
1380 fail_unless (gst_caps_features_is_equal (f1, f2));
1381 f2 = gst_caps_get_features (c1, 1);
1382 fail_unless (gst_caps_features_is_equal (f1, f2));
1384 gst_caps_unref (c1);
1386 c1 = gst_caps_new_any ();
1387 fail_unless_equals_int (gst_caps_get_size (c1), 0);
1389 f1 = gst_caps_features_new ("memory:EGLImage", NULL);
1390 /* Nothing to set the features on, but method should still take
1391 * ownership of the given features */
1392 gst_caps_set_features_simple (c1, f1);
1393 fail_unless_equals_int (gst_caps_get_size (c1), 0);
1394 fail_unless (gst_caps_is_any (c1));
1396 gst_caps_unref (c1);
1401 GST_START_TEST (test_special_caps)
1405 caps = gst_caps_new_any ();
1406 fail_unless (gst_caps_is_any (caps));
1407 fail_unless (gst_caps_is_any (caps) == TRUE);
1408 fail_if (gst_caps_is_empty (caps));
1409 fail_unless (gst_caps_is_empty (caps) == FALSE);
1410 gst_caps_unref (caps);
1412 caps = gst_caps_new_empty ();
1413 fail_if (gst_caps_is_any (caps));
1414 fail_unless (gst_caps_is_any (caps) == FALSE);
1415 fail_unless (gst_caps_is_empty (caps));
1416 fail_unless (gst_caps_is_empty (caps) == TRUE);
1417 gst_caps_unref (caps);
1423 foreach_append_function (GstCapsFeatures * features, GstStructure * structure,
1426 GstCaps *caps = user_data;
1428 gst_caps_append_structure_full (caps, gst_structure_copy (structure),
1429 features ? gst_caps_features_copy (features) : NULL);
1434 GST_START_TEST (test_foreach)
1436 GstCaps *caps, *caps2;
1439 gst_caps_from_string
1440 ("video/x-raw, format=I420; video/x-raw(foo:bar); video/x-h264");
1441 caps2 = gst_caps_new_empty ();
1442 fail_unless (gst_caps_foreach (caps, foreach_append_function, caps2));
1443 fail_unless (gst_caps_is_strictly_equal (caps, caps2));
1444 gst_caps_unref (caps);
1445 gst_caps_unref (caps2);
1447 caps = gst_caps_new_empty ();
1448 caps2 = gst_caps_new_empty ();
1449 fail_unless (gst_caps_foreach (caps, foreach_append_function, caps2));
1450 fail_unless (gst_caps_is_strictly_equal (caps, caps2));
1451 gst_caps_unref (caps);
1452 gst_caps_unref (caps2);
1458 map_function (GstCapsFeatures * features, GstStructure * structure,
1461 /* Remove caps features if there are any, otherwise add some dummy */
1462 if (gst_caps_features_contains (features, "foo:bar")) {
1463 gst_caps_features_remove (features, "foo:bar");
1465 gst_caps_features_add (features, "foo:bar");
1466 gst_caps_features_remove (features, GST_CAPS_FEATURE_MEMORY_SYSTEM_MEMORY);
1469 /* Set some dummy integer in the structure */
1470 gst_structure_set (structure, "foo", G_TYPE_INT, 123, NULL);
1475 GST_START_TEST (test_map_in_place)
1477 GstCaps *caps, *caps2;
1480 gst_caps_from_string
1481 ("video/x-raw, format=I420; video/x-raw(foo:bar); video/x-h264");
1483 gst_caps_from_string
1484 ("video/x-raw(foo:bar), foo=(int)123, format=I420; video/x-raw, foo=(int)123; video/x-h264(foo:bar), foo=(int)123");
1485 fail_unless (gst_caps_map_in_place (caps, map_function, NULL));
1486 fail_unless (gst_caps_is_strictly_equal (caps, caps2));
1487 gst_caps_unref (caps);
1488 gst_caps_unref (caps2);
1490 caps = gst_caps_new_empty ();
1491 caps2 = gst_caps_new_empty ();
1492 fail_unless (gst_caps_map_in_place (caps, map_function, NULL));
1493 fail_unless (gst_caps_is_strictly_equal (caps, caps2));
1494 gst_caps_unref (caps);
1495 gst_caps_unref (caps2);
1501 filter_map_function (GstCapsFeatures * features, GstStructure * structure,
1504 if (!gst_structure_has_name (structure, "video/x-raw"))
1507 if (!gst_caps_features_contains (features, "foo:bar"))
1510 /* Set some dummy integer in the structure */
1511 gst_structure_set (structure, "foo", G_TYPE_INT, 123, NULL);
1516 GST_START_TEST (test_filter_and_map_in_place)
1518 GstCaps *caps, *caps2;
1521 gst_caps_from_string
1522 ("video/x-raw, format=I420; video/x-raw(foo:bar); video/x-h264");
1523 caps2 = gst_caps_from_string ("video/x-raw(foo:bar), foo=(int)123");
1524 gst_caps_filter_and_map_in_place (caps, filter_map_function, NULL);
1525 fail_unless (gst_caps_is_strictly_equal (caps, caps2));
1526 gst_caps_unref (caps);
1527 gst_caps_unref (caps2);
1529 caps = gst_caps_from_string ("video/x-raw, format=I420; video/x-h264");
1530 caps2 = gst_caps_new_empty ();
1531 gst_caps_filter_and_map_in_place (caps, filter_map_function, NULL);
1532 fail_unless (gst_caps_is_strictly_equal (caps, caps2));
1533 gst_caps_unref (caps);
1534 gst_caps_unref (caps2);
1536 caps = gst_caps_new_empty ();
1537 caps2 = gst_caps_new_empty ();
1538 gst_caps_filter_and_map_in_place (caps, filter_map_function, NULL);
1539 fail_unless (gst_caps_is_strictly_equal (caps, caps2));
1540 gst_caps_unref (caps);
1541 gst_caps_unref (caps2);
1546 GST_START_TEST (test_equality)
1548 GstCaps *empty1, *empty2, *any1, *any2, *caps1, *caps2, *caps3, *caps4,
1549 *caps5, *caps6, *caps7, *caps8, *caps9;
1552 empty1 = gst_caps_new_empty ();
1554 empty2 = gst_caps_new_empty ();
1556 any1 = gst_caps_new_any ();
1558 any2 = gst_caps_new_any ();
1559 s = gst_structure_new ("structure", "int", G_TYPE_INT, 4, "float",
1560 G_TYPE_FLOAT, 5.7, NULL);
1562 gst_caps_append_structure (any2, s);
1563 /* should still be ANY after append */
1565 caps1 = gst_caps_new_simple ("structure", "int", G_TYPE_INT, 4, "float",
1566 G_TYPE_FLOAT, 5.7, NULL);
1567 fail_unless (caps1);
1569 caps2 = gst_caps_new_simple ("structure", "int", G_TYPE_INT, 4, "float",
1570 G_TYPE_FLOAT, 5.7, NULL);
1571 fail_unless (caps2);
1572 /* append an identical structure */
1573 s = gst_structure_new ("structure", "int", G_TYPE_INT, 4, "float",
1574 G_TYPE_FLOAT, 5.7, NULL);
1576 gst_caps_append_structure (caps2, s);
1578 /* change field name */
1579 caps3 = gst_caps_new_simple ("structure", "intX", G_TYPE_INT, 4, "float",
1580 G_TYPE_FLOAT, 5.7, NULL);
1581 fail_unless (caps3);
1583 /* change field type */
1584 caps4 = gst_caps_new_simple ("structure", "int", G_TYPE_UINT, 4, "float",
1585 G_TYPE_FLOAT, 5.7, NULL);
1586 fail_unless (caps4);
1588 /* change structure name */
1589 caps5 = gst_caps_new_simple ("structureX", "int", G_TYPE_INT, 4, "float",
1590 G_TYPE_FLOAT, 5.7, NULL);
1591 fail_unless (caps5);
1593 /* change field value */
1594 caps6 = gst_caps_new_simple ("structure", "int", G_TYPE_INT, 3, "float",
1595 G_TYPE_FLOAT, 5.7, NULL);
1596 fail_unless (caps6);
1598 /* change caps features */
1599 caps7 = gst_caps_new_simple ("structure", "int", G_TYPE_INT, 4, "float",
1600 G_TYPE_FLOAT, 5.7, NULL);
1601 fail_unless (caps6);
1602 gst_caps_set_features (caps7, 0, gst_caps_features_new_any ());
1605 caps8 = gst_caps_new_simple ("structure", "int", G_TYPE_INT, 4, "float",
1606 G_TYPE_FLOAT, 5.7, NULL);
1607 fail_unless (caps8);
1608 s = gst_structure_new ("structure2", "string", G_TYPE_STRING, "val", NULL);
1610 gst_caps_append_structure (caps8, s);
1612 /* reverse the order of the structures */
1613 caps9 = gst_caps_new_simple ("structure2", "string", G_TYPE_STRING, "val",
1615 fail_unless (caps9);
1616 s = gst_structure_new ("structure", "int", G_TYPE_INT, 4, "float",
1617 G_TYPE_FLOAT, 5.7, NULL);
1619 gst_caps_append_structure (caps9, s);
1621 fail_unless (gst_caps_is_equal (empty1, empty2) == TRUE);
1622 fail_unless (gst_caps_is_strictly_equal (empty1, empty2) == TRUE);
1623 fail_unless (gst_caps_is_equal (empty1, any1) == FALSE);
1624 fail_unless (gst_caps_is_strictly_equal (empty1, any1) == FALSE);
1625 fail_unless (gst_caps_is_equal (empty1, any2) == FALSE);
1626 fail_unless (gst_caps_is_strictly_equal (empty1, any2) == FALSE);
1627 fail_unless (gst_caps_is_equal (empty1, caps1) == FALSE);
1628 fail_unless (gst_caps_is_strictly_equal (empty1, caps1) == FALSE);
1629 fail_unless (gst_caps_is_equal (empty1, caps2) == FALSE);
1630 fail_unless (gst_caps_is_strictly_equal (empty1, caps2) == FALSE);
1631 fail_unless (gst_caps_is_equal (empty1, caps3) == FALSE);
1632 fail_unless (gst_caps_is_strictly_equal (empty1, caps3) == FALSE);
1633 fail_unless (gst_caps_is_equal (empty1, caps4) == FALSE);
1634 fail_unless (gst_caps_is_strictly_equal (empty1, caps4) == FALSE);
1635 fail_unless (gst_caps_is_equal (empty1, caps5) == FALSE);
1636 fail_unless (gst_caps_is_strictly_equal (empty1, caps5) == FALSE);
1637 fail_unless (gst_caps_is_equal (empty1, caps6) == FALSE);
1638 fail_unless (gst_caps_is_strictly_equal (empty1, caps6) == FALSE);
1639 fail_unless (gst_caps_is_equal (empty1, caps7) == FALSE);
1640 fail_unless (gst_caps_is_strictly_equal (empty1, caps7) == FALSE);
1641 fail_unless (gst_caps_is_equal (empty1, caps8) == FALSE);
1642 fail_unless (gst_caps_is_strictly_equal (empty1, caps8) == FALSE);
1643 fail_unless (gst_caps_is_equal (empty1, caps9) == FALSE);
1644 fail_unless (gst_caps_is_strictly_equal (empty1, caps9) == FALSE);
1646 fail_unless (gst_caps_is_equal (any1, any2) == TRUE);
1647 fail_unless (gst_caps_is_strictly_equal (any1, any2) == TRUE);
1648 fail_unless (gst_caps_is_equal (any1, caps1) == FALSE);
1649 fail_unless (gst_caps_is_strictly_equal (any1, caps1) == FALSE);
1650 fail_unless (gst_caps_is_equal (any1, caps2) == FALSE);
1651 fail_unless (gst_caps_is_strictly_equal (any1, caps2) == FALSE);
1652 fail_unless (gst_caps_is_equal (any1, caps3) == FALSE);
1653 fail_unless (gst_caps_is_strictly_equal (any1, caps3) == FALSE);
1654 fail_unless (gst_caps_is_equal (any1, caps4) == FALSE);
1655 fail_unless (gst_caps_is_strictly_equal (any1, caps4) == FALSE);
1656 fail_unless (gst_caps_is_equal (any1, caps5) == FALSE);
1657 fail_unless (gst_caps_is_strictly_equal (any1, caps5) == FALSE);
1658 fail_unless (gst_caps_is_equal (any1, caps6) == FALSE);
1659 fail_unless (gst_caps_is_strictly_equal (any1, caps6) == FALSE);
1660 fail_unless (gst_caps_is_equal (any1, caps7) == FALSE);
1661 fail_unless (gst_caps_is_strictly_equal (any1, caps7) == FALSE);
1662 fail_unless (gst_caps_is_equal (any1, caps8) == FALSE);
1663 fail_unless (gst_caps_is_strictly_equal (any1, caps8) == FALSE);
1664 fail_unless (gst_caps_is_equal (any1, caps9) == FALSE);
1665 fail_unless (gst_caps_is_strictly_equal (any1, caps9) == FALSE);
1667 fail_unless (gst_caps_is_equal (any2, caps1) == FALSE);
1668 fail_unless (gst_caps_is_strictly_equal (any2, caps1) == FALSE);
1669 fail_unless (gst_caps_is_equal (any2, caps2) == FALSE);
1670 fail_unless (gst_caps_is_strictly_equal (any2, caps2) == FALSE);
1671 fail_unless (gst_caps_is_equal (any2, caps3) == FALSE);
1672 fail_unless (gst_caps_is_strictly_equal (any2, caps3) == FALSE);
1673 fail_unless (gst_caps_is_equal (any2, caps4) == FALSE);
1674 fail_unless (gst_caps_is_strictly_equal (any2, caps4) == FALSE);
1675 fail_unless (gst_caps_is_equal (any2, caps5) == FALSE);
1676 fail_unless (gst_caps_is_strictly_equal (any2, caps5) == FALSE);
1677 fail_unless (gst_caps_is_equal (any2, caps6) == FALSE);
1678 fail_unless (gst_caps_is_strictly_equal (any2, caps6) == FALSE);
1679 fail_unless (gst_caps_is_equal (any2, caps7) == FALSE);
1680 fail_unless (gst_caps_is_strictly_equal (any2, caps7) == FALSE);
1681 fail_unless (gst_caps_is_equal (any2, caps8) == FALSE);
1682 fail_unless (gst_caps_is_strictly_equal (any2, caps8) == FALSE);
1683 fail_unless (gst_caps_is_equal (any2, caps9) == FALSE);
1684 fail_unless (gst_caps_is_strictly_equal (any2, caps9) == FALSE);
1686 /* caps1 and caps2 are equal, but not strictly equal because one has
1687 * two copies of the same structure */
1688 fail_unless (gst_caps_is_equal (caps1, caps2) == TRUE);
1689 fail_unless (gst_caps_is_strictly_equal (caps1, caps2) == FALSE);
1690 fail_unless (gst_caps_is_equal (caps1, caps3) == FALSE);
1691 fail_unless (gst_caps_is_strictly_equal (caps1, caps3) == FALSE);
1692 fail_unless (gst_caps_is_equal (caps1, caps4) == FALSE);
1693 fail_unless (gst_caps_is_strictly_equal (caps1, caps4) == FALSE);
1694 fail_unless (gst_caps_is_equal (caps1, caps5) == FALSE);
1695 fail_unless (gst_caps_is_strictly_equal (caps1, caps5) == FALSE);
1696 fail_unless (gst_caps_is_equal (caps1, caps6) == FALSE);
1697 fail_unless (gst_caps_is_strictly_equal (caps1, caps6) == FALSE);
1698 fail_unless (gst_caps_is_equal (caps1, caps7) == FALSE);
1699 fail_unless (gst_caps_is_strictly_equal (caps1, caps7) == FALSE);
1700 fail_unless (gst_caps_is_equal (caps1, caps8) == FALSE);
1701 fail_unless (gst_caps_is_strictly_equal (caps1, caps8) == FALSE);
1702 fail_unless (gst_caps_is_equal (caps1, caps9) == FALSE);
1703 fail_unless (gst_caps_is_strictly_equal (caps1, caps9) == FALSE);
1705 fail_unless (gst_caps_is_equal (caps2, caps3) == FALSE);
1706 fail_unless (gst_caps_is_strictly_equal (caps2, caps3) == FALSE);
1707 fail_unless (gst_caps_is_equal (caps2, caps4) == FALSE);
1708 fail_unless (gst_caps_is_strictly_equal (caps2, caps4) == FALSE);
1709 fail_unless (gst_caps_is_equal (caps2, caps5) == FALSE);
1710 fail_unless (gst_caps_is_strictly_equal (caps2, caps5) == FALSE);
1711 fail_unless (gst_caps_is_equal (caps2, caps6) == FALSE);
1712 fail_unless (gst_caps_is_strictly_equal (caps2, caps6) == FALSE);
1713 fail_unless (gst_caps_is_equal (caps2, caps7) == FALSE);
1714 fail_unless (gst_caps_is_strictly_equal (caps2, caps7) == FALSE);
1715 fail_unless (gst_caps_is_equal (caps2, caps8) == FALSE);
1716 fail_unless (gst_caps_is_strictly_equal (caps2, caps8) == FALSE);
1717 fail_unless (gst_caps_is_equal (caps2, caps9) == FALSE);
1718 fail_unless (gst_caps_is_strictly_equal (caps2, caps9) == FALSE);
1720 /* caps8 and caps9 are equal, but not strictly equal because their
1721 * order of structures is different */
1722 fail_unless (gst_caps_is_equal (caps8, caps9) == TRUE);
1723 fail_unless (gst_caps_is_strictly_equal (caps8, caps9) == FALSE);
1725 gst_caps_unref (empty1);
1726 gst_caps_unref (empty2);
1727 gst_caps_unref (any1);
1728 gst_caps_unref (any2);
1729 gst_caps_unref (caps1);
1730 gst_caps_unref (caps2);
1731 gst_caps_unref (caps3);
1732 gst_caps_unref (caps4);
1733 gst_caps_unref (caps5);
1734 gst_caps_unref (caps6);
1735 gst_caps_unref (caps7);
1736 gst_caps_unref (caps8);
1737 gst_caps_unref (caps9);
1742 GST_START_TEST (test_remains_any)
1744 GstCaps *any, *caps;
1747 /* test append structure to ANY */
1748 any = gst_caps_new_any ();
1749 fail_unless (gst_caps_is_any (any));
1750 fail_if (gst_caps_get_size (any));
1751 s = gst_structure_new ("structure", "int", G_TYPE_INT, 4, NULL);
1753 gst_caps_append_structure (any, s);
1754 fail_unless (gst_caps_is_any (any));
1755 fail_if (gst_caps_get_size (any));
1756 ASSERT_CRITICAL (gst_caps_get_structure (any, 0));
1758 s = gst_structure_new ("structure", "int", G_TYPE_INT, 4, NULL);
1760 gst_caps_append_structure_full (any, s, gst_caps_features_new_any ());
1761 fail_unless (gst_caps_is_any (any));
1762 fail_if (gst_caps_get_size (any));
1763 ASSERT_CRITICAL (gst_caps_get_structure (any, 0));
1765 /* test merge structure with ANY */
1766 s = gst_structure_new ("structure", "int", G_TYPE_INT, 4, NULL);
1768 any = gst_caps_merge_structure (any, s);
1769 fail_unless (gst_caps_is_any (any));
1770 fail_if (gst_caps_get_size (any));
1771 ASSERT_CRITICAL (gst_caps_get_structure (any, 0));
1773 s = gst_structure_new ("structure", "int", G_TYPE_INT, 4, NULL);
1775 any = gst_caps_merge_structure_full (any, s, gst_caps_features_new_any ());
1776 fail_unless (gst_caps_is_any (any));
1777 fail_if (gst_caps_get_size (any));
1778 ASSERT_CRITICAL (gst_caps_get_structure (any, 0));
1780 /* test appending non-ANY to ANY */
1781 caps = gst_caps_new_simple ("structure", "int", G_TYPE_INT, 4, NULL);
1783 gst_caps_append (any, caps);
1784 fail_unless (gst_caps_is_any (any));
1785 fail_if (gst_caps_get_size (any));
1786 ASSERT_CRITICAL (gst_caps_get_structure (any, 0));
1788 /* test merging non-ANY with ANY */
1789 caps = gst_caps_new_simple ("structure", "int", G_TYPE_INT, 4, NULL);
1791 any = gst_caps_merge (any, caps);
1792 fail_unless (gst_caps_is_any (any));
1793 fail_if (gst_caps_get_size (any));
1794 ASSERT_CRITICAL (gst_caps_get_structure (any, 0));
1796 caps = gst_caps_new_simple ("structure", "int", G_TYPE_INT, 4, NULL);
1798 any = gst_caps_merge (caps, any);
1799 fail_unless (gst_caps_is_any (any));
1800 fail_if (gst_caps_get_size (any));
1801 ASSERT_CRITICAL (gst_caps_get_structure (any, 0));
1803 gst_caps_unref (any);
1805 /* test appending ANY to non-ANY */
1806 caps = gst_caps_new_simple ("structure", "int", G_TYPE_INT, 4, NULL);
1808 fail_unless_equals_int (gst_caps_get_size (caps), 1);
1809 fail_unless (gst_caps_get_structure (caps, 0));
1810 gst_caps_append (caps, gst_caps_new_any ());
1811 fail_unless (gst_caps_is_any (caps));
1812 fail_if (gst_caps_get_size (caps));
1813 ASSERT_CRITICAL (gst_caps_get_structure (caps, 0));
1815 gst_caps_unref (caps);
1821 gst_caps_suite (void)
1823 Suite *s = suite_create ("GstCaps");
1824 TCase *tc_chain = tcase_create ("operations");
1826 suite_add_tcase (s, tc_chain);
1827 tcase_add_test (tc_chain, test_from_string);
1828 tcase_add_test (tc_chain, test_double_append);
1829 tcase_add_test (tc_chain, test_mutability);
1830 tcase_add_test (tc_chain, test_static_caps);
1831 tcase_add_test (tc_chain, test_simplify);
1832 tcase_add_test (tc_chain, test_truncate);
1833 tcase_add_test (tc_chain, test_fixate);
1834 tcase_add_test (tc_chain, test_subset);
1835 tcase_add_test (tc_chain, test_subset_duplication);
1836 tcase_add_test (tc_chain, test_merge_fundamental);
1837 tcase_add_test (tc_chain, test_merge_same);
1838 tcase_add_test (tc_chain, test_merge_subset);
1839 tcase_add_test (tc_chain, test_intersect);
1840 tcase_add_test (tc_chain, test_intersect2);
1841 tcase_add_test (tc_chain, test_intersect_list_duplicate);
1842 tcase_add_test (tc_chain, test_intersect_zigzag);
1843 tcase_add_test (tc_chain, test_intersect_first);
1844 tcase_add_test (tc_chain, test_intersect_first2);
1845 tcase_add_test (tc_chain, test_intersect_duplication);
1846 tcase_add_test (tc_chain, test_intersect_flagset);
1847 tcase_add_test (tc_chain, test_union);
1848 tcase_add_test (tc_chain, test_normalize);
1849 tcase_add_test (tc_chain, test_broken);
1850 tcase_add_test (tc_chain, test_features);
1851 tcase_add_test (tc_chain, test_special_caps);
1852 tcase_add_test (tc_chain, test_foreach);
1853 tcase_add_test (tc_chain, test_map_in_place);
1854 tcase_add_test (tc_chain, test_filter_and_map_in_place);
1855 tcase_add_test (tc_chain, test_equality);
1856 tcase_add_test (tc_chain, test_remains_any);
1861 GST_CHECK_MAIN (gst_caps);