2 * Copyright (C) 2005 Andy Wingo <wingo@pobox.com>
3 * Copyright (C) <2005> Thomas Vander Stichele <thomas at apestaart dot org>
5 * gstcaps.c: Unit test for GstCaps
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
24 #include <gst/check/gstcheck.h>
25 #include <gst/gstcaps.h>
28 GST_START_TEST (test_from_string)
35 for (i = 0; i < G_N_ELEMENTS (caps_list); i++) {
36 caps = gst_caps_from_string (caps_list[i]);
37 fail_if (caps == NULL,
38 "Could not create caps from string %s\n", caps_list[i]);
39 to_str = gst_caps_to_string (caps);
40 fail_if (to_str == NULL,
41 "Could not convert caps back to string %s\n", caps_list[i]);
42 caps2 = gst_caps_from_string (caps_list[i]);
43 fail_if (caps2 == NULL, "Could not create caps from string %s\n", to_str);
45 fail_unless (gst_caps_is_equal (caps, caps));
46 fail_unless (gst_caps_is_equal (caps, caps2));
48 gst_caps_unref (caps);
49 gst_caps_unref (caps2);
56 GST_START_TEST (test_double_append)
61 c1 = gst_caps_new_any ();
62 s1 = gst_structure_from_string ("audio/x-raw,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");
108 caps1 = gst_static_caps_get (&scaps);
109 fail_unless (caps1 != NULL);
110 /* 1 refcount core, one from us */
111 fail_unless (GST_CAPS_REFCOUNT (caps1) == 2);
113 /* caps should be the same */
114 caps2 = gst_static_caps_get (&scaps);
115 fail_unless (caps2 != NULL);
116 /* 1 refcount core, two from us */
117 fail_unless (GST_CAPS_REFCOUNT (caps1) == 3);
118 /* caps must be equal */
119 fail_unless (caps1 == caps2);
121 gst_caps_unref (caps1);
122 gst_caps_unref (caps2);
127 static const gchar non_simple_caps_string[] =
128 "video/x-raw, format=(string)I420, framerate=(fraction)[ 1/100, 100 ], "
129 "width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ]; video/x-raw, "
130 "format=(string)YUY2, framerate=(fraction)[ 1/100, 100 ], width=(int)[ 16, 4096 ], "
131 "height=(int)[ 16, 4096 ]; video/x-raw, format=(string)RGB8_PALETTED, "
132 "framerate=(fraction)[ 1/100, 100 ], width=(int)[ 16, 4096 ], "
133 "height=(int)[ 16, 4096 ]; video/x-raw, "
134 "format=(string){ I420, YUY2, YV12 }, width=(int)[ 16, 4096 ], "
135 "height=(int)[ 16, 4096 ], framerate=(fraction)[ 1/100, 100 ]";
138 check_string_list (const GValue * format_value)
140 const GValue *string_value;
141 gboolean got_rgb8 = FALSE;
142 gboolean got_yv12 = FALSE;
143 gboolean got_i420 = FALSE;
144 gboolean got_yuy2 = FALSE;
147 string_value = gst_value_list_get_value (format_value, 0);
148 fail_unless (string_value != NULL);
149 fail_unless (G_VALUE_HOLDS_STRING (string_value));
150 string = g_value_get_string (string_value);
151 fail_unless (string != NULL);
152 got_rgb8 = got_rgb8 || (g_str_equal (string, "RGB8_PALETTED"));
153 got_i420 = got_i420 || (g_str_equal (string, "I420"));
154 got_yuy2 = got_yuy2 || (g_str_equal (string, "YUY2"));
155 got_yv12 = got_yv12 || (g_str_equal (string, "YV12"));
157 string_value = gst_value_list_get_value (format_value, 1);
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, 2);
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, 3);
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 return (got_rgb8 && got_i420 && got_yuy2 && got_yv12);
190 GST_START_TEST (test_simplify)
195 caps = gst_caps_from_string (non_simple_caps_string);
196 fail_unless (caps != NULL,
197 "gst_caps_from_string (non_simple_caps_string) failed");
199 caps = gst_caps_do_simplify (caps);
200 fail_unless (caps != NULL, "gst_caps_do_simplify() should have worked");
202 /* check simplified caps, should be:
204 * video/x-raw, format=(string){ RGB8_PALETTED, YV12, YUY2, I420 },
205 * width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ],
206 * framerate=(fraction)[ 1/100, 100 ]
208 GST_DEBUG ("simplyfied %" GST_PTR_FORMAT, caps);
209 fail_unless (gst_caps_get_size (caps) == 1);
210 s1 = gst_caps_get_structure (caps, 0);
211 fail_unless (s1 != NULL);
213 fail_unless (gst_structure_has_name (s1, "video/x-raw"));
215 const GValue *framerate_value;
216 const GValue *format_value;
217 const GValue *width_value;
218 const GValue *height_value;
219 const GValue *val_fps;
220 GValue test_fps = { 0, };
221 gint min_width, max_width;
222 gint min_height, max_height;
224 format_value = gst_structure_get_value (s1, "format");
225 fail_unless (format_value != NULL);
226 fail_unless (GST_VALUE_HOLDS_LIST (format_value));
227 fail_unless (gst_value_list_get_size (format_value) == 4);
228 fail_unless (check_string_list (format_value) == TRUE);
230 g_value_init (&test_fps, GST_TYPE_FRACTION);
231 framerate_value = gst_structure_get_value (s1, "framerate");
232 fail_unless (framerate_value != NULL);
233 fail_unless (GST_VALUE_HOLDS_FRACTION_RANGE (framerate_value));
235 val_fps = gst_value_get_fraction_range_min (framerate_value);
236 gst_value_set_fraction (&test_fps, 1, 100);
237 fail_unless (gst_value_compare (&test_fps, val_fps) == GST_VALUE_EQUAL);
239 val_fps = gst_value_get_fraction_range_max (framerate_value);
240 gst_value_set_fraction (&test_fps, 100, 1);
241 fail_unless (gst_value_compare (&test_fps, val_fps) == GST_VALUE_EQUAL);
243 g_value_unset (&test_fps);
245 width_value = gst_structure_get_value (s1, "width");
246 fail_unless (width_value != NULL);
247 fail_unless (GST_VALUE_HOLDS_INT_RANGE (width_value));
248 min_width = gst_value_get_int_range_min (width_value);
249 max_width = gst_value_get_int_range_max (width_value);
250 fail_unless (min_width == 16 && max_width == 4096);
252 height_value = gst_structure_get_value (s1, "height");
253 fail_unless (height_value != NULL);
254 fail_unless (GST_VALUE_HOLDS_INT_RANGE (height_value));
255 min_height = gst_value_get_int_range_min (height_value);
256 max_height = gst_value_get_int_range_max (height_value);
257 fail_unless (min_height == 16 && max_height == 4096);
260 gst_caps_unref (caps);
265 GST_START_TEST (test_truncate)
269 caps = gst_caps_from_string (non_simple_caps_string);
270 fail_unless (caps != NULL,
271 "gst_caps_from_string (non_simple_caps_string) failed");
272 fail_unless_equals_int (gst_caps_get_size (caps), 4);
273 caps = gst_caps_truncate (caps);
274 fail_unless_equals_int (gst_caps_get_size (caps), 1);
275 gst_caps_unref (caps);
280 GST_START_TEST (test_subset)
284 c1 = gst_caps_from_string ("video/x-raw; video/x-raw");
285 c2 = gst_caps_from_string ("video/x-raw, format=(string)YUY2");
286 fail_unless (gst_caps_is_subset (c2, c1));
287 fail_if (gst_caps_is_subset (c1, c2));
291 c1 = gst_caps_from_string
292 ("audio/x-raw, channels=(int)[ 1, 2 ], rate=(int)44100");
293 c2 = gst_caps_from_string ("audio/x-raw, channels=(int)1, rate=(int)44100");
294 fail_unless (gst_caps_is_subset (c2, c1));
295 fail_if (gst_caps_is_subset (c1, c2));
299 c1 = gst_caps_from_string ("audio/x-raw, channels=(int) {1}");
300 c2 = gst_caps_from_string ("audio/x-raw, channels=(int)1");
301 fail_unless (gst_caps_is_subset (c2, c1));
302 fail_unless (gst_caps_is_subset (c1, c2));
303 fail_unless (gst_caps_is_equal (c1, c2));
307 c1 = gst_caps_from_string
308 ("audio/x-raw, rate=(int)44100, channels=(int)3, format=(string)U16_LE");
309 c2 = gst_caps_from_string
310 ("audio/x-raw, rate=(int)[ 1, 2147483647 ], channels=(int)[ 1, 2147483647 ], format=(string){ S16_LE, U16_LE }");
311 fail_unless (gst_caps_is_subset (c1, c2));
312 fail_if (gst_caps_is_subset (c2, c1));
319 GST_START_TEST (test_merge_fundamental)
323 /* ANY + specific = ANY */
324 c1 = gst_caps_from_string ("audio/x-raw,rate=44100");
325 c2 = gst_caps_new_any ();
326 c2 = gst_caps_merge (c2, c1);
327 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
328 fail_unless (gst_caps_get_size (c2) == 0, NULL);
329 fail_unless (gst_caps_is_any (c2), NULL);
332 /* specific + ANY = ANY */
333 c2 = gst_caps_from_string ("audio/x-raw,rate=44100");
334 c1 = gst_caps_new_any ();
335 c2 = gst_caps_merge (c2, c1);
336 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
337 fail_unless (gst_caps_get_size (c2) == 0, NULL);
338 fail_unless (gst_caps_is_any (c2), NULL);
341 /* EMPTY + specific = specific */
342 c1 = gst_caps_from_string ("audio/x-raw,rate=44100");
343 c2 = gst_caps_new_empty ();
344 c2 = gst_caps_merge (c2, c1);
345 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
346 fail_unless (gst_caps_get_size (c2) == 1, NULL);
347 fail_if (gst_caps_is_empty (c2), NULL);
350 /* specific + EMPTY = specific */
351 c2 = gst_caps_from_string ("audio/x-raw,rate=44100");
352 c1 = gst_caps_new_empty ();
353 c2 = gst_caps_merge (c2, c1);
354 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
355 fail_unless (gst_caps_get_size (c2) == 1, NULL);
356 fail_if (gst_caps_is_empty (c2), NULL);
362 GST_START_TEST (test_merge_same)
364 GstCaps *c1, *c2, *test;
366 /* this is the same */
367 c1 = gst_caps_from_string ("audio/x-raw,rate=44100,channels=1");
368 c2 = gst_caps_from_string ("audio/x-raw,rate=44100,channels=1");
369 c2 = gst_caps_merge (c2, c1);
370 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
371 fail_unless (gst_caps_get_size (c2) == 1, NULL);
372 test = gst_caps_from_string ("audio/x-raw,rate=44100,channels=1");
373 fail_unless (gst_caps_is_equal (c2, test));
374 gst_caps_unref (test);
378 c1 = gst_caps_from_string ("audio/x-raw,rate=44100,channels=1");
379 c2 = gst_caps_from_string ("audio/x-raw,channels=1,rate=44100");
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) == 1, NULL);
385 c1 = gst_caps_from_string ("video/x-foo, data=(buffer)AA");
386 c2 = gst_caps_from_string ("video/x-foo, data=(buffer)AABB");
387 c2 = gst_caps_merge (c2, c1);
388 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
389 fail_unless (gst_caps_get_size (c2) == 2, NULL);
392 c1 = gst_caps_from_string ("video/x-foo, data=(buffer)AABB");
393 c2 = gst_caps_from_string ("video/x-foo, data=(buffer)AA");
394 c2 = gst_caps_merge (c2, c1);
395 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
396 fail_unless (gst_caps_get_size (c2) == 2, NULL);
399 c1 = gst_caps_from_string ("video/x-foo, data=(buffer)AA");
400 c2 = gst_caps_from_string ("video/x-foo, data=(buffer)AA");
401 c2 = gst_caps_merge (c2, c1);
402 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
403 fail_unless (gst_caps_get_size (c2) == 1, NULL);
406 c1 = gst_caps_from_string ("video/x-foo, data=(buffer)AA");
407 c2 = gst_caps_from_string ("video/x-bar, data=(buffer)AA");
408 c2 = gst_caps_merge (c2, c1);
409 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
410 fail_unless (gst_caps_get_size (c2) == 2, NULL);
416 GST_START_TEST (test_merge_subset)
418 GstCaps *c1, *c2, *test;
420 /* the 2nd is already covered */
421 c2 = gst_caps_from_string ("audio/x-raw,channels=[1,2]");
422 c1 = gst_caps_from_string ("audio/x-raw,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,channels=[1,2]");
427 fail_unless (gst_caps_is_equal (c2, test));
429 gst_caps_unref (test);
432 c2 = gst_caps_from_string ("audio/x-raw,channels=1,rate=44100");
433 c1 = gst_caps_from_string ("audio/x-raw,channels=[1,2],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) == 2, NULL);
437 test = gst_caps_from_string ("audio/x-raw,channels=[1,2],rate=44100");
438 fail_unless (gst_caps_is_equal (c2, test));
440 gst_caps_unref (test);
442 /* second one was already contained in the first one */
443 c2 = gst_caps_from_string ("audio/x-raw,channels=[1,3]");
444 c1 = gst_caps_from_string ("audio/x-raw,channels=[1,2]");
445 c2 = gst_caps_merge (c2, c1);
446 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
447 fail_unless (gst_caps_get_size (c2) == 1, NULL);
448 test = gst_caps_from_string ("audio/x-raw,channels=[1,3]");
449 fail_unless (gst_caps_is_equal (c2, test));
451 gst_caps_unref (test);
453 /* second one was already contained in the first one */
454 c2 = gst_caps_from_string ("audio/x-raw,channels=[1,4]");
455 c1 = gst_caps_from_string ("audio/x-raw,channels=[1,2]");
456 c2 = gst_caps_merge (c2, c1);
457 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
458 fail_unless (gst_caps_get_size (c2) == 1, NULL);
459 test = gst_caps_from_string ("audio/x-raw,channels=[1,4]");
460 fail_unless (gst_caps_is_equal (c2, test));
462 gst_caps_unref (test);
464 /* second one was already contained in the first one */
465 c2 = gst_caps_from_string ("audio/x-raw,channels=[1,4]");
466 c1 = gst_caps_from_string ("audio/x-raw,channels=[2,4]");
467 c2 = gst_caps_merge (c2, c1);
468 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
469 fail_unless (gst_caps_get_size (c2) == 1, NULL);
470 test = gst_caps_from_string ("audio/x-raw,channels=[1,4]");
471 fail_unless (gst_caps_is_equal (c2, test));
473 gst_caps_unref (test);
475 /* second one was already contained in the first one */
476 c2 = gst_caps_from_string ("audio/x-raw,channels=[1,4]");
477 c1 = gst_caps_from_string ("audio/x-raw,channels=[2,3]");
478 c2 = gst_caps_merge (c2, c1);
479 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
480 fail_unless (gst_caps_get_size (c2) == 1, NULL);
481 test = gst_caps_from_string ("audio/x-raw,channels=[1,4]");
482 fail_unless (gst_caps_is_equal (c2, test));
484 gst_caps_unref (test);
486 /* these caps cannot be merged */
487 c2 = gst_caps_from_string ("audio/x-raw,channels=[2,3]");
488 c1 = gst_caps_from_string ("audio/x-raw,channels=[1,4]");
489 c2 = gst_caps_merge (c2, c1);
490 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
491 fail_unless (gst_caps_get_size (c2) == 2, NULL);
494 ("audio/x-raw,channels=[2,3];audio/x-raw,channels=[1,4]");
495 fail_unless (gst_caps_is_equal (c2, test));
497 gst_caps_unref (test);
499 /* these caps cannot be merged */
500 c2 = gst_caps_from_string ("audio/x-raw,channels=[1,2]");
501 c1 = gst_caps_from_string ("audio/x-raw,channels=[1,3]");
502 c2 = gst_caps_merge (c2, c1);
503 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
504 fail_unless (gst_caps_get_size (c2) == 2, NULL);
507 ("audio/x-raw,channels=[1,2];audio/x-raw,channels=[1,3]");
508 fail_unless (gst_caps_is_equal (c2, test));
510 gst_caps_unref (test);
512 c2 = gst_caps_from_string ("audio/x-raw,channels={1,2}");
513 c1 = gst_caps_from_string ("audio/x-raw,channels={1,2,3,4}");
514 c2 = gst_caps_merge (c2, c1);
515 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
516 fail_unless (gst_caps_get_size (c2) == 2, NULL);
517 test = gst_caps_from_string ("audio/x-raw,channels={1,2};"
518 "audio/x-raw,channels={1,2,3,4}");
519 fail_unless (gst_caps_is_equal (c2, test));
521 gst_caps_unref (test);
523 c2 = gst_caps_from_string ("audio/x-raw,channels={1,2}");
524 c1 = gst_caps_from_string ("audio/x-raw,channels={1,3}");
525 c2 = gst_caps_merge (c2, c1);
526 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
527 fail_unless (gst_caps_get_size (c2) == 2, NULL);
528 test = gst_caps_from_string ("audio/x-raw,channels={1,2};"
529 "audio/x-raw,channels={1,3}");
530 fail_unless (gst_caps_is_equal (c2, test));
532 gst_caps_unref (test);
534 c2 = gst_caps_from_string ("video/x-raw, framerate=(fraction){ 15/2, 5/1 }");
535 c1 = gst_caps_from_string ("video/x-raw, framerate=(fraction){ 15/1, 5/1 }");
536 test = gst_caps_copy (c1);
537 c2 = gst_caps_merge (c2, c1);
538 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
539 fail_unless (gst_caps_is_subset (test, c2));
540 gst_caps_unref (test);
543 c2 = gst_caps_from_string ("audio/x-raw");
544 c1 = gst_caps_from_string ("audio/x-raw,channels=1");
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) == 1, NULL);
548 test = gst_caps_from_string ("audio/x-raw");
549 fail_unless (gst_caps_is_equal (c2, test));
551 gst_caps_unref (test);
553 c2 = gst_caps_from_string ("audio/x-raw,channels=1");
554 c1 = gst_caps_from_string ("audio/x-raw");
555 c2 = gst_caps_merge (c2, c1);
556 GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
557 fail_unless (gst_caps_get_size (c2) == 2, NULL);
558 test = gst_caps_from_string ("audio/x-raw,channels=1; audio/x-raw");
559 fail_unless (gst_caps_is_equal (c2, test));
561 gst_caps_unref (test);
566 GST_START_TEST (test_intersect)
569 GstCaps *c1, *c2, *ci1, *ci2;
571 /* field not specified = any value possible, so the intersection
572 * should keep fields which are only part of one set of caps */
573 c2 = gst_caps_from_string ("video/x-raw,format=(string)I420,width=20");
574 c1 = gst_caps_from_string ("video/x-raw,format=(string)I420");
576 ci1 = gst_caps_intersect (c2, c1);
577 GST_DEBUG ("intersected: %" GST_PTR_FORMAT, ci1);
578 fail_unless (gst_caps_get_size (ci1) == 1, NULL);
579 s = gst_caps_get_structure (ci1, 0);
580 fail_unless (gst_structure_has_name (s, "video/x-raw"));
581 fail_unless (gst_structure_get_value (s, "format") != NULL);
582 fail_unless (gst_structure_get_value (s, "width") != NULL);
584 /* with changed order */
585 ci2 = gst_caps_intersect (c1, c2);
586 GST_DEBUG ("intersected: %" GST_PTR_FORMAT, ci2);
587 fail_unless (gst_caps_get_size (ci2) == 1, NULL);
588 s = gst_caps_get_structure (ci2, 0);
589 fail_unless (gst_structure_has_name (s, "video/x-raw"));
590 fail_unless (gst_structure_get_value (s, "format") != NULL);
591 fail_unless (gst_structure_get_value (s, "width") != NULL);
593 fail_unless (gst_caps_is_equal (ci1, ci2));
595 gst_caps_unref (ci1);
596 gst_caps_unref (ci2);
603 c2 = gst_caps_from_string ("video/x-raw,format=(string)I420,width=20");
604 c1 = gst_caps_from_string ("video/x-raw,format=(string)I420,width=30");
606 ci1 = gst_caps_intersect (c2, c1);
607 GST_DEBUG ("intersected: %" GST_PTR_FORMAT, ci1);
608 fail_unless (gst_caps_is_empty (ci1), NULL);
610 /* with changed order */
611 ci2 = gst_caps_intersect (c1, c2);
612 GST_DEBUG ("intersected: %" GST_PTR_FORMAT, ci2);
613 fail_unless (gst_caps_is_empty (ci2), NULL);
615 fail_unless (gst_caps_is_equal (ci1, ci2));
617 gst_caps_unref (ci1);
618 gst_caps_unref (ci2);
625 c2 = gst_caps_from_string ("video/x-raw,format=(string)I420,width=20");
626 c1 = gst_caps_from_string ("video/x-raw2,format=(string)I420,width=20");
628 ci1 = gst_caps_intersect (c2, c1);
629 GST_DEBUG ("intersected: %" GST_PTR_FORMAT, ci1);
630 fail_unless (gst_caps_is_empty (ci1), NULL);
632 /* with changed order */
633 ci2 = gst_caps_intersect (c1, c2);
634 GST_DEBUG ("intersected: %" GST_PTR_FORMAT, ci2);
635 fail_unless (gst_caps_is_empty (ci2), NULL);
637 fail_unless (gst_caps_is_equal (ci1, ci2));
639 gst_caps_unref (ci1);
640 gst_caps_unref (ci2);
647 c2 = gst_caps_from_string ("video/x-raw,format=(string)I420,width=20");
648 c1 = gst_caps_from_string ("video/x-raw,format=(string)I420,height=30");
650 ci1 = gst_caps_intersect (c2, c1);
651 GST_DEBUG ("intersected: %" GST_PTR_FORMAT, ci1);
652 fail_unless (gst_caps_get_size (ci1) == 1, NULL);
653 s = gst_caps_get_structure (ci1, 0);
654 fail_unless (gst_structure_has_name (s, "video/x-raw"));
655 fail_unless (gst_structure_get_value (s, "format") != NULL);
656 fail_unless (gst_structure_get_value (s, "width") != NULL);
657 fail_unless (gst_structure_get_value (s, "height") != NULL);
659 /* with changed order */
660 ci2 = gst_caps_intersect (c1, c2);
661 GST_DEBUG ("intersected: %" GST_PTR_FORMAT, ci2);
662 fail_unless (gst_caps_get_size (ci2) == 1, NULL);
663 s = gst_caps_get_structure (ci2, 0);
664 fail_unless (gst_structure_has_name (s, "video/x-raw"));
665 fail_unless (gst_structure_get_value (s, "format") != NULL);
666 fail_unless (gst_structure_get_value (s, "height") != NULL);
667 fail_unless (gst_structure_get_value (s, "width") != NULL);
669 fail_unless (gst_caps_is_equal (ci1, ci2));
671 gst_caps_unref (ci1);
672 gst_caps_unref (ci2);
680 GST_START_TEST (test_intersect2)
682 GstCaps *caps1, *caps2, *icaps;
684 /* tests array subtraction */
685 caps1 = gst_caps_from_string ("audio/x-raw, "
686 "channel-positions=(int)< "
687 "{ 1, 2, 3, 4, 5, 6 }, "
688 "{ 1, 2, 3, 4, 5, 6 }, "
689 "{ 1, 2, 3, 4, 5, 6 }, "
690 "{ 1, 2, 3, 4, 5, 6 }, "
691 "{ 1, 2, 3, 4, 5, 6 }, " "{ 1, 2, 3, 4, 5, 6 }>");
692 caps2 = gst_caps_from_string ("audio/x-raw, "
693 "channel-positions=(int)< 1, 2, 3, 4, 5, 6 >");
694 icaps = gst_caps_intersect (caps1, caps2);
695 GST_LOG ("intersected caps: %" GST_PTR_FORMAT, icaps);
696 fail_if (gst_caps_is_empty (icaps));
697 fail_unless (gst_caps_is_equal (icaps, caps2));
698 gst_caps_unref (caps1);
699 gst_caps_unref (caps2);
700 gst_caps_unref (icaps);
704 caps1 = gst_caps_from_string ("some/type, foo=(int)< { 1, 2 }, { 3, 4} >");
705 caps2 = gst_caps_from_string ("some/type, foo=(int)< 1, 3 >");
706 icaps = gst_caps_intersect (caps1, caps2);
707 GST_LOG ("intersected caps: %" GST_PTR_FORMAT, icaps);
708 fail_if (gst_caps_is_empty (icaps));
709 fail_unless (gst_caps_is_equal (icaps, caps2));
710 gst_caps_unref (caps1);
711 gst_caps_unref (caps2);
712 gst_caps_unref (icaps);
718 GST_START_TEST (test_intersect_zigzag)
720 GstCaps *caps1, *caps2, *icaps, *result;
722 /* tests if caps order is maintained */
723 caps1 = gst_caps_from_string ("format/A; format/B; format/C; format/D");
724 caps2 = gst_caps_from_string ("format/D; format/A; format/B; format/C");
726 icaps = gst_caps_intersect_full (caps1, caps2, GST_CAPS_INTERSECT_ZIG_ZAG);
727 result = gst_caps_from_string ("format/B; format/A; format/D; format/C");
728 GST_LOG ("intersected caps: %" GST_PTR_FORMAT, icaps);
729 fail_if (gst_caps_is_empty (icaps));
730 fail_unless (gst_caps_is_equal (icaps, result));
731 gst_caps_unref (icaps);
732 gst_caps_unref (result);
734 icaps = gst_caps_intersect_full (caps2, caps1, GST_CAPS_INTERSECT_FIRST);
735 result = gst_caps_from_string ("format/A; format/B; format/D; format/C");
736 GST_LOG ("intersected caps: %" GST_PTR_FORMAT, icaps);
737 fail_if (gst_caps_is_empty (icaps));
738 fail_unless (gst_caps_is_equal (icaps, result));
739 gst_caps_unref (icaps);
740 gst_caps_unref (result);
742 gst_caps_unref (caps1);
743 gst_caps_unref (caps2);
749 GST_START_TEST (test_intersect_first)
751 GstCaps *caps1, *caps2, *icaps, *result;
753 /* tests if caps order is maintained */
754 caps1 = gst_caps_from_string ("format/A; format/B; format/C; format/D");
755 caps2 = gst_caps_from_string ("format/C; format/D; format/A");
756 icaps = gst_caps_intersect_full (caps1, caps2, GST_CAPS_INTERSECT_FIRST);
757 result = gst_caps_from_string ("format/A; format/C; format/D");
758 GST_LOG ("intersected caps: %" GST_PTR_FORMAT, icaps);
759 fail_if (gst_caps_is_empty (icaps));
760 fail_unless (gst_caps_is_equal (icaps, result));
761 gst_caps_unref (caps1);
762 gst_caps_unref (caps2);
763 gst_caps_unref (icaps);
764 gst_caps_unref (result);
770 GST_START_TEST (test_intersect_first2)
772 GstCaps *caps1, *caps2, *icaps, *result;
774 /* tests if caps order is maintained */
775 caps1 = gst_caps_from_string ("format/A; format/B; format/C; format/D");
776 caps2 = gst_caps_from_string ("format/D; format/A; format/B; format/C");
778 icaps = gst_caps_intersect_full (caps1, caps2, GST_CAPS_INTERSECT_FIRST);
779 result = gst_caps_from_string ("format/A; format/B; format/C; format/D");
780 GST_LOG ("intersected caps: %" GST_PTR_FORMAT, icaps);
781 fail_if (gst_caps_is_empty (icaps));
782 fail_unless (gst_caps_is_equal (icaps, result));
783 gst_caps_unref (icaps);
784 gst_caps_unref (result);
786 icaps = gst_caps_intersect_full (caps2, caps1, GST_CAPS_INTERSECT_FIRST);
787 result = gst_caps_from_string ("format/D; format/A; format/B; format/C");
788 GST_LOG ("intersected caps: %" GST_PTR_FORMAT, icaps);
789 fail_if (gst_caps_is_empty (icaps));
790 fail_unless (gst_caps_is_equal (icaps, result));
791 gst_caps_unref (icaps);
792 gst_caps_unref (result);
794 gst_caps_unref (caps1);
795 gst_caps_unref (caps2);
800 GST_START_TEST (test_intersect_duplication)
802 GstCaps *c1, *c2, *test;
804 c1 = gst_caps_from_string
805 ("audio/x-raw, format=(string)S16_LE, rate=(int)[ 1, 2147483647 ], channels=(int)[ 1, 2 ]");
806 c2 = gst_caps_from_string
807 ("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 ]");
809 test = gst_caps_intersect_full (c1, c2, GST_CAPS_INTERSECT_FIRST);
810 fail_unless_equals_int (gst_caps_get_size (test), 1);
811 fail_unless (gst_caps_is_equal (c1, test));
814 gst_caps_unref (test);
820 _caps_is_fixed_foreach (GQuark field_id, const GValue * value, gpointer unused)
822 return gst_value_is_fixed (value);
826 GST_START_TEST (test_normalize)
828 GstCaps *in, *norm, *out;
831 in = gst_caps_from_string ("some/type, foo=(int){ 1 , 2 }");
832 out = gst_caps_from_string ("some/type, foo=(int) 1; some/type, foo=(int) 2");
833 norm = gst_caps_normalize (in);
834 fail_if (gst_caps_is_empty (norm));
835 fail_unless (gst_caps_is_equal (norm, out));
836 for (i = 0; i < gst_caps_get_size (norm); i++) {
837 GstStructure *st = gst_caps_get_structure (norm, i);
838 /* Make sure all fields of all structures are fixed */
839 fail_unless (gst_structure_foreach (st, _caps_is_fixed_foreach, NULL));
843 gst_caps_unref (out);
844 gst_caps_unref (norm);
846 in = gst_caps_from_string
847 ("some/type, foo=(int){ 1 , 2 }, bar=(int){ 3, 4 }");
850 ("some/type, foo=(int) 1, bar=(int) 3; some/type, foo=(int) 2, bar=(int) 3;"
851 "some/type, foo=(int) 1, bar=(int) 4; some/type, foo=(int) 2, bar=(int) 4;");
852 norm = gst_caps_normalize (in);
853 fail_if (gst_caps_is_empty (norm));
854 fail_unless (gst_caps_is_equal (norm, out));
855 for (i = 0; i < gst_caps_get_size (norm); i++) {
856 GstStructure *st = gst_caps_get_structure (norm, i);
857 /* Make sure all fields of all structures are fixed */
858 fail_unless (gst_structure_foreach (st, _caps_is_fixed_foreach, NULL));
862 gst_caps_unref (out);
863 gst_caps_unref (norm);
865 in = gst_caps_from_string
866 ("some/type, foo=(string){ 1 , 2 }, bar=(string) { 3 }");
869 ("some/type, foo=(string) 1, bar=(string) 3; some/type, foo=(string) 2, bar=(string) 3");
870 norm = gst_caps_normalize (in);
871 fail_if (gst_caps_is_empty (norm));
872 fail_unless (gst_caps_is_equal (norm, out));
873 for (i = 0; i < gst_caps_get_size (norm); i++) {
874 GstStructure *st = gst_caps_get_structure (norm, i);
875 /* Make sure all fields of all structures are fixed */
876 fail_unless (gst_structure_foreach (st, _caps_is_fixed_foreach, NULL));
880 gst_caps_unref (out);
881 gst_caps_unref (norm);
886 GST_START_TEST (test_broken)
890 /* NULL is not valid for media_type */
891 ASSERT_CRITICAL (c1 =
892 gst_caps_new_simple (NULL, "field", G_TYPE_INT, 1, NULL));
895 #ifndef G_DISABLE_CHECKS
896 /* such a name is not valid, see gst_structure_validate_name() */
897 ASSERT_CRITICAL (c1 =
898 gst_caps_new_simple ("1#@abc", "field", G_TYPE_INT, 1, NULL));
907 gst_caps_suite (void)
909 Suite *s = suite_create ("GstCaps");
910 TCase *tc_chain = tcase_create ("operations");
912 suite_add_tcase (s, tc_chain);
913 tcase_add_test (tc_chain, test_from_string);
914 tcase_add_test (tc_chain, test_double_append);
915 tcase_add_test (tc_chain, test_mutability);
916 tcase_add_test (tc_chain, test_static_caps);
917 tcase_add_test (tc_chain, test_simplify);
918 tcase_add_test (tc_chain, test_truncate);
919 tcase_add_test (tc_chain, test_subset);
920 tcase_add_test (tc_chain, test_merge_fundamental);
921 tcase_add_test (tc_chain, test_merge_same);
922 tcase_add_test (tc_chain, test_merge_subset);
923 tcase_add_test (tc_chain, test_intersect);
924 tcase_add_test (tc_chain, test_intersect2);
925 tcase_add_test (tc_chain, test_intersect_zigzag);
926 tcase_add_test (tc_chain, test_intersect_first);
927 tcase_add_test (tc_chain, test_intersect_first2);
928 tcase_add_test (tc_chain, test_intersect_duplication);
929 tcase_add_test (tc_chain, test_normalize);
930 tcase_add_test (tc_chain, test_broken);
935 GST_CHECK_MAIN (gst_caps);