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);
47 fail_unless (gst_caps_is_equal (caps, caps));
48 fail_unless (gst_caps_is_equal (caps, caps2));
50 gst_caps_unref (caps);
51 gst_caps_unref (caps2);
58 GST_START_TEST (test_double_append)
63 c1 = gst_caps_new_any ();
64 s1 = gst_structure_from_string ("audio/x-raw,rate=44100", NULL);
65 gst_caps_append_structure (c1, s1);
66 ASSERT_CRITICAL (gst_caps_append_structure (c1, s1));
73 GST_START_TEST (test_mutability)
79 c1 = gst_caps_new_any ();
80 s1 = gst_structure_from_string ("audio/x-raw,rate=44100", NULL);
81 gst_structure_set (s1, "rate", G_TYPE_INT, 48000, NULL);
82 gst_caps_append_structure (c1, s1);
83 gst_structure_set (s1, "rate", G_TYPE_INT, 22500, NULL);
85 ASSERT_CRITICAL (gst_structure_set (s1, "rate", G_TYPE_INT, 11250, NULL));
86 fail_unless (gst_structure_get_int (s1, "rate", &ret));
87 fail_unless (ret == 22500);
88 ASSERT_CRITICAL (gst_caps_set_simple (c1, "rate", G_TYPE_INT, 11250, NULL));
89 fail_unless (gst_structure_get_int (s1, "rate", &ret));
90 fail_unless (ret == 22500);
92 gst_structure_set (s1, "rate", G_TYPE_INT, 11250, NULL);
93 fail_unless (gst_structure_get_int (s1, "rate", &ret));
94 fail_unless (ret == 11250);
95 gst_caps_set_simple (c1, "rate", G_TYPE_INT, 1, NULL);
96 fail_unless (gst_structure_get_int (s1, "rate", &ret));
97 fail_unless (ret == 1);
103 GST_START_TEST (test_static_caps)
105 static GstStaticCaps scaps = GST_STATIC_CAPS ("audio/x-raw,rate=44100");
108 static GstStaticCaps sany = GST_STATIC_CAPS_ANY;
109 static GstStaticCaps snone = GST_STATIC_CAPS_NONE;
112 caps1 = gst_static_caps_get (&scaps);
113 fail_unless (caps1 != NULL);
114 /* 1 refcount core, one from us */
115 fail_unless (GST_CAPS_REFCOUNT (caps1) == 2);
117 /* caps should be the same */
118 caps2 = gst_static_caps_get (&scaps);
119 fail_unless (caps2 != NULL);
120 /* 1 refcount core, two from us */
121 fail_unless (GST_CAPS_REFCOUNT (caps1) == 3);
122 /* caps must be equal */
123 fail_unless (caps1 == caps2);
125 gst_caps_unref (caps1);
126 gst_caps_unref (caps2);
128 caps1 = gst_static_caps_get (&sany);
129 fail_unless (gst_caps_is_equal (caps1, GST_CAPS_ANY));
130 caps2 = gst_static_caps_get (&snone);
131 fail_unless (gst_caps_is_equal (caps2, GST_CAPS_NONE));
132 fail_if (gst_caps_is_equal (caps1, caps2));
133 gst_caps_unref (caps1);
134 gst_caps_unref (caps2);
139 static const gchar non_simple_caps_string[] =
140 "video/x-raw, format=(string)I420, framerate=(fraction)[ 1/100, 100 ], "
141 "width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ]; video/x-raw, "
142 "format=(string)YUY2, framerate=(fraction)[ 1/100, 100 ], width=(int)[ 16, 4096 ], "
143 "height=(int)[ 16, 4096 ]; video/x-raw, format=(string)RGB8_PALETTED, "
144 "framerate=(fraction)[ 1/100, 100 ], width=(int)[ 16, 4096 ], "
145 "height=(int)[ 16, 4096 ]; video/x-raw, "
146 "format=(string){ I420, YUY2, YV12 }, width=(int)[ 16, 4096 ], "
147 "height=(int)[ 16, 4096 ], framerate=(fraction)[ 1/100, 100 ]";
150 check_string_list (const GValue * format_value)
152 const GValue *string_value;
153 gboolean got_rgb8 = FALSE;
154 gboolean got_yv12 = FALSE;
155 gboolean got_i420 = FALSE;
156 gboolean got_yuy2 = FALSE;
159 string_value = gst_value_list_get_value (format_value, 0);
160 fail_unless (string_value != NULL);
161 fail_unless (G_VALUE_HOLDS_STRING (string_value));
162 string = g_value_get_string (string_value);
163 fail_unless (string != NULL);
164 got_rgb8 = got_rgb8 || (g_str_equal (string, "RGB8_PALETTED"));
165 got_i420 = got_i420 || (g_str_equal (string, "I420"));
166 got_yuy2 = got_yuy2 || (g_str_equal (string, "YUY2"));
167 got_yv12 = got_yv12 || (g_str_equal (string, "YV12"));
169 string_value = gst_value_list_get_value (format_value, 1);
170 fail_unless (string_value != NULL);
171 fail_unless (G_VALUE_HOLDS_STRING (string_value));
172 string = g_value_get_string (string_value);
173 fail_unless (string != NULL);
174 got_rgb8 = got_rgb8 || (g_str_equal (string, "RGB8_PALETTED"));
175 got_i420 = got_i420 || (g_str_equal (string, "I420"));
176 got_yuy2 = got_yuy2 || (g_str_equal (string, "YUY2"));
177 got_yv12 = got_yv12 || (g_str_equal (string, "YV12"));
179 string_value = gst_value_list_get_value (format_value, 2);
180 fail_unless (string_value != NULL);
181 fail_unless (G_VALUE_HOLDS_STRING (string_value));
182 string = g_value_get_string (string_value);
183 fail_unless (string != NULL);
184 got_rgb8 = got_rgb8 || (g_str_equal (string, "RGB8_PALETTED"));
185 got_i420 = got_i420 || (g_str_equal (string, "I420"));
186 got_yuy2 = got_yuy2 || (g_str_equal (string, "YUY2"));
187 got_yv12 = got_yv12 || (g_str_equal (string, "YV12"));
189 string_value = gst_value_list_get_value (format_value, 3);
190 fail_unless (string_value != NULL);
191 fail_unless (G_VALUE_HOLDS_STRING (string_value));
192 string = g_value_get_string (string_value);
193 fail_unless (string != NULL);
194 got_rgb8 = got_rgb8 || (g_str_equal (string, "RGB8_PALETTED"));
195 got_i420 = got_i420 || (g_str_equal (string, "I420"));
196 got_yuy2 = got_yuy2 || (g_str_equal (string, "YUY2"));
197 got_yv12 = got_yv12 || (g_str_equal (string, "YV12"));
199 return (got_rgb8 && got_i420 && got_yuy2 && got_yv12);
202 GST_START_TEST (test_simplify)
207 caps = gst_caps_from_string (non_simple_caps_string);
208 fail_unless (caps != NULL,
209 "gst_caps_from_string (non_simple_caps_string) failed");
211 caps = gst_caps_simplify (caps);
212 fail_unless (caps != NULL, "gst_caps_simplify() should have worked");
214 /* check simplified caps, should be:
216 * video/x-raw, format=(string){ RGB8_PALETTED, YV12, YUY2, I420 },
217 * width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ],
218 * framerate=(fraction)[ 1/100, 100 ]
220 GST_DEBUG ("simplyfied %" GST_PTR_FORMAT, caps);
221 fail_unless (gst_caps_get_size (caps) == 1);
222 s1 = gst_caps_get_structure (caps, 0);
223 fail_unless (s1 != NULL);
225 fail_unless (gst_structure_has_name (s1, "video/x-raw"));
227 const GValue *framerate_value;
228 const GValue *format_value;
229 const GValue *width_value;
230 const GValue *height_value;
231 const GValue *val_fps;
232 GValue test_fps = { 0, };
233 gint min_width, max_width;
234 gint min_height, max_height;
236 format_value = gst_structure_get_value (s1, "format");
237 fail_unless (format_value != NULL);
238 fail_unless (GST_VALUE_HOLDS_LIST (format_value));
239 fail_unless (gst_value_list_get_size (format_value) == 4);
240 fail_unless (check_string_list (format_value) == TRUE);
242 g_value_init (&test_fps, GST_TYPE_FRACTION);
243 framerate_value = gst_structure_get_value (s1, "framerate");
244 fail_unless (framerate_value != NULL);
245 fail_unless (GST_VALUE_HOLDS_FRACTION_RANGE (framerate_value));
247 val_fps = gst_value_get_fraction_range_min (framerate_value);
248 gst_value_set_fraction (&test_fps, 1, 100);
249 fail_unless (gst_value_compare (&test_fps, val_fps) == GST_VALUE_EQUAL);
251 val_fps = gst_value_get_fraction_range_max (framerate_value);
252 gst_value_set_fraction (&test_fps, 100, 1);
253 fail_unless (gst_value_compare (&test_fps, val_fps) == GST_VALUE_EQUAL);
255 g_value_unset (&test_fps);
257 width_value = gst_structure_get_value (s1, "width");
258 fail_unless (width_value != NULL);
259 fail_unless (GST_VALUE_HOLDS_INT_RANGE (width_value));
260 min_width = gst_value_get_int_range_min (width_value);
261 max_width = gst_value_get_int_range_max (width_value);
262 fail_unless (min_width == 16 && max_width == 4096);
264 height_value = gst_structure_get_value (s1, "height");
265 fail_unless (height_value != NULL);
266 fail_unless (GST_VALUE_HOLDS_INT_RANGE (height_value));
267 min_height = gst_value_get_int_range_min (height_value);
268 max_height = gst_value_get_int_range_max (height_value);
269 fail_unless (min_height == 16 && max_height == 4096);
272 gst_caps_unref (caps);
277 GST_START_TEST (test_truncate)
281 caps = gst_caps_from_string (non_simple_caps_string);
282 fail_unless (caps != NULL,
283 "gst_caps_from_string (non_simple_caps_string) failed");
284 fail_unless_equals_int (gst_caps_get_size (caps), 4);
285 caps = gst_caps_truncate (caps);
286 fail_unless_equals_int (gst_caps_get_size (caps), 1);
287 gst_caps_unref (caps);
292 GST_START_TEST (test_subset)
296 c1 = gst_caps_from_string ("video/x-raw; video/x-raw");
297 c2 = gst_caps_from_string ("video/x-raw, format=(string)YUY2");
298 fail_unless (gst_caps_is_subset (c2, c1));
299 fail_if (gst_caps_is_subset (c1, c2));
303 c1 = gst_caps_from_string
304 ("audio/x-raw, channels=(int)[ 1, 2 ], rate=(int)44100");
305 c2 = gst_caps_from_string ("audio/x-raw, channels=(int)1, rate=(int)44100");
306 fail_unless (gst_caps_is_subset (c2, c1));
307 fail_if (gst_caps_is_subset (c1, c2));
311 c1 = gst_caps_from_string ("audio/x-raw, channels=(int) {1}");
312 c2 = gst_caps_from_string ("audio/x-raw, channels=(int)1");
313 fail_unless (gst_caps_is_subset (c2, c1));
314 fail_unless (gst_caps_is_subset (c1, c2));
315 fail_unless (gst_caps_is_equal (c1, c2));
319 c1 = gst_caps_from_string
320 ("audio/x-raw, rate=(int)44100, channels=(int)3, format=(string)U16_LE");
321 c2 = gst_caps_from_string
322 ("audio/x-raw, rate=(int)[ 1, 2147483647 ], channels=(int)[ 1, 2147483647 ], format=(string){ S16_LE, U16_LE }");
323 fail_unless (gst_caps_is_subset (c1, c2));
324 fail_if (gst_caps_is_subset (c2, c1));
328 c1 = gst_caps_from_string ("video/x-h264, parsed=(boolean)true");
329 c2 = gst_caps_from_string
330 ("video/x-h264, stream-format=(string)byte-stream, alignment=(string)nal");
331 fail_if (gst_caps_is_subset (c2, c1));
332 fail_if (gst_caps_is_subset (c1, c2));
333 fail_if (gst_caps_is_equal (c1, c2));
340 GST_START_TEST (test_subset_duplication)
344 c1 = gst_caps_from_string ("audio/x-raw, format=(string)F32LE");
345 c2 = gst_caps_from_string ("audio/x-raw, format=(string)F32LE");
347 fail_unless (gst_caps_is_subset (c1, c2));
348 fail_unless (gst_caps_is_subset (c2, c1));
351 c2 = gst_caps_from_string ("audio/x-raw, format=(string){ F32LE }");
353 fail_unless (gst_caps_is_subset (c1, c2));
354 fail_unless (gst_caps_is_subset (c2, c1));
357 c2 = gst_caps_from_string ("audio/x-raw, format=(string){ F32LE, F32LE }");
359 fail_unless (gst_caps_is_subset (c1, c2));
360 fail_unless (gst_caps_is_subset (c2, c1));
363 c2 = gst_caps_from_string
364 ("audio/x-raw, format=(string){ F32LE, F32LE, F32LE }");
366 fail_unless (gst_caps_is_subset (c1, c2));
367 fail_unless (gst_caps_is_subset (c2, c1));
375 GST_START_TEST (test_merge_fundamental)
379 /* ANY + specific = ANY */
380 c1 = gst_caps_from_string ("audio/x-raw,rate=44100");
381 c2 = gst_caps_new_any ();
382 c2 = gst_caps_merge (c2, c1);
383 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
384 fail_unless (gst_caps_get_size (c2) == 0, NULL);
385 fail_unless (gst_caps_is_any (c2), NULL);
388 /* specific + ANY = ANY */
389 c2 = gst_caps_from_string ("audio/x-raw,rate=44100");
390 c1 = gst_caps_new_any ();
391 c2 = gst_caps_merge (c2, c1);
392 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
393 fail_unless (gst_caps_get_size (c2) == 0, NULL);
394 fail_unless (gst_caps_is_any (c2), NULL);
397 /* EMPTY + specific = specific */
398 c1 = gst_caps_from_string ("audio/x-raw,rate=44100");
399 c2 = gst_caps_new_empty ();
400 c2 = gst_caps_merge (c2, c1);
401 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
402 fail_unless (gst_caps_get_size (c2) == 1, NULL);
403 fail_if (gst_caps_is_empty (c2), NULL);
406 /* specific + EMPTY = specific */
407 c2 = gst_caps_from_string ("audio/x-raw,rate=44100");
408 c1 = gst_caps_new_empty ();
409 c2 = gst_caps_merge (c2, c1);
410 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
411 fail_unless (gst_caps_get_size (c2) == 1, NULL);
412 fail_if (gst_caps_is_empty (c2), NULL);
418 GST_START_TEST (test_merge_same)
420 GstCaps *c1, *c2, *test;
422 /* this is the same */
423 c1 = gst_caps_from_string ("audio/x-raw,rate=44100,channels=1");
424 c2 = gst_caps_from_string ("audio/x-raw,rate=44100,channels=1");
425 c2 = gst_caps_merge (c2, c1);
426 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
427 fail_unless (gst_caps_get_size (c2) == 1, NULL);
428 test = gst_caps_from_string ("audio/x-raw,rate=44100,channels=1");
429 fail_unless (gst_caps_is_equal (c2, test));
430 gst_caps_unref (test);
434 c1 = gst_caps_from_string ("audio/x-raw,rate=44100,channels=1");
435 c2 = gst_caps_from_string ("audio/x-raw,channels=1,rate=44100");
436 c2 = gst_caps_merge (c2, c1);
437 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
438 fail_unless (gst_caps_get_size (c2) == 1, NULL);
441 c1 = gst_caps_from_string ("video/x-foo, data=(buffer)AA");
442 c2 = gst_caps_from_string ("video/x-foo, data=(buffer)AABB");
443 c2 = gst_caps_merge (c2, c1);
444 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
445 fail_unless (gst_caps_get_size (c2) == 2, NULL);
448 c1 = gst_caps_from_string ("video/x-foo, data=(buffer)AABB");
449 c2 = gst_caps_from_string ("video/x-foo, data=(buffer)AA");
450 c2 = gst_caps_merge (c2, c1);
451 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
452 fail_unless (gst_caps_get_size (c2) == 2, NULL);
455 c1 = gst_caps_from_string ("video/x-foo, data=(buffer)AA");
456 c2 = gst_caps_from_string ("video/x-foo, data=(buffer)AA");
457 c2 = gst_caps_merge (c2, c1);
458 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
459 fail_unless (gst_caps_get_size (c2) == 1, NULL);
462 c1 = gst_caps_from_string ("video/x-foo, data=(buffer)AA");
463 c2 = gst_caps_from_string ("video/x-bar, data=(buffer)AA");
464 c2 = gst_caps_merge (c2, c1);
465 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
466 fail_unless (gst_caps_get_size (c2) == 2, NULL);
472 GST_START_TEST (test_merge_subset)
474 GstCaps *c1, *c2, *test;
476 /* the 2nd is already covered */
477 c2 = gst_caps_from_string ("audio/x-raw,channels=[1,2]");
478 c1 = gst_caps_from_string ("audio/x-raw,channels=1");
479 c2 = gst_caps_merge (c2, c1);
480 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
481 fail_unless (gst_caps_get_size (c2) == 1, NULL);
482 test = gst_caps_from_string ("audio/x-raw,channels=[1,2]");
483 fail_unless (gst_caps_is_equal (c2, test));
485 gst_caps_unref (test);
488 c2 = gst_caps_from_string ("audio/x-raw,channels=1,rate=44100");
489 c1 = gst_caps_from_string ("audio/x-raw,channels=[1,2],rate=44100");
490 c2 = gst_caps_merge (c2, c1);
491 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
492 fail_unless (gst_caps_get_size (c2) == 2, NULL);
493 test = gst_caps_from_string ("audio/x-raw,channels=[1,2],rate=44100");
494 fail_unless (gst_caps_is_equal (c2, test));
496 gst_caps_unref (test);
498 /* second one was already contained in the first one */
499 c2 = gst_caps_from_string ("audio/x-raw,channels=[1,3]");
500 c1 = gst_caps_from_string ("audio/x-raw,channels=[1,2]");
501 c2 = gst_caps_merge (c2, c1);
502 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
503 fail_unless (gst_caps_get_size (c2) == 1, NULL);
504 test = gst_caps_from_string ("audio/x-raw,channels=[1,3]");
505 fail_unless (gst_caps_is_equal (c2, test));
507 gst_caps_unref (test);
509 /* second one was already contained in the first one */
510 c2 = gst_caps_from_string ("audio/x-raw,channels=[1,4]");
511 c1 = gst_caps_from_string ("audio/x-raw,channels=[1,2]");
512 c2 = gst_caps_merge (c2, c1);
513 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
514 fail_unless (gst_caps_get_size (c2) == 1, NULL);
515 test = gst_caps_from_string ("audio/x-raw,channels=[1,4]");
516 fail_unless (gst_caps_is_equal (c2, test));
518 gst_caps_unref (test);
520 /* second one was already contained in the first one */
521 c2 = gst_caps_from_string ("audio/x-raw,channels=[1,4]");
522 c1 = gst_caps_from_string ("audio/x-raw,channels=[2,4]");
523 c2 = gst_caps_merge (c2, c1);
524 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
525 fail_unless (gst_caps_get_size (c2) == 1, NULL);
526 test = gst_caps_from_string ("audio/x-raw,channels=[1,4]");
527 fail_unless (gst_caps_is_equal (c2, test));
529 gst_caps_unref (test);
531 /* second one was already contained in the first one */
532 c2 = gst_caps_from_string ("audio/x-raw,channels=[1,4]");
533 c1 = gst_caps_from_string ("audio/x-raw,channels=[2,3]");
534 c2 = gst_caps_merge (c2, c1);
535 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
536 fail_unless (gst_caps_get_size (c2) == 1, NULL);
537 test = gst_caps_from_string ("audio/x-raw,channels=[1,4]");
538 fail_unless (gst_caps_is_equal (c2, test));
540 gst_caps_unref (test);
542 /* these caps cannot be merged */
543 c2 = gst_caps_from_string ("audio/x-raw,channels=[2,3]");
544 c1 = gst_caps_from_string ("audio/x-raw,channels=[1,4]");
545 c2 = gst_caps_merge (c2, c1);
546 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
547 fail_unless (gst_caps_get_size (c2) == 2, NULL);
550 ("audio/x-raw,channels=[2,3];audio/x-raw,channels=[1,4]");
551 fail_unless (gst_caps_is_equal (c2, test));
553 gst_caps_unref (test);
555 /* these caps cannot be merged */
556 c2 = gst_caps_from_string ("audio/x-raw,channels=[1,2]");
557 c1 = gst_caps_from_string ("audio/x-raw,channels=[1,3]");
558 c2 = gst_caps_merge (c2, c1);
559 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
560 fail_unless (gst_caps_get_size (c2) == 2, NULL);
563 ("audio/x-raw,channels=[1,2];audio/x-raw,channels=[1,3]");
564 fail_unless (gst_caps_is_equal (c2, test));
566 gst_caps_unref (test);
568 c2 = gst_caps_from_string ("audio/x-raw,channels={1,2}");
569 c1 = gst_caps_from_string ("audio/x-raw,channels={1,2,3,4}");
570 c2 = gst_caps_merge (c2, c1);
571 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
572 fail_unless (gst_caps_get_size (c2) == 2, NULL);
573 test = gst_caps_from_string ("audio/x-raw,channels={1,2};"
574 "audio/x-raw,channels={1,2,3,4}");
575 fail_unless (gst_caps_is_equal (c2, test));
577 gst_caps_unref (test);
579 c2 = gst_caps_from_string ("audio/x-raw,channels={1,2}");
580 c1 = gst_caps_from_string ("audio/x-raw,channels={1,3}");
581 c2 = gst_caps_merge (c2, c1);
582 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
583 fail_unless (gst_caps_get_size (c2) == 2, NULL);
584 test = gst_caps_from_string ("audio/x-raw,channels={1,2};"
585 "audio/x-raw,channels={1,3}");
586 fail_unless (gst_caps_is_equal (c2, test));
588 gst_caps_unref (test);
590 c2 = gst_caps_from_string ("video/x-raw, framerate=(fraction){ 15/2, 5/1 }");
591 c1 = gst_caps_from_string ("video/x-raw, framerate=(fraction){ 15/1, 5/1 }");
592 test = gst_caps_copy (c1);
593 c2 = gst_caps_merge (c2, c1);
594 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
595 fail_unless (gst_caps_is_subset (test, c2));
596 gst_caps_unref (test);
599 c2 = gst_caps_from_string ("audio/x-raw");
600 c1 = gst_caps_from_string ("audio/x-raw,channels=1");
601 c2 = gst_caps_merge (c2, c1);
602 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
603 fail_unless (gst_caps_get_size (c2) == 1, NULL);
604 test = gst_caps_from_string ("audio/x-raw");
605 fail_unless (gst_caps_is_equal (c2, test));
607 gst_caps_unref (test);
609 c2 = gst_caps_from_string ("audio/x-raw,channels=1");
610 c1 = gst_caps_from_string ("audio/x-raw");
611 c2 = gst_caps_merge (c2, c1);
612 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
613 fail_unless (gst_caps_get_size (c2) == 2, NULL);
614 test = gst_caps_from_string ("audio/x-raw,channels=1; audio/x-raw");
615 fail_unless (gst_caps_is_equal (c2, test));
617 gst_caps_unref (test);
622 GST_START_TEST (test_intersect)
625 GstCaps *c1, *c2, *ci1, *ci2;
627 /* field not specified = any value possible, so the intersection
628 * should keep fields which are only part of one set of caps */
629 c2 = gst_caps_from_string ("video/x-raw,format=(string)I420,width=20");
630 c1 = gst_caps_from_string ("video/x-raw,format=(string)I420");
632 ci1 = gst_caps_intersect (c2, c1);
633 GST_DEBUG ("intersected: %" GST_PTR_FORMAT, ci1);
634 fail_unless (gst_caps_get_size (ci1) == 1, NULL);
635 s = gst_caps_get_structure (ci1, 0);
636 fail_unless (gst_structure_has_name (s, "video/x-raw"));
637 fail_unless (gst_structure_get_value (s, "format") != NULL);
638 fail_unless (gst_structure_get_value (s, "width") != NULL);
640 /* with changed order */
641 ci2 = gst_caps_intersect (c1, c2);
642 GST_DEBUG ("intersected: %" GST_PTR_FORMAT, ci2);
643 fail_unless (gst_caps_get_size (ci2) == 1, NULL);
644 s = gst_caps_get_structure (ci2, 0);
645 fail_unless (gst_structure_has_name (s, "video/x-raw"));
646 fail_unless (gst_structure_get_value (s, "format") != NULL);
647 fail_unless (gst_structure_get_value (s, "width") != NULL);
649 fail_unless (gst_caps_is_equal (ci1, ci2));
651 gst_caps_unref (ci1);
652 gst_caps_unref (ci2);
659 c2 = gst_caps_from_string ("video/x-raw,format=(string)I420,width=20");
660 c1 = gst_caps_from_string ("video/x-raw,format=(string)I420,width=30");
662 ci1 = gst_caps_intersect (c2, c1);
663 GST_DEBUG ("intersected: %" GST_PTR_FORMAT, ci1);
664 fail_unless (gst_caps_is_empty (ci1), NULL);
666 /* with changed order */
667 ci2 = gst_caps_intersect (c1, c2);
668 GST_DEBUG ("intersected: %" GST_PTR_FORMAT, ci2);
669 fail_unless (gst_caps_is_empty (ci2), NULL);
671 fail_unless (gst_caps_is_equal (ci1, ci2));
673 gst_caps_unref (ci1);
674 gst_caps_unref (ci2);
681 c2 = gst_caps_from_string ("video/x-raw,format=(string)I420,width=20");
682 c1 = gst_caps_from_string ("video/x-raw2,format=(string)I420,width=20");
684 ci1 = gst_caps_intersect (c2, c1);
685 GST_DEBUG ("intersected: %" GST_PTR_FORMAT, ci1);
686 fail_unless (gst_caps_is_empty (ci1), NULL);
688 /* with changed order */
689 ci2 = gst_caps_intersect (c1, c2);
690 GST_DEBUG ("intersected: %" GST_PTR_FORMAT, ci2);
691 fail_unless (gst_caps_is_empty (ci2), NULL);
693 fail_unless (gst_caps_is_equal (ci1, ci2));
695 gst_caps_unref (ci1);
696 gst_caps_unref (ci2);
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,height=30");
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);
713 fail_unless (gst_structure_get_value (s, "height") != NULL);
715 /* with changed order */
716 ci2 = gst_caps_intersect (c1, c2);
717 GST_DEBUG ("intersected: %" GST_PTR_FORMAT, ci2);
718 fail_unless (gst_caps_get_size (ci2) == 1, NULL);
719 s = gst_caps_get_structure (ci2, 0);
720 fail_unless (gst_structure_has_name (s, "video/x-raw"));
721 fail_unless (gst_structure_get_value (s, "format") != NULL);
722 fail_unless (gst_structure_get_value (s, "height") != NULL);
723 fail_unless (gst_structure_get_value (s, "width") != NULL);
725 fail_unless (gst_caps_is_equal (ci1, ci2));
727 gst_caps_unref (ci1);
728 gst_caps_unref (ci2);
736 GST_START_TEST (test_intersect2)
738 GstCaps *caps1, *caps2, *icaps;
740 /* tests array subtraction */
741 caps1 = gst_caps_from_string ("audio/x-raw, "
742 "channel-positions=(int)< "
743 "{ 1, 2, 3, 4, 5, 6 }, "
744 "{ 1, 2, 3, 4, 5, 6 }, "
745 "{ 1, 2, 3, 4, 5, 6 }, "
746 "{ 1, 2, 3, 4, 5, 6 }, "
747 "{ 1, 2, 3, 4, 5, 6 }, " "{ 1, 2, 3, 4, 5, 6 }>");
748 caps2 = gst_caps_from_string ("audio/x-raw, "
749 "channel-positions=(int)< 1, 2, 3, 4, 5, 6 >");
750 icaps = gst_caps_intersect (caps1, caps2);
751 GST_LOG ("intersected caps: %" GST_PTR_FORMAT, icaps);
752 fail_if (gst_caps_is_empty (icaps));
753 fail_unless (gst_caps_is_equal (icaps, caps2));
754 gst_caps_unref (caps1);
755 gst_caps_unref (caps2);
756 gst_caps_unref (icaps);
760 caps1 = gst_caps_from_string ("some/type, foo=(int)< { 1, 2 }, { 3, 4} >");
761 caps2 = gst_caps_from_string ("some/type, foo=(int)< 1, 3 >");
762 icaps = gst_caps_intersect (caps1, caps2);
763 GST_LOG ("intersected caps: %" GST_PTR_FORMAT, icaps);
764 fail_if (gst_caps_is_empty (icaps));
765 fail_unless (gst_caps_is_equal (icaps, caps2));
766 gst_caps_unref (caps1);
767 gst_caps_unref (caps2);
768 gst_caps_unref (icaps);
773 GST_START_TEST (test_intersect_list_duplicate)
775 GstCaps *caps1, *caps2, *icaps;
777 /* make sure we don't take too long to intersect these.. */
778 caps1 = gst_caps_from_string ("video/x-raw, format=(string)YV12; "
779 "video/x-raw, format=(string)I420; video/x-raw, format=(string)YUY2; "
780 "video/x-raw, format=(string)UYVY; "
781 "video/x-raw, format=(string){ I420, YV12, YUY2, UYVY, AYUV, RGBx, BGRx,"
782 " xRGB, xBGR, { 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 } } }, { RGBA, RGBA, { RGBA, RGBA }, "
789 "{ RGBA, RGBA, { RGBA, RGBA } }, { RGBA, RGBA, { RGBA, RGBA }, "
790 "{ RGBA, RGBA, { RGBA, RGBA } } } } } }, BGRA, ARGB, { ABGR, ABGR, "
791 "{ 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 "{ ABGR, ABGR, { ABGR, ABGR }, { ABGR, ABGR, { ABGR, ABGR } }, "
798 "{ ABGR, ABGR, { ABGR, ABGR }, { ABGR, ABGR, { ABGR, ABGR } } } } } }, "
799 "RGB, BGR, Y41B, Y42B, YVYU, Y444 }; "
800 "video/x-raw, format=(string){ I420, YV12, YUY2, UYVY, AYUV, RGBx, BGRx, "
801 "xRGB, xBGR, { 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 } } }, { RGBA, RGBA, { RGBA, RGBA }, "
808 "{ RGBA, RGBA, { RGBA, RGBA } }, { RGBA, RGBA, { RGBA, RGBA }, "
809 "{ RGBA, RGBA, { RGBA, RGBA } } } } } }, BGRA, ARGB, "
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 "{ ABGR, ABGR, { ABGR, ABGR }, { ABGR, ABGR, { ABGR, ABGR } }, "
817 "{ ABGR, ABGR, { ABGR, ABGR }, { ABGR, ABGR, { ABGR, ABGR } } } } } }, "
818 "RGB, BGR, Y41B, Y42B, YVYU, Y444, NV12, NV21 }; "
819 "video/x-raw, format=(string){ I420, YV12, YUY2, UYVY, AYUV, RGBx, "
820 "BGRx, xRGB, xBGR, { RGBA, RGBA, { RGBA, RGBA }, "
821 "{ RGBA, RGBA, { RGBA, RGBA } }, { RGBA, RGBA, { RGBA, RGBA }, "
822 "{ RGBA, RGBA, { RGBA, RGBA } } } }, BGRA, ARGB, "
823 "{ ABGR, ABGR, { ABGR, ABGR }, { ABGR, ABGR, { ABGR, ABGR } }, "
824 "{ ABGR, ABGR, { ABGR, ABGR }, { ABGR, ABGR, { ABGR, ABGR } } } }, "
825 "RGB, BGR, Y41B, Y42B, YVYU, Y444, NV12, NV21 }");
827 caps2 = gst_caps_copy (caps1);
829 icaps = gst_caps_intersect (caps1, caps2);
831 gst_caps_unref (caps1);
832 gst_caps_unref (caps2);
833 gst_caps_unref (icaps);
838 GST_START_TEST (test_intersect_zigzag)
840 GstCaps *caps1, *caps2, *icaps, *result;
842 /* tests if caps order is maintained */
843 caps1 = gst_caps_from_string ("format/A; format/B; format/C; format/D");
844 caps2 = gst_caps_from_string ("format/D; format/A; format/B; format/C");
846 icaps = gst_caps_intersect_full (caps1, caps2, GST_CAPS_INTERSECT_ZIG_ZAG);
847 result = gst_caps_from_string ("format/B; format/A; format/D; format/C");
848 GST_LOG ("intersected caps: %" GST_PTR_FORMAT, icaps);
849 fail_if (gst_caps_is_empty (icaps));
850 fail_unless (gst_caps_is_equal (icaps, result));
851 gst_caps_unref (icaps);
852 gst_caps_unref (result);
854 icaps = gst_caps_intersect_full (caps2, caps1, GST_CAPS_INTERSECT_FIRST);
855 result = gst_caps_from_string ("format/A; format/B; format/D; format/C");
856 GST_LOG ("intersected caps: %" GST_PTR_FORMAT, icaps);
857 fail_if (gst_caps_is_empty (icaps));
858 fail_unless (gst_caps_is_equal (icaps, result));
859 gst_caps_unref (icaps);
860 gst_caps_unref (result);
862 gst_caps_unref (caps1);
863 gst_caps_unref (caps2);
869 GST_START_TEST (test_intersect_first)
871 GstCaps *caps1, *caps2, *icaps, *result;
873 /* tests if caps order is maintained */
874 caps1 = gst_caps_from_string ("format/A; format/B; format/C; format/D");
875 caps2 = gst_caps_from_string ("format/C; format/D; format/A");
876 icaps = gst_caps_intersect_full (caps1, caps2, GST_CAPS_INTERSECT_FIRST);
877 result = gst_caps_from_string ("format/A; format/C; format/D");
878 GST_LOG ("intersected caps: %" GST_PTR_FORMAT, icaps);
879 fail_if (gst_caps_is_empty (icaps));
880 fail_unless (gst_caps_is_equal (icaps, result));
881 gst_caps_unref (caps1);
882 gst_caps_unref (caps2);
883 gst_caps_unref (icaps);
884 gst_caps_unref (result);
890 GST_START_TEST (test_intersect_first2)
892 GstCaps *caps1, *caps2, *icaps, *result;
894 /* tests if caps order is maintained */
895 caps1 = gst_caps_from_string ("format/A; format/B; format/C; format/D");
896 caps2 = gst_caps_from_string ("format/D; format/A; format/B; format/C");
898 icaps = gst_caps_intersect_full (caps1, caps2, GST_CAPS_INTERSECT_FIRST);
899 result = gst_caps_from_string ("format/A; format/B; format/C; format/D");
900 GST_LOG ("intersected caps: %" GST_PTR_FORMAT, icaps);
901 fail_if (gst_caps_is_empty (icaps));
902 fail_unless (gst_caps_is_equal (icaps, result));
903 gst_caps_unref (icaps);
904 gst_caps_unref (result);
906 icaps = gst_caps_intersect_full (caps2, caps1, GST_CAPS_INTERSECT_FIRST);
907 result = gst_caps_from_string ("format/D; format/A; format/B; format/C");
908 GST_LOG ("intersected caps: %" GST_PTR_FORMAT, icaps);
909 fail_if (gst_caps_is_empty (icaps));
910 fail_unless (gst_caps_is_equal (icaps, result));
911 gst_caps_unref (icaps);
912 gst_caps_unref (result);
914 gst_caps_unref (caps1);
915 gst_caps_unref (caps2);
920 GST_START_TEST (test_intersect_duplication)
922 GstCaps *c1, *c2, *test;
924 c1 = gst_caps_from_string
925 ("audio/x-raw, format=(string)S16_LE, rate=(int)[ 1, 2147483647 ], channels=(int)[ 1, 2 ]");
926 c2 = gst_caps_from_string
927 ("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 ]");
929 test = gst_caps_intersect_full (c1, c2, GST_CAPS_INTERSECT_FIRST);
930 fail_unless_equals_int (gst_caps_get_size (test), 1);
931 fail_unless (gst_caps_is_equal (c1, test));
934 gst_caps_unref (test);
939 GST_START_TEST (test_intersect_flagset)
941 GstCaps *c1, *c2, *test;
942 GType test_flagset_type;
943 GstSeekFlags test_flags, test_mask;
946 /* Test that matching bits inside the mask intersect,
947 * and bits outside the mask don't matter */
948 c1 = gst_caps_from_string ("test/x-caps,field=ffd81d:fffff0");
949 c2 = gst_caps_from_string ("test/x-caps,field=0fd81f:0ffff0");
951 test = gst_caps_intersect_full (c1, c2, GST_CAPS_INTERSECT_FIRST);
952 fail_unless_equals_int (gst_caps_get_size (test), 1);
953 fail_unless (gst_caps_is_equal (c1, test));
956 gst_caps_unref (test);
958 /* Test that non-matching bits in the mask don't intersect */
959 c1 = gst_caps_from_string ("test/x-caps,field=ff001d:0ffff0");
960 c2 = gst_caps_from_string ("test/x-caps,field=0fd81f:0ffff0");
962 test = gst_caps_intersect_full (c1, c2, GST_CAPS_INTERSECT_FIRST);
963 fail_unless (gst_caps_is_empty (test));
966 gst_caps_unref (test);
968 /* Check custom flags type serialisation and de-serialisation */
969 test_flagset_type = gst_flagset_register (GST_TYPE_SEEK_FLAGS);
970 fail_unless (g_type_is_a (test_flagset_type, GST_TYPE_FLAG_SET));
973 GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_TRICKMODE |
974 GST_SEEK_FLAG_TRICKMODE_KEY_UNITS;
976 GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_TRICKMODE |
977 GST_SEEK_FLAG_TRICKMODE_NO_AUDIO;
979 c1 = gst_caps_new_simple ("test/x-caps", "field", test_flagset_type,
980 test_flags, test_mask, NULL);
982 test_string = gst_caps_to_string (c1);
983 fail_if (test_string == NULL);
985 GST_DEBUG ("Serialised caps to %s", test_string);
986 c2 = gst_caps_from_string (test_string);
987 g_free (test_string);
989 fail_unless (gst_caps_is_equal (c1, c2), "Caps %s != %s",
990 gst_caps_to_string (c1), gst_caps_to_string (c2));
998 GST_START_TEST (test_union)
1000 GstCaps *c1, *c2, *test, *expect;
1002 /* Test that matching bits inside the masks union OK, */
1003 c1 = gst_caps_from_string ("test/x-caps,field=ffd81d:0ffff0");
1004 c2 = gst_caps_from_string ("test/x-caps,field=0fd81f:0ffff0");
1006 test = gst_caps_merge (c1, c2);
1007 test = gst_caps_simplify (test);
1008 /* c1, c2 now invalid */
1009 fail_unless_equals_int (gst_caps_get_size (test), 1);
1010 gst_caps_unref (test);
1012 /* Test that non-intersecting sets of masked bits are OK */
1013 c1 = gst_caps_from_string ("test/x-caps,field=ff001d:0ffff0");
1014 c2 = gst_caps_from_string ("test/x-caps,field=4fd81f:f00000");
1015 expect = gst_caps_from_string ("test/x-caps,field=4f001d:fffff0");
1016 test = gst_caps_simplify (gst_caps_merge (c1, c2));
1017 /* c1, c2 now invalid */
1018 GST_LOG ("Expected caps %" GST_PTR_FORMAT " got %" GST_PTR_FORMAT "\n",
1020 fail_unless (gst_caps_is_equal (test, expect));
1021 gst_caps_unref (test);
1022 gst_caps_unref (expect);
1024 /* Test that partially-intersecting sets of masked bits that match are OK */
1025 c1 = gst_caps_from_string ("test/x-caps,field=ff001d:0ffff0");
1026 c2 = gst_caps_from_string ("test/x-caps,field=4fd81f:ff0000");
1027 expect = gst_caps_from_string ("test/x-caps,field=4f001d:fffff0");
1028 test = gst_caps_simplify (gst_caps_merge (c1, c2));
1029 /* c1, c2 now invalid */
1030 GST_LOG ("Expected caps %" GST_PTR_FORMAT " got %" GST_PTR_FORMAT "\n",
1032 fail_unless (gst_caps_is_equal (test, expect));
1033 gst_caps_unref (test);
1034 gst_caps_unref (expect);
1040 _caps_is_fixed_foreach (GQuark field_id, const GValue * value, gpointer unused)
1042 return gst_value_is_fixed (value);
1046 GST_START_TEST (test_normalize)
1048 GstCaps *in, *norm, *out;
1051 in = gst_caps_from_string ("some/type, foo=(int){ 1 , 2 }");
1052 out = gst_caps_from_string ("some/type, foo=(int) 1; some/type, foo=(int) 2");
1053 norm = gst_caps_normalize (in);
1054 fail_if (gst_caps_is_empty (norm));
1055 fail_unless (gst_caps_is_equal (norm, out));
1056 for (i = 0; i < gst_caps_get_size (norm); i++) {
1057 GstStructure *st = gst_caps_get_structure (norm, i);
1058 /* Make sure all fields of all structures are fixed */
1059 fail_unless (gst_structure_foreach (st, _caps_is_fixed_foreach, NULL));
1062 gst_caps_unref (out);
1063 gst_caps_unref (norm);
1065 in = gst_caps_from_string
1066 ("some/type, foo=(int){ 1 , 2 }, bar=(int){ 3, 4 }");
1068 gst_caps_from_string
1069 ("some/type, foo=(int) 1, bar=(int) 3; some/type, foo=(int) 2, bar=(int) 3;"
1070 "some/type, foo=(int) 1, bar=(int) 4; some/type, foo=(int) 2, bar=(int) 4;");
1071 norm = gst_caps_normalize (in);
1072 fail_if (gst_caps_is_empty (norm));
1073 fail_unless (gst_caps_is_equal (norm, out));
1074 for (i = 0; i < gst_caps_get_size (norm); i++) {
1075 GstStructure *st = gst_caps_get_structure (norm, i);
1076 /* Make sure all fields of all structures are fixed */
1077 fail_unless (gst_structure_foreach (st, _caps_is_fixed_foreach, NULL));
1080 gst_caps_unref (out);
1081 gst_caps_unref (norm);
1083 in = gst_caps_from_string
1084 ("some/type, foo=(string){ 1 , 2 }, bar=(string) { 3 }");
1086 gst_caps_from_string
1087 ("some/type, foo=(string) 1, bar=(string) 3; some/type, foo=(string) 2, bar=(string) 3");
1088 norm = gst_caps_normalize (in);
1089 fail_if (gst_caps_is_empty (norm));
1090 fail_unless (gst_caps_is_equal (norm, out));
1091 for (i = 0; i < gst_caps_get_size (norm); i++) {
1092 GstStructure *st = gst_caps_get_structure (norm, i);
1093 /* Make sure all fields of all structures are fixed */
1094 fail_unless (gst_structure_foreach (st, _caps_is_fixed_foreach, NULL));
1097 gst_caps_unref (out);
1098 gst_caps_unref (norm);
1103 GST_START_TEST (test_broken)
1107 /* NULL is not valid for media_type */
1108 ASSERT_CRITICAL (c1 =
1109 gst_caps_new_simple (NULL, "field", G_TYPE_INT, 1, NULL));
1112 /* such a name is not valid, see gst_structure_validate_name() */
1113 ASSERT_CRITICAL (c1 =
1114 gst_caps_new_simple ("1#@abc", "field", G_TYPE_INT, 1, NULL));
1120 GST_START_TEST (test_features)
1122 GstCaps *c1, *c2, *c3;
1123 GstStructure *s1, *s2;
1124 GstCapsFeatures *f1, *f2;
1126 static GstStaticCaps scaps =
1128 ("video/x-raw(memory:EGLImage), width=320, height=[ 240, 260 ]");
1130 c1 = gst_caps_new_empty ();
1131 fail_unless (c1 != NULL);
1132 s1 = gst_structure_new ("video/x-raw", "width", G_TYPE_INT, 320, "height",
1133 GST_TYPE_INT_RANGE, 240, 260, NULL);
1134 fail_unless (s1 != NULL);
1135 f1 = gst_caps_features_new ("memory:EGLImage", NULL);
1136 fail_unless (f1 != NULL);
1138 gst_caps_append_structure_full (c1, s1, f1);
1139 s2 = gst_caps_get_structure (c1, 0);
1140 fail_unless (s1 == s2);
1141 f2 = gst_caps_get_features (c1, 0);
1142 fail_unless (f1 == f2);
1144 str1 = gst_caps_to_string (c1);
1145 fail_unless (str1 != NULL);
1146 c2 = gst_caps_from_string (str1);
1147 fail_unless (c2 != NULL);
1150 fail_unless (gst_caps_is_equal (c1, c2));
1151 fail_unless (gst_caps_is_subset (c1, c2));
1152 fail_unless (gst_caps_is_subset (c2, c1));
1153 fail_unless (gst_caps_can_intersect (c1, c2));
1155 gst_caps_unref (c2);
1157 c2 = gst_caps_new_empty ();
1158 fail_unless (c2 != NULL);
1159 s2 = gst_structure_new ("video/x-raw", "width", G_TYPE_INT, 320, "height",
1160 GST_TYPE_INT_RANGE, 240, 260, NULL);
1161 fail_unless (s2 != NULL);
1162 f2 = gst_caps_features_new ("memory:VASurface", "meta:VAMeta", NULL);
1163 fail_unless (f2 != NULL);
1164 gst_caps_append_structure_full (c2, s2, f2);
1166 fail_if (gst_caps_is_equal (c1, c2));
1167 fail_if (gst_caps_is_subset (c1, c2));
1168 fail_if (gst_caps_is_subset (c2, c1));
1169 fail_if (gst_caps_can_intersect (c1, c2));
1171 str1 = gst_caps_to_string (c2);
1172 fail_unless (str1 != NULL);
1173 c3 = gst_caps_from_string (str1);
1174 fail_unless (c3 != NULL);
1177 fail_unless (gst_caps_is_equal (c2, c3));
1178 fail_unless (gst_caps_is_subset (c2, c3));
1179 fail_unless (gst_caps_is_subset (c3, c2));
1180 fail_unless (gst_caps_can_intersect (c2, c3));
1182 f1 = gst_caps_get_features (c3, 0);
1183 fail_unless (f1 != NULL);
1185 gst_caps_features_contains (f1, "memory:VASurface");
1186 gst_caps_features_remove (f1, "memory:VASurface");
1187 fail_if (gst_caps_is_equal (c2, c3));
1188 fail_if (gst_caps_is_subset (c2, c3));
1189 fail_if (gst_caps_is_subset (c3, c2));
1190 fail_if (gst_caps_can_intersect (c2, c3));
1192 gst_caps_unref (c3);
1193 gst_caps_unref (c2);
1195 c2 = gst_static_caps_get (&scaps);
1196 fail_unless (c2 != NULL);
1197 fail_unless (gst_caps_is_equal (c1, c2));
1198 fail_unless (gst_caps_is_subset (c1, c2));
1199 fail_unless (gst_caps_is_subset (c2, c1));
1200 fail_unless (gst_caps_can_intersect (c1, c2));
1201 gst_caps_unref (c2);
1203 c2 = gst_caps_from_string
1204 ("video/x-raw(ANY), width=320, height=[ 240, 260 ]");
1205 fail_unless (c2 != NULL);
1206 fail_if (gst_caps_is_equal (c1, c2));
1207 fail_unless (gst_caps_is_subset (c1, c2));
1208 fail_if (gst_caps_is_subset (c2, c1));
1209 fail_unless (gst_caps_can_intersect (c1, c2));
1211 c3 = gst_caps_intersect (c1, c2);
1212 fail_unless (gst_caps_is_equal (c3, c1));
1214 gst_caps_unref (c3);
1215 gst_caps_unref (c2);
1216 gst_caps_unref (c1);
1218 c1 = gst_caps_from_string ("video/x-raw");
1219 c2 = gst_caps_from_string ("video/x-raw");
1221 f1 = gst_caps_get_features (c1, 0);
1222 gst_caps_features_add (f1, "memory:VASurface");
1224 fail_unless (gst_caps_features_is_equal (f1, gst_caps_get_features (c1, 0)));
1225 fail_if (gst_caps_can_intersect (c1, c2));
1227 f2 = gst_caps_get_features (c2, 0);
1228 fail_unless (gst_caps_features_is_equal
1229 (GST_CAPS_FEATURES_MEMORY_SYSTEM_MEMORY, f2));
1231 gst_caps_unref (c2);
1232 gst_caps_unref (c1);
1234 c1 = gst_caps_from_string ("video/x-raw");
1235 f1 = gst_caps_get_features (c1, 0);
1236 f2 = gst_caps_features_new ("memory:dmabuf", NULL);
1237 gst_caps_set_features (c1, 0, f2);
1239 gst_caps_unref (c1);
1244 GST_START_TEST (test_special_caps)
1248 caps = gst_caps_new_any ();
1249 fail_unless (gst_caps_is_any (caps));
1250 fail_unless (gst_caps_is_any (caps) == TRUE);
1251 fail_if (gst_caps_is_empty (caps));
1252 fail_unless (gst_caps_is_empty (caps) == FALSE);
1253 gst_caps_unref (caps);
1255 caps = gst_caps_new_empty ();
1256 fail_if (gst_caps_is_any (caps));
1257 fail_unless (gst_caps_is_any (caps) == FALSE);
1258 fail_unless (gst_caps_is_empty (caps));
1259 fail_unless (gst_caps_is_empty (caps) == TRUE);
1260 gst_caps_unref (caps);
1266 foreach_append_function (GstCapsFeatures * features, GstStructure * structure,
1269 GstCaps *caps = user_data;
1271 gst_caps_append_structure_full (caps, gst_structure_copy (structure),
1272 features ? gst_caps_features_copy (features) : NULL);
1277 GST_START_TEST (test_foreach)
1279 GstCaps *caps, *caps2;
1282 gst_caps_from_string
1283 ("video/x-raw, format=I420; video/x-raw(foo:bar); video/x-h264");
1284 caps2 = gst_caps_new_empty ();
1285 fail_unless (gst_caps_foreach (caps, foreach_append_function, caps2));
1286 fail_unless (gst_caps_is_strictly_equal (caps, caps2));
1287 gst_caps_unref (caps);
1288 gst_caps_unref (caps2);
1290 caps = gst_caps_new_empty ();
1291 caps2 = gst_caps_new_empty ();
1292 fail_unless (gst_caps_foreach (caps, foreach_append_function, caps2));
1293 fail_unless (gst_caps_is_strictly_equal (caps, caps2));
1294 gst_caps_unref (caps);
1295 gst_caps_unref (caps2);
1301 map_function (GstCapsFeatures * features, GstStructure * structure,
1304 /* Remove caps features if there are any, otherwise add some dummy */
1305 if (gst_caps_features_contains (features, "foo:bar")) {
1306 gst_caps_features_remove (features, "foo:bar");
1308 gst_caps_features_add (features, "foo:bar");
1309 gst_caps_features_remove (features, GST_CAPS_FEATURE_MEMORY_SYSTEM_MEMORY);
1312 /* Set some dummy integer in the structure */
1313 gst_structure_set (structure, "foo", G_TYPE_INT, 123, NULL);
1318 GST_START_TEST (test_map_in_place)
1320 GstCaps *caps, *caps2;
1323 gst_caps_from_string
1324 ("video/x-raw, format=I420; video/x-raw(foo:bar); video/x-h264");
1326 gst_caps_from_string
1327 ("video/x-raw(foo:bar), foo=(int)123, format=I420; video/x-raw, foo=(int)123; video/x-h264(foo:bar), foo=(int)123");
1328 fail_unless (gst_caps_map_in_place (caps, map_function, NULL));
1329 fail_unless (gst_caps_is_strictly_equal (caps, caps2));
1330 gst_caps_unref (caps);
1331 gst_caps_unref (caps2);
1333 caps = gst_caps_new_empty ();
1334 caps2 = gst_caps_new_empty ();
1335 fail_unless (gst_caps_map_in_place (caps, map_function, NULL));
1336 fail_unless (gst_caps_is_strictly_equal (caps, caps2));
1337 gst_caps_unref (caps);
1338 gst_caps_unref (caps2);
1344 filter_map_function (GstCapsFeatures * features, GstStructure * structure,
1347 if (!gst_structure_has_name (structure, "video/x-raw"))
1350 if (!gst_caps_features_contains (features, "foo:bar"))
1353 /* Set some dummy integer in the structure */
1354 gst_structure_set (structure, "foo", G_TYPE_INT, 123, NULL);
1359 GST_START_TEST (test_filter_and_map_in_place)
1361 GstCaps *caps, *caps2;
1364 gst_caps_from_string
1365 ("video/x-raw, format=I420; video/x-raw(foo:bar); video/x-h264");
1366 caps2 = gst_caps_from_string ("video/x-raw(foo:bar), foo=(int)123");
1367 gst_caps_filter_and_map_in_place (caps, filter_map_function, NULL);
1368 fail_unless (gst_caps_is_strictly_equal (caps, caps2));
1369 gst_caps_unref (caps);
1370 gst_caps_unref (caps2);
1372 caps = gst_caps_from_string ("video/x-raw, format=I420; video/x-h264");
1373 caps2 = gst_caps_new_empty ();
1374 gst_caps_filter_and_map_in_place (caps, filter_map_function, NULL);
1375 fail_unless (gst_caps_is_strictly_equal (caps, caps2));
1376 gst_caps_unref (caps);
1377 gst_caps_unref (caps2);
1379 caps = gst_caps_new_empty ();
1380 caps2 = gst_caps_new_empty ();
1381 gst_caps_filter_and_map_in_place (caps, filter_map_function, NULL);
1382 fail_unless (gst_caps_is_strictly_equal (caps, caps2));
1383 gst_caps_unref (caps);
1384 gst_caps_unref (caps2);
1390 gst_caps_suite (void)
1392 Suite *s = suite_create ("GstCaps");
1393 TCase *tc_chain = tcase_create ("operations");
1395 suite_add_tcase (s, tc_chain);
1396 tcase_add_test (tc_chain, test_from_string);
1397 tcase_add_test (tc_chain, test_double_append);
1398 tcase_add_test (tc_chain, test_mutability);
1399 tcase_add_test (tc_chain, test_static_caps);
1400 tcase_add_test (tc_chain, test_simplify);
1401 tcase_add_test (tc_chain, test_truncate);
1402 tcase_add_test (tc_chain, test_subset);
1403 tcase_add_test (tc_chain, test_subset_duplication);
1404 tcase_add_test (tc_chain, test_merge_fundamental);
1405 tcase_add_test (tc_chain, test_merge_same);
1406 tcase_add_test (tc_chain, test_merge_subset);
1407 tcase_add_test (tc_chain, test_intersect);
1408 tcase_add_test (tc_chain, test_intersect2);
1409 tcase_add_test (tc_chain, test_intersect_list_duplicate);
1410 tcase_add_test (tc_chain, test_intersect_zigzag);
1411 tcase_add_test (tc_chain, test_intersect_first);
1412 tcase_add_test (tc_chain, test_intersect_first2);
1413 tcase_add_test (tc_chain, test_intersect_duplication);
1414 tcase_add_test (tc_chain, test_intersect_flagset);
1415 tcase_add_test (tc_chain, test_union);
1416 tcase_add_test (tc_chain, test_normalize);
1417 tcase_add_test (tc_chain, test_broken);
1418 tcase_add_test (tc_chain, test_features);
1419 tcase_add_test (tc_chain, test_special_caps);
1420 tcase_add_test (tc_chain, test_foreach);
1421 tcase_add_test (tc_chain, test_map_in_place);
1422 tcase_add_test (tc_chain, test_filter_and_map_in_place);
1427 GST_CHECK_MAIN (gst_caps);