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.
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 (to_str);
43 fail_if (caps2 == NULL, "Could not create caps from string %s\n", to_str);
45 fail_unless (gst_caps_is_equal (caps, caps));
46 fail_unless (gst_caps_is_equal (caps, caps2));
48 gst_caps_unref (caps);
49 gst_caps_unref (caps2);
56 GST_START_TEST (test_double_append)
61 c1 = gst_caps_new_any ();
62 s1 = gst_structure_from_string ("audio/x-raw,rate=44100", NULL);
63 gst_caps_append_structure (c1, s1);
64 ASSERT_CRITICAL (gst_caps_append_structure (c1, s1));
71 GST_START_TEST (test_mutability)
77 c1 = gst_caps_new_any ();
78 s1 = gst_structure_from_string ("audio/x-raw,rate=44100", NULL);
79 gst_structure_set (s1, "rate", G_TYPE_INT, 48000, NULL);
80 gst_caps_append_structure (c1, s1);
81 gst_structure_set (s1, "rate", G_TYPE_INT, 22500, NULL);
83 ASSERT_CRITICAL (gst_structure_set (s1, "rate", G_TYPE_INT, 11250, NULL));
84 fail_unless (gst_structure_get_int (s1, "rate", &ret));
85 fail_unless (ret == 22500);
86 ASSERT_CRITICAL (gst_caps_set_simple (c1, "rate", G_TYPE_INT, 11250, NULL));
87 fail_unless (gst_structure_get_int (s1, "rate", &ret));
88 fail_unless (ret == 22500);
90 gst_structure_set (s1, "rate", G_TYPE_INT, 11250, NULL);
91 fail_unless (gst_structure_get_int (s1, "rate", &ret));
92 fail_unless (ret == 11250);
93 gst_caps_set_simple (c1, "rate", G_TYPE_INT, 1, NULL);
94 fail_unless (gst_structure_get_int (s1, "rate", &ret));
95 fail_unless (ret == 1);
101 GST_START_TEST (test_static_caps)
103 static GstStaticCaps scaps = GST_STATIC_CAPS ("audio/x-raw,rate=44100");
106 static GstStaticCaps sany = GST_STATIC_CAPS_ANY;
107 static GstStaticCaps snone = GST_STATIC_CAPS_NONE;
110 caps1 = gst_static_caps_get (&scaps);
111 fail_unless (caps1 != NULL);
112 /* 1 refcount core, one from us */
113 fail_unless (GST_CAPS_REFCOUNT (caps1) == 2);
115 /* caps should be the same */
116 caps2 = gst_static_caps_get (&scaps);
117 fail_unless (caps2 != NULL);
118 /* 1 refcount core, two from us */
119 fail_unless (GST_CAPS_REFCOUNT (caps1) == 3);
120 /* caps must be equal */
121 fail_unless (caps1 == caps2);
123 gst_caps_unref (caps1);
124 gst_caps_unref (caps2);
126 caps1 = gst_static_caps_get (&sany);
127 fail_unless (gst_caps_is_equal (caps1, GST_CAPS_ANY));
128 caps2 = gst_static_caps_get (&snone);
129 fail_unless (gst_caps_is_equal (caps2, GST_CAPS_NONE));
130 fail_if (gst_caps_is_equal (caps1, caps2));
131 gst_caps_unref (caps1);
132 gst_caps_unref (caps2);
137 static const gchar non_simple_caps_string[] =
138 "video/x-raw, format=(string)I420, framerate=(fraction)[ 1/100, 100 ], "
139 "width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ]; video/x-raw, "
140 "format=(string)YUY2, framerate=(fraction)[ 1/100, 100 ], width=(int)[ 16, 4096 ], "
141 "height=(int)[ 16, 4096 ]; video/x-raw, format=(string)RGB8_PALETTED, "
142 "framerate=(fraction)[ 1/100, 100 ], width=(int)[ 16, 4096 ], "
143 "height=(int)[ 16, 4096 ]; video/x-raw, "
144 "format=(string){ I420, YUY2, YV12 }, width=(int)[ 16, 4096 ], "
145 "height=(int)[ 16, 4096 ], framerate=(fraction)[ 1/100, 100 ]";
148 check_string_list (const GValue * format_value)
150 const GValue *string_value;
151 gboolean got_rgb8 = FALSE;
152 gboolean got_yv12 = FALSE;
153 gboolean got_i420 = FALSE;
154 gboolean got_yuy2 = FALSE;
157 string_value = gst_value_list_get_value (format_value, 0);
158 fail_unless (string_value != NULL);
159 fail_unless (G_VALUE_HOLDS_STRING (string_value));
160 string = g_value_get_string (string_value);
161 fail_unless (string != NULL);
162 got_rgb8 = got_rgb8 || (g_str_equal (string, "RGB8_PALETTED"));
163 got_i420 = got_i420 || (g_str_equal (string, "I420"));
164 got_yuy2 = got_yuy2 || (g_str_equal (string, "YUY2"));
165 got_yv12 = got_yv12 || (g_str_equal (string, "YV12"));
167 string_value = gst_value_list_get_value (format_value, 1);
168 fail_unless (string_value != NULL);
169 fail_unless (G_VALUE_HOLDS_STRING (string_value));
170 string = g_value_get_string (string_value);
171 fail_unless (string != NULL);
172 got_rgb8 = got_rgb8 || (g_str_equal (string, "RGB8_PALETTED"));
173 got_i420 = got_i420 || (g_str_equal (string, "I420"));
174 got_yuy2 = got_yuy2 || (g_str_equal (string, "YUY2"));
175 got_yv12 = got_yv12 || (g_str_equal (string, "YV12"));
177 string_value = gst_value_list_get_value (format_value, 2);
178 fail_unless (string_value != NULL);
179 fail_unless (G_VALUE_HOLDS_STRING (string_value));
180 string = g_value_get_string (string_value);
181 fail_unless (string != NULL);
182 got_rgb8 = got_rgb8 || (g_str_equal (string, "RGB8_PALETTED"));
183 got_i420 = got_i420 || (g_str_equal (string, "I420"));
184 got_yuy2 = got_yuy2 || (g_str_equal (string, "YUY2"));
185 got_yv12 = got_yv12 || (g_str_equal (string, "YV12"));
187 string_value = gst_value_list_get_value (format_value, 3);
188 fail_unless (string_value != NULL);
189 fail_unless (G_VALUE_HOLDS_STRING (string_value));
190 string = g_value_get_string (string_value);
191 fail_unless (string != NULL);
192 got_rgb8 = got_rgb8 || (g_str_equal (string, "RGB8_PALETTED"));
193 got_i420 = got_i420 || (g_str_equal (string, "I420"));
194 got_yuy2 = got_yuy2 || (g_str_equal (string, "YUY2"));
195 got_yv12 = got_yv12 || (g_str_equal (string, "YV12"));
197 return (got_rgb8 && got_i420 && got_yuy2 && got_yv12);
200 GST_START_TEST (test_simplify)
205 caps = gst_caps_from_string (non_simple_caps_string);
206 fail_unless (caps != NULL,
207 "gst_caps_from_string (non_simple_caps_string) failed");
209 caps = gst_caps_simplify (caps);
210 fail_unless (caps != NULL, "gst_caps_simplify() should have worked");
212 /* check simplified caps, should be:
214 * video/x-raw, format=(string){ RGB8_PALETTED, YV12, YUY2, I420 },
215 * width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ],
216 * framerate=(fraction)[ 1/100, 100 ]
218 GST_DEBUG ("simplyfied %" GST_PTR_FORMAT, caps);
219 fail_unless (gst_caps_get_size (caps) == 1);
220 s1 = gst_caps_get_structure (caps, 0);
221 fail_unless (s1 != NULL);
223 fail_unless (gst_structure_has_name (s1, "video/x-raw"));
225 const GValue *framerate_value;
226 const GValue *format_value;
227 const GValue *width_value;
228 const GValue *height_value;
229 const GValue *val_fps;
230 GValue test_fps = { 0, };
231 gint min_width, max_width;
232 gint min_height, max_height;
234 format_value = gst_structure_get_value (s1, "format");
235 fail_unless (format_value != NULL);
236 fail_unless (GST_VALUE_HOLDS_LIST (format_value));
237 fail_unless (gst_value_list_get_size (format_value) == 4);
238 fail_unless (check_string_list (format_value) == TRUE);
240 g_value_init (&test_fps, GST_TYPE_FRACTION);
241 framerate_value = gst_structure_get_value (s1, "framerate");
242 fail_unless (framerate_value != NULL);
243 fail_unless (GST_VALUE_HOLDS_FRACTION_RANGE (framerate_value));
245 val_fps = gst_value_get_fraction_range_min (framerate_value);
246 gst_value_set_fraction (&test_fps, 1, 100);
247 fail_unless (gst_value_compare (&test_fps, val_fps) == GST_VALUE_EQUAL);
249 val_fps = gst_value_get_fraction_range_max (framerate_value);
250 gst_value_set_fraction (&test_fps, 100, 1);
251 fail_unless (gst_value_compare (&test_fps, val_fps) == GST_VALUE_EQUAL);
253 g_value_unset (&test_fps);
255 width_value = gst_structure_get_value (s1, "width");
256 fail_unless (width_value != NULL);
257 fail_unless (GST_VALUE_HOLDS_INT_RANGE (width_value));
258 min_width = gst_value_get_int_range_min (width_value);
259 max_width = gst_value_get_int_range_max (width_value);
260 fail_unless (min_width == 16 && max_width == 4096);
262 height_value = gst_structure_get_value (s1, "height");
263 fail_unless (height_value != NULL);
264 fail_unless (GST_VALUE_HOLDS_INT_RANGE (height_value));
265 min_height = gst_value_get_int_range_min (height_value);
266 max_height = gst_value_get_int_range_max (height_value);
267 fail_unless (min_height == 16 && max_height == 4096);
270 gst_caps_unref (caps);
275 GST_START_TEST (test_truncate)
279 caps = gst_caps_from_string (non_simple_caps_string);
280 fail_unless (caps != NULL,
281 "gst_caps_from_string (non_simple_caps_string) failed");
282 fail_unless_equals_int (gst_caps_get_size (caps), 4);
283 caps = gst_caps_truncate (caps);
284 fail_unless_equals_int (gst_caps_get_size (caps), 1);
285 gst_caps_unref (caps);
290 GST_START_TEST (test_subset)
294 c1 = gst_caps_from_string ("video/x-raw; video/x-raw");
295 c2 = gst_caps_from_string ("video/x-raw, format=(string)YUY2");
296 fail_unless (gst_caps_is_subset (c2, c1));
297 fail_if (gst_caps_is_subset (c1, c2));
301 c1 = gst_caps_from_string
302 ("audio/x-raw, channels=(int)[ 1, 2 ], rate=(int)44100");
303 c2 = gst_caps_from_string ("audio/x-raw, channels=(int)1, rate=(int)44100");
304 fail_unless (gst_caps_is_subset (c2, c1));
305 fail_if (gst_caps_is_subset (c1, c2));
309 c1 = gst_caps_from_string ("audio/x-raw, channels=(int) {1}");
310 c2 = gst_caps_from_string ("audio/x-raw, channels=(int)1");
311 fail_unless (gst_caps_is_subset (c2, c1));
312 fail_unless (gst_caps_is_subset (c1, c2));
313 fail_unless (gst_caps_is_equal (c1, c2));
317 c1 = gst_caps_from_string
318 ("audio/x-raw, rate=(int)44100, channels=(int)3, format=(string)U16_LE");
319 c2 = gst_caps_from_string
320 ("audio/x-raw, rate=(int)[ 1, 2147483647 ], channels=(int)[ 1, 2147483647 ], format=(string){ S16_LE, U16_LE }");
321 fail_unless (gst_caps_is_subset (c1, c2));
322 fail_if (gst_caps_is_subset (c2, c1));
326 c1 = gst_caps_from_string ("video/x-h264, parsed=(boolean)true");
327 c2 = gst_caps_from_string
328 ("video/x-h264, stream-format=(string)byte-stream, alignment=(string)nal");
329 fail_if (gst_caps_is_subset (c2, c1));
330 fail_if (gst_caps_is_subset (c1, c2));
331 fail_if (gst_caps_is_equal (c1, c2));
338 GST_START_TEST (test_subset_duplication)
342 c1 = gst_caps_from_string ("audio/x-raw, format=(string)F32LE");
343 c2 = gst_caps_from_string ("audio/x-raw, format=(string)F32LE");
345 fail_unless (gst_caps_is_subset (c1, c2));
346 fail_unless (gst_caps_is_subset (c2, c1));
349 c2 = gst_caps_from_string ("audio/x-raw, format=(string){ F32LE }");
351 fail_unless (gst_caps_is_subset (c1, c2));
352 fail_unless (gst_caps_is_subset (c2, c1));
355 c2 = gst_caps_from_string ("audio/x-raw, format=(string){ F32LE, F32LE }");
357 fail_unless (gst_caps_is_subset (c1, c2));
358 fail_unless (gst_caps_is_subset (c2, c1));
361 c2 = gst_caps_from_string
362 ("audio/x-raw, format=(string){ F32LE, F32LE, F32LE }");
364 fail_unless (gst_caps_is_subset (c1, c2));
365 fail_unless (gst_caps_is_subset (c2, c1));
373 GST_START_TEST (test_merge_fundamental)
377 /* ANY + specific = ANY */
378 c1 = gst_caps_from_string ("audio/x-raw,rate=44100");
379 c2 = gst_caps_new_any ();
380 c2 = gst_caps_merge (c2, c1);
381 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
382 fail_unless (gst_caps_get_size (c2) == 0, NULL);
383 fail_unless (gst_caps_is_any (c2), NULL);
386 /* specific + ANY = ANY */
387 c2 = gst_caps_from_string ("audio/x-raw,rate=44100");
388 c1 = gst_caps_new_any ();
389 c2 = gst_caps_merge (c2, c1);
390 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
391 fail_unless (gst_caps_get_size (c2) == 0, NULL);
392 fail_unless (gst_caps_is_any (c2), NULL);
395 /* EMPTY + specific = specific */
396 c1 = gst_caps_from_string ("audio/x-raw,rate=44100");
397 c2 = gst_caps_new_empty ();
398 c2 = gst_caps_merge (c2, c1);
399 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
400 fail_unless (gst_caps_get_size (c2) == 1, NULL);
401 fail_if (gst_caps_is_empty (c2), NULL);
404 /* specific + EMPTY = specific */
405 c2 = gst_caps_from_string ("audio/x-raw,rate=44100");
406 c1 = gst_caps_new_empty ();
407 c2 = gst_caps_merge (c2, c1);
408 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
409 fail_unless (gst_caps_get_size (c2) == 1, NULL);
410 fail_if (gst_caps_is_empty (c2), NULL);
416 GST_START_TEST (test_merge_same)
418 GstCaps *c1, *c2, *test;
420 /* this is the same */
421 c1 = gst_caps_from_string ("audio/x-raw,rate=44100,channels=1");
422 c2 = gst_caps_from_string ("audio/x-raw,rate=44100,channels=1");
423 c2 = gst_caps_merge (c2, c1);
424 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
425 fail_unless (gst_caps_get_size (c2) == 1, NULL);
426 test = gst_caps_from_string ("audio/x-raw,rate=44100,channels=1");
427 fail_unless (gst_caps_is_equal (c2, test));
428 gst_caps_unref (test);
432 c1 = gst_caps_from_string ("audio/x-raw,rate=44100,channels=1");
433 c2 = gst_caps_from_string ("audio/x-raw,channels=1,rate=44100");
434 c2 = gst_caps_merge (c2, c1);
435 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
436 fail_unless (gst_caps_get_size (c2) == 1, NULL);
439 c1 = gst_caps_from_string ("video/x-foo, data=(buffer)AA");
440 c2 = gst_caps_from_string ("video/x-foo, data=(buffer)AABB");
441 c2 = gst_caps_merge (c2, c1);
442 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
443 fail_unless (gst_caps_get_size (c2) == 2, NULL);
446 c1 = gst_caps_from_string ("video/x-foo, data=(buffer)AABB");
447 c2 = gst_caps_from_string ("video/x-foo, data=(buffer)AA");
448 c2 = gst_caps_merge (c2, c1);
449 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
450 fail_unless (gst_caps_get_size (c2) == 2, NULL);
453 c1 = gst_caps_from_string ("video/x-foo, data=(buffer)AA");
454 c2 = gst_caps_from_string ("video/x-foo, data=(buffer)AA");
455 c2 = 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);
460 c1 = gst_caps_from_string ("video/x-foo, data=(buffer)AA");
461 c2 = gst_caps_from_string ("video/x-bar, data=(buffer)AA");
462 c2 = gst_caps_merge (c2, c1);
463 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
464 fail_unless (gst_caps_get_size (c2) == 2, NULL);
470 GST_START_TEST (test_merge_subset)
472 GstCaps *c1, *c2, *test;
474 /* the 2nd is already covered */
475 c2 = gst_caps_from_string ("audio/x-raw,channels=[1,2]");
476 c1 = gst_caps_from_string ("audio/x-raw,channels=1");
477 c2 = 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,channels=[1,2]");
481 fail_unless (gst_caps_is_equal (c2, test));
483 gst_caps_unref (test);
486 c2 = gst_caps_from_string ("audio/x-raw,channels=1,rate=44100");
487 c1 = gst_caps_from_string ("audio/x-raw,channels=[1,2],rate=44100");
488 c2 = 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) == 2, NULL);
491 test = gst_caps_from_string ("audio/x-raw,channels=[1,2],rate=44100");
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,channels=[1,3]");
498 c1 = gst_caps_from_string ("audio/x-raw,channels=[1,2]");
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,channels=[1,3]");
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,channels=[1,4]");
509 c1 = gst_caps_from_string ("audio/x-raw,channels=[1,2]");
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);
513 test = gst_caps_from_string ("audio/x-raw,channels=[1,4]");
514 fail_unless (gst_caps_is_equal (c2, test));
516 gst_caps_unref (test);
518 /* second one was already contained in the first one */
519 c2 = gst_caps_from_string ("audio/x-raw,channels=[1,4]");
520 c1 = gst_caps_from_string ("audio/x-raw,channels=[2,4]");
521 c2 = 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) == 1, NULL);
524 test = gst_caps_from_string ("audio/x-raw,channels=[1,4]");
525 fail_unless (gst_caps_is_equal (c2, test));
527 gst_caps_unref (test);
529 /* second one was already contained in the first one */
530 c2 = gst_caps_from_string ("audio/x-raw,channels=[1,4]");
531 c1 = gst_caps_from_string ("audio/x-raw,channels=[2,3]");
532 c2 = gst_caps_merge (c2, c1);
533 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
534 fail_unless (gst_caps_get_size (c2) == 1, NULL);
535 test = gst_caps_from_string ("audio/x-raw,channels=[1,4]");
536 fail_unless (gst_caps_is_equal (c2, test));
538 gst_caps_unref (test);
540 /* these caps cannot be merged */
541 c2 = gst_caps_from_string ("audio/x-raw,channels=[2,3]");
542 c1 = gst_caps_from_string ("audio/x-raw,channels=[1,4]");
543 c2 = gst_caps_merge (c2, c1);
544 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
545 fail_unless (gst_caps_get_size (c2) == 2, NULL);
548 ("audio/x-raw,channels=[2,3];audio/x-raw,channels=[1,4]");
549 fail_unless (gst_caps_is_equal (c2, test));
551 gst_caps_unref (test);
553 /* these caps cannot be merged */
554 c2 = gst_caps_from_string ("audio/x-raw,channels=[1,2]");
555 c1 = gst_caps_from_string ("audio/x-raw,channels=[1,3]");
556 c2 = gst_caps_merge (c2, c1);
557 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
558 fail_unless (gst_caps_get_size (c2) == 2, NULL);
561 ("audio/x-raw,channels=[1,2];audio/x-raw,channels=[1,3]");
562 fail_unless (gst_caps_is_equal (c2, test));
564 gst_caps_unref (test);
566 c2 = gst_caps_from_string ("audio/x-raw,channels={1,2}");
567 c1 = gst_caps_from_string ("audio/x-raw,channels={1,2,3,4}");
568 c2 = gst_caps_merge (c2, c1);
569 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
570 fail_unless (gst_caps_get_size (c2) == 2, NULL);
571 test = gst_caps_from_string ("audio/x-raw,channels={1,2};"
572 "audio/x-raw,channels={1,2,3,4}");
573 fail_unless (gst_caps_is_equal (c2, test));
575 gst_caps_unref (test);
577 c2 = gst_caps_from_string ("audio/x-raw,channels={1,2}");
578 c1 = gst_caps_from_string ("audio/x-raw,channels={1,3}");
579 c2 = gst_caps_merge (c2, c1);
580 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
581 fail_unless (gst_caps_get_size (c2) == 2, NULL);
582 test = gst_caps_from_string ("audio/x-raw,channels={1,2};"
583 "audio/x-raw,channels={1,3}");
584 fail_unless (gst_caps_is_equal (c2, test));
586 gst_caps_unref (test);
588 c2 = gst_caps_from_string ("video/x-raw, framerate=(fraction){ 15/2, 5/1 }");
589 c1 = gst_caps_from_string ("video/x-raw, framerate=(fraction){ 15/1, 5/1 }");
590 test = gst_caps_copy (c1);
591 c2 = gst_caps_merge (c2, c1);
592 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
593 fail_unless (gst_caps_is_subset (test, c2));
594 gst_caps_unref (test);
597 c2 = gst_caps_from_string ("audio/x-raw");
598 c1 = gst_caps_from_string ("audio/x-raw,channels=1");
599 c2 = gst_caps_merge (c2, c1);
600 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
601 fail_unless (gst_caps_get_size (c2) == 1, NULL);
602 test = gst_caps_from_string ("audio/x-raw");
603 fail_unless (gst_caps_is_equal (c2, test));
605 gst_caps_unref (test);
607 c2 = gst_caps_from_string ("audio/x-raw,channels=1");
608 c1 = gst_caps_from_string ("audio/x-raw");
609 c2 = gst_caps_merge (c2, c1);
610 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
611 fail_unless (gst_caps_get_size (c2) == 2, NULL);
612 test = gst_caps_from_string ("audio/x-raw,channels=1; audio/x-raw");
613 fail_unless (gst_caps_is_equal (c2, test));
615 gst_caps_unref (test);
620 GST_START_TEST (test_intersect)
623 GstCaps *c1, *c2, *ci1, *ci2;
625 /* field not specified = any value possible, so the intersection
626 * should keep fields which are only part of one set of caps */
627 c2 = gst_caps_from_string ("video/x-raw,format=(string)I420,width=20");
628 c1 = gst_caps_from_string ("video/x-raw,format=(string)I420");
630 ci1 = gst_caps_intersect (c2, c1);
631 GST_DEBUG ("intersected: %" GST_PTR_FORMAT, ci1);
632 fail_unless (gst_caps_get_size (ci1) == 1, NULL);
633 s = gst_caps_get_structure (ci1, 0);
634 fail_unless (gst_structure_has_name (s, "video/x-raw"));
635 fail_unless (gst_structure_get_value (s, "format") != NULL);
636 fail_unless (gst_structure_get_value (s, "width") != NULL);
638 /* with changed order */
639 ci2 = gst_caps_intersect (c1, c2);
640 GST_DEBUG ("intersected: %" GST_PTR_FORMAT, ci2);
641 fail_unless (gst_caps_get_size (ci2) == 1, NULL);
642 s = gst_caps_get_structure (ci2, 0);
643 fail_unless (gst_structure_has_name (s, "video/x-raw"));
644 fail_unless (gst_structure_get_value (s, "format") != NULL);
645 fail_unless (gst_structure_get_value (s, "width") != NULL);
647 fail_unless (gst_caps_is_equal (ci1, ci2));
649 gst_caps_unref (ci1);
650 gst_caps_unref (ci2);
657 c2 = gst_caps_from_string ("video/x-raw,format=(string)I420,width=20");
658 c1 = gst_caps_from_string ("video/x-raw,format=(string)I420,width=30");
660 ci1 = gst_caps_intersect (c2, c1);
661 GST_DEBUG ("intersected: %" GST_PTR_FORMAT, ci1);
662 fail_unless (gst_caps_is_empty (ci1), NULL);
664 /* with changed order */
665 ci2 = gst_caps_intersect (c1, c2);
666 GST_DEBUG ("intersected: %" GST_PTR_FORMAT, ci2);
667 fail_unless (gst_caps_is_empty (ci2), NULL);
669 fail_unless (gst_caps_is_equal (ci1, ci2));
671 gst_caps_unref (ci1);
672 gst_caps_unref (ci2);
679 c2 = gst_caps_from_string ("video/x-raw,format=(string)I420,width=20");
680 c1 = gst_caps_from_string ("video/x-raw2,format=(string)I420,width=20");
682 ci1 = gst_caps_intersect (c2, c1);
683 GST_DEBUG ("intersected: %" GST_PTR_FORMAT, ci1);
684 fail_unless (gst_caps_is_empty (ci1), NULL);
686 /* with changed order */
687 ci2 = gst_caps_intersect (c1, c2);
688 GST_DEBUG ("intersected: %" GST_PTR_FORMAT, ci2);
689 fail_unless (gst_caps_is_empty (ci2), NULL);
691 fail_unless (gst_caps_is_equal (ci1, ci2));
693 gst_caps_unref (ci1);
694 gst_caps_unref (ci2);
701 c2 = gst_caps_from_string ("video/x-raw,format=(string)I420,width=20");
702 c1 = gst_caps_from_string ("video/x-raw,format=(string)I420,height=30");
704 ci1 = gst_caps_intersect (c2, c1);
705 GST_DEBUG ("intersected: %" GST_PTR_FORMAT, ci1);
706 fail_unless (gst_caps_get_size (ci1) == 1, NULL);
707 s = gst_caps_get_structure (ci1, 0);
708 fail_unless (gst_structure_has_name (s, "video/x-raw"));
709 fail_unless (gst_structure_get_value (s, "format") != NULL);
710 fail_unless (gst_structure_get_value (s, "width") != NULL);
711 fail_unless (gst_structure_get_value (s, "height") != NULL);
713 /* with changed order */
714 ci2 = gst_caps_intersect (c1, c2);
715 GST_DEBUG ("intersected: %" GST_PTR_FORMAT, ci2);
716 fail_unless (gst_caps_get_size (ci2) == 1, NULL);
717 s = gst_caps_get_structure (ci2, 0);
718 fail_unless (gst_structure_has_name (s, "video/x-raw"));
719 fail_unless (gst_structure_get_value (s, "format") != NULL);
720 fail_unless (gst_structure_get_value (s, "height") != 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);
734 GST_START_TEST (test_intersect2)
736 GstCaps *caps1, *caps2, *icaps;
738 /* tests array subtraction */
739 caps1 = gst_caps_from_string ("audio/x-raw, "
740 "channel-positions=(int)< "
741 "{ 1, 2, 3, 4, 5, 6 }, "
742 "{ 1, 2, 3, 4, 5, 6 }, "
743 "{ 1, 2, 3, 4, 5, 6 }, "
744 "{ 1, 2, 3, 4, 5, 6 }, "
745 "{ 1, 2, 3, 4, 5, 6 }, " "{ 1, 2, 3, 4, 5, 6 }>");
746 caps2 = gst_caps_from_string ("audio/x-raw, "
747 "channel-positions=(int)< 1, 2, 3, 4, 5, 6 >");
748 icaps = gst_caps_intersect (caps1, caps2);
749 GST_LOG ("intersected caps: %" GST_PTR_FORMAT, icaps);
750 fail_if (gst_caps_is_empty (icaps));
751 fail_unless (gst_caps_is_equal (icaps, caps2));
752 gst_caps_unref (caps1);
753 gst_caps_unref (caps2);
754 gst_caps_unref (icaps);
758 caps1 = gst_caps_from_string ("some/type, foo=(int)< { 1, 2 }, { 3, 4} >");
759 caps2 = gst_caps_from_string ("some/type, foo=(int)< 1, 3 >");
760 icaps = gst_caps_intersect (caps1, caps2);
761 GST_LOG ("intersected caps: %" GST_PTR_FORMAT, icaps);
762 fail_if (gst_caps_is_empty (icaps));
763 fail_unless (gst_caps_is_equal (icaps, caps2));
764 gst_caps_unref (caps1);
765 gst_caps_unref (caps2);
766 gst_caps_unref (icaps);
771 GST_START_TEST (test_intersect_list_duplicate)
773 GstCaps *caps1, *caps2, *icaps;
775 /* make sure we don't take too long to intersect these.. */
776 caps1 = gst_caps_from_string ("video/x-raw, format=(string)YV12; "
777 "video/x-raw, format=(string)I420; video/x-raw, format=(string)YUY2; "
778 "video/x-raw, format=(string)UYVY; "
779 "video/x-raw, format=(string){ I420, YV12, YUY2, UYVY, AYUV, RGBx, BGRx,"
780 " xRGB, xBGR, { RGBA, RGBA, { RGBA, RGBA }, "
781 "{ RGBA, RGBA, { RGBA, RGBA } }, { RGBA, RGBA, { RGBA, RGBA }, "
782 "{ RGBA, RGBA, { RGBA, RGBA } } }, { RGBA, RGBA, { RGBA, RGBA }, "
783 "{ RGBA, RGBA, { RGBA, RGBA } }, { RGBA, RGBA, { RGBA, RGBA }, "
784 "{ RGBA, RGBA, { RGBA, RGBA } } } }, { RGBA, RGBA, { RGBA, RGBA }, "
785 "{ RGBA, RGBA, { RGBA, RGBA } }, { RGBA, RGBA, { RGBA, RGBA }, "
786 "{ RGBA, RGBA, { RGBA, RGBA } } }, { RGBA, RGBA, { RGBA, RGBA }, "
787 "{ RGBA, RGBA, { RGBA, RGBA } }, { RGBA, RGBA, { RGBA, RGBA }, "
788 "{ RGBA, RGBA, { RGBA, RGBA } } } } } }, BGRA, ARGB, { ABGR, ABGR, "
789 "{ ABGR, ABGR }, { ABGR, ABGR, { ABGR, ABGR } }, "
790 "{ ABGR, ABGR, { ABGR, ABGR }, { ABGR, ABGR, { ABGR, ABGR } } }, "
791 "{ ABGR, ABGR, { ABGR, ABGR }, { ABGR, ABGR, { ABGR, ABGR } }, "
792 "{ ABGR, ABGR, { ABGR, ABGR }, { ABGR, ABGR, { ABGR, ABGR } } } }, "
793 "{ ABGR, ABGR, { ABGR, ABGR }, { ABGR, ABGR, { ABGR, ABGR } }, "
794 "{ ABGR, ABGR, { ABGR, ABGR }, { ABGR, ABGR, { ABGR, ABGR } } }, "
795 "{ ABGR, ABGR, { ABGR, ABGR }, { ABGR, ABGR, { ABGR, ABGR } }, "
796 "{ ABGR, ABGR, { ABGR, ABGR }, { ABGR, ABGR, { ABGR, ABGR } } } } } }, "
797 "RGB, BGR, Y41B, Y42B, YVYU, Y444 }; "
798 "video/x-raw, format=(string){ I420, YV12, YUY2, UYVY, AYUV, RGBx, BGRx, "
799 "xRGB, xBGR, { RGBA, RGBA, { RGBA, RGBA }, "
800 "{ RGBA, RGBA, { RGBA, RGBA } }, { RGBA, RGBA, { RGBA, RGBA }, "
801 "{ RGBA, RGBA, { RGBA, RGBA } } }, { RGBA, RGBA, { RGBA, RGBA }, "
802 "{ RGBA, RGBA, { RGBA, RGBA } }, { RGBA, RGBA, { RGBA, RGBA }, "
803 "{ RGBA, RGBA, { RGBA, RGBA } } } }, { RGBA, RGBA, { RGBA, RGBA }, "
804 "{ RGBA, RGBA, { RGBA, RGBA } }, { RGBA, RGBA, { RGBA, RGBA }, "
805 "{ RGBA, RGBA, { RGBA, RGBA } } }, { RGBA, RGBA, { RGBA, RGBA }, "
806 "{ RGBA, RGBA, { RGBA, RGBA } }, { RGBA, RGBA, { RGBA, RGBA }, "
807 "{ RGBA, RGBA, { RGBA, RGBA } } } } } }, BGRA, ARGB, "
808 "{ ABGR, ABGR, { ABGR, ABGR }, { ABGR, ABGR, { ABGR, ABGR } }, "
809 "{ ABGR, ABGR, { ABGR, ABGR }, { ABGR, ABGR, { ABGR, ABGR } } }, "
810 "{ ABGR, ABGR, { ABGR, ABGR }, { ABGR, ABGR, { ABGR, ABGR } }, "
811 "{ ABGR, ABGR, { ABGR, ABGR }, { ABGR, ABGR, { ABGR, ABGR } } } }, "
812 "{ ABGR, ABGR, { ABGR, ABGR }, { ABGR, ABGR, { ABGR, ABGR } }, "
813 "{ ABGR, ABGR, { ABGR, ABGR }, { ABGR, ABGR, { ABGR, ABGR } } }, "
814 "{ ABGR, ABGR, { ABGR, ABGR }, { ABGR, ABGR, { ABGR, ABGR } }, "
815 "{ ABGR, ABGR, { ABGR, ABGR }, { ABGR, ABGR, { ABGR, ABGR } } } } } }, "
816 "RGB, BGR, Y41B, Y42B, YVYU, Y444, NV12, NV21 }; "
817 "video/x-raw, format=(string){ I420, YV12, YUY2, UYVY, AYUV, RGBx, "
818 "BGRx, xRGB, xBGR, { RGBA, RGBA, { RGBA, RGBA }, "
819 "{ RGBA, RGBA, { RGBA, RGBA } }, { RGBA, RGBA, { RGBA, RGBA }, "
820 "{ RGBA, RGBA, { RGBA, RGBA } } } }, BGRA, ARGB, "
821 "{ ABGR, ABGR, { ABGR, ABGR }, { ABGR, ABGR, { ABGR, ABGR } }, "
822 "{ ABGR, ABGR, { ABGR, ABGR }, { ABGR, ABGR, { ABGR, ABGR } } } }, "
823 "RGB, BGR, Y41B, Y42B, YVYU, Y444, NV12, NV21 }");
825 caps2 = gst_caps_copy (caps1);
827 icaps = gst_caps_intersect (caps1, caps2);
829 gst_caps_unref (caps1);
830 gst_caps_unref (caps2);
831 gst_caps_unref (icaps);
836 GST_START_TEST (test_intersect_zigzag)
838 GstCaps *caps1, *caps2, *icaps, *result;
840 /* tests if caps order is maintained */
841 caps1 = gst_caps_from_string ("format/A; format/B; format/C; format/D");
842 caps2 = gst_caps_from_string ("format/D; format/A; format/B; format/C");
844 icaps = gst_caps_intersect_full (caps1, caps2, GST_CAPS_INTERSECT_ZIG_ZAG);
845 result = gst_caps_from_string ("format/B; format/A; format/D; format/C");
846 GST_LOG ("intersected caps: %" GST_PTR_FORMAT, icaps);
847 fail_if (gst_caps_is_empty (icaps));
848 fail_unless (gst_caps_is_equal (icaps, result));
849 gst_caps_unref (icaps);
850 gst_caps_unref (result);
852 icaps = gst_caps_intersect_full (caps2, caps1, GST_CAPS_INTERSECT_FIRST);
853 result = gst_caps_from_string ("format/A; format/B; format/D; format/C");
854 GST_LOG ("intersected caps: %" GST_PTR_FORMAT, icaps);
855 fail_if (gst_caps_is_empty (icaps));
856 fail_unless (gst_caps_is_equal (icaps, result));
857 gst_caps_unref (icaps);
858 gst_caps_unref (result);
860 gst_caps_unref (caps1);
861 gst_caps_unref (caps2);
867 GST_START_TEST (test_intersect_first)
869 GstCaps *caps1, *caps2, *icaps, *result;
871 /* tests if caps order is maintained */
872 caps1 = gst_caps_from_string ("format/A; format/B; format/C; format/D");
873 caps2 = gst_caps_from_string ("format/C; format/D; format/A");
874 icaps = gst_caps_intersect_full (caps1, caps2, GST_CAPS_INTERSECT_FIRST);
875 result = gst_caps_from_string ("format/A; format/C; format/D");
876 GST_LOG ("intersected caps: %" GST_PTR_FORMAT, icaps);
877 fail_if (gst_caps_is_empty (icaps));
878 fail_unless (gst_caps_is_equal (icaps, result));
879 gst_caps_unref (caps1);
880 gst_caps_unref (caps2);
881 gst_caps_unref (icaps);
882 gst_caps_unref (result);
888 GST_START_TEST (test_intersect_first2)
890 GstCaps *caps1, *caps2, *icaps, *result;
892 /* tests if caps order is maintained */
893 caps1 = gst_caps_from_string ("format/A; format/B; format/C; format/D");
894 caps2 = gst_caps_from_string ("format/D; format/A; format/B; format/C");
896 icaps = gst_caps_intersect_full (caps1, caps2, GST_CAPS_INTERSECT_FIRST);
897 result = gst_caps_from_string ("format/A; format/B; format/C; format/D");
898 GST_LOG ("intersected caps: %" GST_PTR_FORMAT, icaps);
899 fail_if (gst_caps_is_empty (icaps));
900 fail_unless (gst_caps_is_equal (icaps, result));
901 gst_caps_unref (icaps);
902 gst_caps_unref (result);
904 icaps = gst_caps_intersect_full (caps2, caps1, GST_CAPS_INTERSECT_FIRST);
905 result = gst_caps_from_string ("format/D; format/A; format/B; format/C");
906 GST_LOG ("intersected caps: %" GST_PTR_FORMAT, icaps);
907 fail_if (gst_caps_is_empty (icaps));
908 fail_unless (gst_caps_is_equal (icaps, result));
909 gst_caps_unref (icaps);
910 gst_caps_unref (result);
912 gst_caps_unref (caps1);
913 gst_caps_unref (caps2);
918 GST_START_TEST (test_intersect_duplication)
920 GstCaps *c1, *c2, *test;
922 c1 = gst_caps_from_string
923 ("audio/x-raw, format=(string)S16_LE, rate=(int)[ 1, 2147483647 ], channels=(int)[ 1, 2 ]");
924 c2 = gst_caps_from_string
925 ("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 ]");
927 test = gst_caps_intersect_full (c1, c2, GST_CAPS_INTERSECT_FIRST);
928 fail_unless_equals_int (gst_caps_get_size (test), 1);
929 fail_unless (gst_caps_is_equal (c1, test));
932 gst_caps_unref (test);
937 GST_START_TEST (test_intersect_flagset)
939 GstCaps *c1, *c2, *test;
940 GType test_flagset_type;
941 GstSeekFlags test_flags, test_mask;
944 /* Test that matching bits inside the mask intersect,
945 * and bits outside the mask don't matter */
946 c1 = gst_caps_from_string ("test/x-caps,field=ffd81d:fffff0");
947 c2 = gst_caps_from_string ("test/x-caps,field=0fd81f:0ffff0");
949 test = gst_caps_intersect_full (c1, c2, GST_CAPS_INTERSECT_FIRST);
950 fail_unless_equals_int (gst_caps_get_size (test), 1);
951 fail_unless (gst_caps_is_equal (c1, test));
954 gst_caps_unref (test);
956 /* Test that non-matching bits in the mask don't intersect */
957 c1 = gst_caps_from_string ("test/x-caps,field=ff001d:0ffff0");
958 c2 = gst_caps_from_string ("test/x-caps,field=0fd81f:0ffff0");
960 test = gst_caps_intersect_full (c1, c2, GST_CAPS_INTERSECT_FIRST);
961 fail_unless (gst_caps_is_empty (test));
964 gst_caps_unref (test);
966 /* Check custom flags type serialisation and de-serialisation */
967 test_flagset_type = gst_flagset_register (GST_TYPE_SEEK_FLAGS);
968 fail_unless (g_type_is_a (test_flagset_type, GST_TYPE_FLAG_SET));
971 GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_TRICKMODE |
972 GST_SEEK_FLAG_TRICKMODE_KEY_UNITS;
974 GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_TRICKMODE |
975 GST_SEEK_FLAG_TRICKMODE_NO_AUDIO;
977 c1 = gst_caps_new_simple ("test/x-caps", "field", test_flagset_type,
978 (guint64) (test_flags), (guint64) (test_mask), NULL);
980 test_string = gst_caps_to_string (c1);
981 fail_if (test_string == NULL);
983 GST_DEBUG ("Serialised caps to %s", test_string);
984 c2 = gst_caps_from_string (test_string);
985 g_free (test_string);
987 fail_unless (gst_caps_is_equal (c1, c2));
995 GST_START_TEST (test_union)
997 GstCaps *c1, *c2, *test, *expect;
999 /* Test that matching bits inside the masks union OK, */
1000 c1 = gst_caps_from_string ("test/x-caps,field=ffd81d:0ffff0");
1001 c2 = gst_caps_from_string ("test/x-caps,field=0fd81f:0ffff0");
1003 test = gst_caps_merge (c1, c2);
1004 test = gst_caps_simplify (test);
1005 /* c1, c2 now invalid */
1006 fail_unless_equals_int (gst_caps_get_size (test), 1);
1007 gst_caps_unref (test);
1009 /* Test that non-intersecting sets of masked bits are OK */
1010 c1 = gst_caps_from_string ("test/x-caps,field=ff001d:0ffff0");
1011 c2 = gst_caps_from_string ("test/x-caps,field=4fd81f:f00000");
1012 expect = gst_caps_from_string ("test/x-caps,field=4f001d:fffff0");
1013 test = gst_caps_simplify (gst_caps_merge (c1, c2));
1014 /* c1, c2 now invalid */
1015 GST_LOG ("Expected caps %" GST_PTR_FORMAT " got %" GST_PTR_FORMAT "\n",
1017 fail_unless (gst_caps_is_equal (test, expect));
1018 gst_caps_unref (test);
1019 gst_caps_unref (expect);
1021 /* Test that partially-intersecting sets of masked bits that match are OK */
1022 c1 = gst_caps_from_string ("test/x-caps,field=ff001d:0ffff0");
1023 c2 = gst_caps_from_string ("test/x-caps,field=4fd81f:ff0000");
1024 expect = gst_caps_from_string ("test/x-caps,field=4f001d:fffff0");
1025 test = gst_caps_simplify (gst_caps_merge (c1, c2));
1026 /* c1, c2 now invalid */
1027 GST_LOG ("Expected caps %" GST_PTR_FORMAT " got %" GST_PTR_FORMAT "\n",
1029 fail_unless (gst_caps_is_equal (test, expect));
1030 gst_caps_unref (test);
1031 gst_caps_unref (expect);
1037 _caps_is_fixed_foreach (GQuark field_id, const GValue * value, gpointer unused)
1039 return gst_value_is_fixed (value);
1043 GST_START_TEST (test_normalize)
1045 GstCaps *in, *norm, *out;
1048 in = gst_caps_from_string ("some/type, foo=(int){ 1 , 2 }");
1049 out = gst_caps_from_string ("some/type, foo=(int) 1; some/type, foo=(int) 2");
1050 norm = gst_caps_normalize (in);
1051 fail_if (gst_caps_is_empty (norm));
1052 fail_unless (gst_caps_is_equal (norm, out));
1053 for (i = 0; i < gst_caps_get_size (norm); i++) {
1054 GstStructure *st = gst_caps_get_structure (norm, i);
1055 /* Make sure all fields of all structures are fixed */
1056 fail_unless (gst_structure_foreach (st, _caps_is_fixed_foreach, NULL));
1059 gst_caps_unref (out);
1060 gst_caps_unref (norm);
1062 in = gst_caps_from_string
1063 ("some/type, foo=(int){ 1 , 2 }, bar=(int){ 3, 4 }");
1065 gst_caps_from_string
1066 ("some/type, foo=(int) 1, bar=(int) 3; some/type, foo=(int) 2, bar=(int) 3;"
1067 "some/type, foo=(int) 1, bar=(int) 4; some/type, foo=(int) 2, bar=(int) 4;");
1068 norm = gst_caps_normalize (in);
1069 fail_if (gst_caps_is_empty (norm));
1070 fail_unless (gst_caps_is_equal (norm, out));
1071 for (i = 0; i < gst_caps_get_size (norm); i++) {
1072 GstStructure *st = gst_caps_get_structure (norm, i);
1073 /* Make sure all fields of all structures are fixed */
1074 fail_unless (gst_structure_foreach (st, _caps_is_fixed_foreach, NULL));
1077 gst_caps_unref (out);
1078 gst_caps_unref (norm);
1080 in = gst_caps_from_string
1081 ("some/type, foo=(string){ 1 , 2 }, bar=(string) { 3 }");
1083 gst_caps_from_string
1084 ("some/type, foo=(string) 1, bar=(string) 3; some/type, foo=(string) 2, bar=(string) 3");
1085 norm = gst_caps_normalize (in);
1086 fail_if (gst_caps_is_empty (norm));
1087 fail_unless (gst_caps_is_equal (norm, out));
1088 for (i = 0; i < gst_caps_get_size (norm); i++) {
1089 GstStructure *st = gst_caps_get_structure (norm, i);
1090 /* Make sure all fields of all structures are fixed */
1091 fail_unless (gst_structure_foreach (st, _caps_is_fixed_foreach, NULL));
1094 gst_caps_unref (out);
1095 gst_caps_unref (norm);
1100 GST_START_TEST (test_broken)
1104 /* NULL is not valid for media_type */
1105 ASSERT_CRITICAL (c1 =
1106 gst_caps_new_simple (NULL, "field", G_TYPE_INT, 1, NULL));
1109 #ifndef G_DISABLE_CHECKS
1110 /* such a name is not valid, see gst_structure_validate_name() */
1111 ASSERT_CRITICAL (c1 =
1112 gst_caps_new_simple ("1#@abc", "field", G_TYPE_INT, 1, NULL));
1119 GST_START_TEST (test_features)
1121 GstCaps *c1, *c2, *c3;
1122 GstStructure *s1, *s2;
1123 GstCapsFeatures *f1, *f2;
1125 static GstStaticCaps scaps =
1127 ("video/x-raw(memory:EGLImage), width=320, height=[ 240, 260 ]");
1129 c1 = gst_caps_new_empty ();
1130 fail_unless (c1 != NULL);
1131 s1 = gst_structure_new ("video/x-raw", "width", G_TYPE_INT, 320, "height",
1132 GST_TYPE_INT_RANGE, 240, 260, NULL);
1133 fail_unless (s1 != NULL);
1134 f1 = gst_caps_features_new ("memory:EGLImage", NULL);
1135 fail_unless (f1 != NULL);
1137 gst_caps_append_structure_full (c1, s1, f1);
1138 s2 = gst_caps_get_structure (c1, 0);
1139 fail_unless (s1 == s2);
1140 f2 = gst_caps_get_features (c1, 0);
1141 fail_unless (f1 == f2);
1143 str1 = gst_caps_to_string (c1);
1144 fail_unless (str1 != NULL);
1145 c2 = gst_caps_from_string (str1);
1146 fail_unless (c2 != NULL);
1149 fail_unless (gst_caps_is_equal (c1, c2));
1150 fail_unless (gst_caps_is_subset (c1, c2));
1151 fail_unless (gst_caps_is_subset (c2, c1));
1152 fail_unless (gst_caps_can_intersect (c1, c2));
1154 gst_caps_unref (c2);
1156 c2 = gst_caps_new_empty ();
1157 fail_unless (c2 != NULL);
1158 s2 = gst_structure_new ("video/x-raw", "width", G_TYPE_INT, 320, "height",
1159 GST_TYPE_INT_RANGE, 240, 260, NULL);
1160 fail_unless (s2 != NULL);
1161 f2 = gst_caps_features_new ("memory:VASurface", "meta:VAMeta", NULL);
1162 fail_unless (f2 != NULL);
1163 gst_caps_append_structure_full (c2, s2, f2);
1165 fail_if (gst_caps_is_equal (c1, c2));
1166 fail_if (gst_caps_is_subset (c1, c2));
1167 fail_if (gst_caps_is_subset (c2, c1));
1168 fail_if (gst_caps_can_intersect (c1, c2));
1170 str1 = gst_caps_to_string (c2);
1171 fail_unless (str1 != NULL);
1172 c3 = gst_caps_from_string (str1);
1173 fail_unless (c3 != NULL);
1176 fail_unless (gst_caps_is_equal (c2, c3));
1177 fail_unless (gst_caps_is_subset (c2, c3));
1178 fail_unless (gst_caps_is_subset (c3, c2));
1179 fail_unless (gst_caps_can_intersect (c2, c3));
1181 f1 = gst_caps_get_features (c3, 0);
1182 fail_unless (f1 != NULL);
1184 gst_caps_features_contains (f1, "memory:VASurface");
1185 gst_caps_features_remove (f1, "memory:VASurface");
1186 fail_if (gst_caps_is_equal (c2, c3));
1187 fail_if (gst_caps_is_subset (c2, c3));
1188 fail_if (gst_caps_is_subset (c3, c2));
1189 fail_if (gst_caps_can_intersect (c2, c3));
1191 gst_caps_unref (c3);
1192 gst_caps_unref (c2);
1194 c2 = gst_static_caps_get (&scaps);
1195 fail_unless (c2 != NULL);
1196 fail_unless (gst_caps_is_equal (c1, c2));
1197 fail_unless (gst_caps_is_subset (c1, c2));
1198 fail_unless (gst_caps_is_subset (c2, c1));
1199 fail_unless (gst_caps_can_intersect (c1, c2));
1200 gst_caps_unref (c2);
1202 c2 = gst_caps_from_string
1203 ("video/x-raw(ANY), width=320, height=[ 240, 260 ]");
1204 fail_unless (c2 != NULL);
1205 fail_if (gst_caps_is_equal (c1, c2));
1206 fail_unless (gst_caps_is_subset (c1, c2));
1207 fail_if (gst_caps_is_subset (c2, c1));
1208 fail_unless (gst_caps_can_intersect (c1, c2));
1210 c3 = gst_caps_intersect (c1, c2);
1211 fail_unless (gst_caps_is_equal (c3, c1));
1213 gst_caps_unref (c3);
1214 gst_caps_unref (c2);
1215 gst_caps_unref (c1);
1217 c1 = gst_caps_from_string ("video/x-raw");
1218 c2 = gst_caps_from_string ("video/x-raw");
1220 f1 = gst_caps_get_features (c1, 0);
1221 gst_caps_features_add (f1, "memory:VASurface");
1223 fail_unless (gst_caps_features_is_equal (f1, gst_caps_get_features (c1, 0)));
1224 fail_if (gst_caps_can_intersect (c1, c2));
1226 f2 = gst_caps_get_features (c2, 0);
1227 fail_unless (gst_caps_features_is_equal
1228 (GST_CAPS_FEATURES_MEMORY_SYSTEM_MEMORY, f2));
1230 gst_caps_unref (c2);
1231 gst_caps_unref (c1);
1233 c1 = gst_caps_from_string ("video/x-raw");
1234 f1 = gst_caps_get_features (c1, 0);
1235 f2 = gst_caps_features_new ("memory:dmabuf", NULL);
1236 gst_caps_set_features (c1, 0, f2);
1238 gst_caps_unref (c1);
1243 GST_START_TEST (test_special_caps)
1247 caps = gst_caps_new_any ();
1248 fail_unless (gst_caps_is_any (caps));
1249 fail_unless (gst_caps_is_any (caps) == TRUE);
1250 fail_if (gst_caps_is_empty (caps));
1251 fail_unless (gst_caps_is_empty (caps) == FALSE);
1252 gst_caps_unref (caps);
1254 caps = gst_caps_new_empty ();
1255 fail_if (gst_caps_is_any (caps));
1256 fail_unless (gst_caps_is_any (caps) == FALSE);
1257 fail_unless (gst_caps_is_empty (caps));
1258 fail_unless (gst_caps_is_empty (caps) == TRUE);
1259 gst_caps_unref (caps);
1265 foreach_append_function (GstCapsFeatures * features, GstStructure * structure,
1268 GstCaps *caps = user_data;
1270 gst_caps_append_structure_full (caps, gst_structure_copy (structure),
1271 features ? gst_caps_features_copy (features) : NULL);
1276 GST_START_TEST (test_foreach)
1278 GstCaps *caps, *caps2;
1281 gst_caps_from_string
1282 ("video/x-raw, format=I420; video/x-raw(foo:bar); video/x-h264");
1283 caps2 = gst_caps_new_empty ();
1284 fail_unless (gst_caps_foreach (caps, foreach_append_function, caps2));
1285 fail_unless (gst_caps_is_strictly_equal (caps, caps2));
1286 gst_caps_unref (caps);
1287 gst_caps_unref (caps2);
1289 caps = gst_caps_new_empty ();
1290 caps2 = gst_caps_new_empty ();
1291 fail_unless (gst_caps_foreach (caps, foreach_append_function, caps2));
1292 fail_unless (gst_caps_is_strictly_equal (caps, caps2));
1293 gst_caps_unref (caps);
1294 gst_caps_unref (caps2);
1300 map_function (GstCapsFeatures * features, GstStructure * structure,
1303 /* Remove caps features if there are any, otherwise add some dummy */
1304 if (gst_caps_features_contains (features, "foo:bar")) {
1305 gst_caps_features_remove (features, "foo:bar");
1307 gst_caps_features_add (features, "foo:bar");
1308 gst_caps_features_remove (features, GST_CAPS_FEATURE_MEMORY_SYSTEM_MEMORY);
1311 /* Set some dummy integer in the structure */
1312 gst_structure_set (structure, "foo", G_TYPE_INT, 123, NULL);
1317 GST_START_TEST (test_map_in_place)
1319 GstCaps *caps, *caps2;
1322 gst_caps_from_string
1323 ("video/x-raw, format=I420; video/x-raw(foo:bar); video/x-h264");
1325 gst_caps_from_string
1326 ("video/x-raw(foo:bar), foo=(int)123, format=I420; video/x-raw, foo=(int)123; video/x-h264(foo:bar), foo=(int)123");
1327 fail_unless (gst_caps_map_in_place (caps, map_function, NULL));
1328 fail_unless (gst_caps_is_strictly_equal (caps, caps2));
1329 gst_caps_unref (caps);
1330 gst_caps_unref (caps2);
1332 caps = gst_caps_new_empty ();
1333 caps2 = gst_caps_new_empty ();
1334 fail_unless (gst_caps_map_in_place (caps, map_function, NULL));
1335 fail_unless (gst_caps_is_strictly_equal (caps, caps2));
1336 gst_caps_unref (caps);
1337 gst_caps_unref (caps2);
1343 filter_map_function (GstCapsFeatures * features, GstStructure * structure,
1346 if (!gst_structure_has_name (structure, "video/x-raw"))
1349 if (!gst_caps_features_contains (features, "foo:bar"))
1352 /* Set some dummy integer in the structure */
1353 gst_structure_set (structure, "foo", G_TYPE_INT, 123, NULL);
1358 GST_START_TEST (test_filter_and_map_in_place)
1360 GstCaps *caps, *caps2;
1363 gst_caps_from_string
1364 ("video/x-raw, format=I420; video/x-raw(foo:bar); video/x-h264");
1365 caps2 = gst_caps_from_string ("video/x-raw(foo:bar), foo=(int)123");
1366 gst_caps_filter_and_map_in_place (caps, filter_map_function, NULL);
1367 fail_unless (gst_caps_is_strictly_equal (caps, caps2));
1368 gst_caps_unref (caps);
1369 gst_caps_unref (caps2);
1371 caps = gst_caps_from_string ("video/x-raw, format=I420; video/x-h264");
1372 caps2 = gst_caps_new_empty ();
1373 gst_caps_filter_and_map_in_place (caps, filter_map_function, NULL);
1374 fail_unless (gst_caps_is_strictly_equal (caps, caps2));
1375 gst_caps_unref (caps);
1376 gst_caps_unref (caps2);
1378 caps = gst_caps_new_empty ();
1379 caps2 = gst_caps_new_empty ();
1380 gst_caps_filter_and_map_in_place (caps, filter_map_function, NULL);
1381 fail_unless (gst_caps_is_strictly_equal (caps, caps2));
1382 gst_caps_unref (caps);
1383 gst_caps_unref (caps2);
1389 gst_caps_suite (void)
1391 Suite *s = suite_create ("GstCaps");
1392 TCase *tc_chain = tcase_create ("operations");
1394 suite_add_tcase (s, tc_chain);
1395 tcase_add_test (tc_chain, test_from_string);
1396 tcase_add_test (tc_chain, test_double_append);
1397 tcase_add_test (tc_chain, test_mutability);
1398 tcase_add_test (tc_chain, test_static_caps);
1399 tcase_add_test (tc_chain, test_simplify);
1400 tcase_add_test (tc_chain, test_truncate);
1401 tcase_add_test (tc_chain, test_subset);
1402 tcase_add_test (tc_chain, test_subset_duplication);
1403 tcase_add_test (tc_chain, test_merge_fundamental);
1404 tcase_add_test (tc_chain, test_merge_same);
1405 tcase_add_test (tc_chain, test_merge_subset);
1406 tcase_add_test (tc_chain, test_intersect);
1407 tcase_add_test (tc_chain, test_intersect2);
1408 tcase_add_test (tc_chain, test_intersect_list_duplicate);
1409 tcase_add_test (tc_chain, test_intersect_zigzag);
1410 tcase_add_test (tc_chain, test_intersect_first);
1411 tcase_add_test (tc_chain, test_intersect_first2);
1412 tcase_add_test (tc_chain, test_intersect_duplication);
1413 tcase_add_test (tc_chain, test_intersect_flagset);
1414 tcase_add_test (tc_chain, test_union);
1415 tcase_add_test (tc_chain, test_normalize);
1416 tcase_add_test (tc_chain, test_broken);
1417 tcase_add_test (tc_chain, test_features);
1418 tcase_add_test (tc_chain, test_special_caps);
1419 tcase_add_test (tc_chain, test_foreach);
1420 tcase_add_test (tc_chain, test_map_in_place);
1421 tcase_add_test (tc_chain, test_filter_and_map_in_place);
1426 GST_CHECK_MAIN (gst_caps);