ca4d59b37f4340b4c6916c4cc812d81d069cf841
[platform/upstream/gstreamer.git] / tests / check / gst / gstcaps.c
1 /* GStreamer
2  * Copyright (C) 2005 Andy Wingo <wingo@pobox.com>
3  * Copyright (C) <2005> Thomas Vander Stichele <thomas at apestaart dot org>
4  *
5  * gstcaps.c: Unit test for GstCaps
6  *
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.
11  *
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.
16  *
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.
21  */
22
23
24 #include <gst/check/gstcheck.h>
25 #include <gst/gstcaps.h>
26 #include "capslist.h"
27
28 GST_START_TEST (test_from_string)
29 {
30   GstCaps *caps;
31   GstCaps *caps2;
32   gchar *to_str;
33   int i;
34
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);
44
45     fail_unless (gst_caps_is_equal (caps, caps));
46     fail_unless (gst_caps_is_equal (caps, caps2));
47
48     gst_caps_unref (caps);
49     gst_caps_unref (caps2);
50     g_free (to_str);
51   }
52 }
53
54 GST_END_TEST;
55
56 GST_START_TEST (test_double_append)
57 {
58   GstStructure *s1;
59   GstCaps *c1;
60
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));
65
66   gst_caps_unref (c1);
67 }
68
69 GST_END_TEST;
70
71 GST_START_TEST (test_mutability)
72 {
73   GstStructure *s1;
74   GstCaps *c1;
75   gint ret;
76
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);
82   gst_caps_ref (c1);
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);
89   gst_caps_unref (c1);
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);
96   gst_caps_unref (c1);
97 }
98
99 GST_END_TEST;
100
101 GST_START_TEST (test_static_caps)
102 {
103   static GstStaticCaps scaps = GST_STATIC_CAPS ("audio/x-raw,rate=44100");
104   GstCaps *caps1;
105   GstCaps *caps2;
106   static GstStaticCaps sany = GST_STATIC_CAPS_ANY;
107   static GstStaticCaps snone = GST_STATIC_CAPS_NONE;
108
109   /* caps creation */
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);
114
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);
122
123   gst_caps_unref (caps1);
124   gst_caps_unref (caps2);
125
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);
133 }
134
135 GST_END_TEST;
136
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 ]";
146
147 static gboolean
148 check_string_list (const GValue * format_value)
149 {
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;
155   const gchar *string;
156
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"));
166
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"));
176
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"));
186
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"));
196
197   return (got_rgb8 && got_i420 && got_yuy2 && got_yv12);
198 }
199
200 GST_START_TEST (test_simplify)
201 {
202   GstStructure *s1;
203   GstCaps *caps;
204
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");
208
209   caps = gst_caps_simplify (caps);
210   fail_unless (caps != NULL, "gst_caps_simplify() should have worked");
211
212   /* check simplified caps, should be:
213    *
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 ]
217    */
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);
222
223   fail_unless (gst_structure_has_name (s1, "video/x-raw"));
224   {
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;
233
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);
239
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));
244
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);
248
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);
252
253     g_value_unset (&test_fps);
254
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);
261
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);
268   }
269
270   gst_caps_unref (caps);
271 }
272
273 GST_END_TEST;
274
275 GST_START_TEST (test_truncate)
276 {
277   GstCaps *caps;
278
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);
286 }
287
288 GST_END_TEST;
289
290 GST_START_TEST (test_subset)
291 {
292   GstCaps *c1, *c2;
293
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));
298   gst_caps_unref (c1);
299   gst_caps_unref (c2);
300
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));
306   gst_caps_unref (c1);
307   gst_caps_unref (c2);
308
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));
314   gst_caps_unref (c1);
315   gst_caps_unref (c2);
316
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));
323   gst_caps_unref (c1);
324   gst_caps_unref (c2);
325
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));
332   gst_caps_unref (c1);
333   gst_caps_unref (c2);
334 }
335
336 GST_END_TEST;
337
338 GST_START_TEST (test_merge_fundamental)
339 {
340   GstCaps *c1, *c2;
341
342   /* ANY + specific = ANY */
343   c1 = gst_caps_from_string ("audio/x-raw,rate=44100");
344   c2 = gst_caps_new_any ();
345   c2 = gst_caps_merge (c2, c1);
346   GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
347   fail_unless (gst_caps_get_size (c2) == 0, NULL);
348   fail_unless (gst_caps_is_any (c2), NULL);
349   gst_caps_unref (c2);
350
351   /* specific + ANY = ANY */
352   c2 = gst_caps_from_string ("audio/x-raw,rate=44100");
353   c1 = gst_caps_new_any ();
354   c2 = gst_caps_merge (c2, c1);
355   GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
356   fail_unless (gst_caps_get_size (c2) == 0, NULL);
357   fail_unless (gst_caps_is_any (c2), NULL);
358   gst_caps_unref (c2);
359
360   /* EMPTY + specific = specific */
361   c1 = gst_caps_from_string ("audio/x-raw,rate=44100");
362   c2 = gst_caps_new_empty ();
363   c2 = gst_caps_merge (c2, c1);
364   GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
365   fail_unless (gst_caps_get_size (c2) == 1, NULL);
366   fail_if (gst_caps_is_empty (c2), NULL);
367   gst_caps_unref (c2);
368
369   /* specific + EMPTY = specific */
370   c2 = gst_caps_from_string ("audio/x-raw,rate=44100");
371   c1 = gst_caps_new_empty ();
372   c2 = gst_caps_merge (c2, c1);
373   GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
374   fail_unless (gst_caps_get_size (c2) == 1, NULL);
375   fail_if (gst_caps_is_empty (c2), NULL);
376   gst_caps_unref (c2);
377 }
378
379 GST_END_TEST;
380
381 GST_START_TEST (test_merge_same)
382 {
383   GstCaps *c1, *c2, *test;
384
385   /* this is the same */
386   c1 = gst_caps_from_string ("audio/x-raw,rate=44100,channels=1");
387   c2 = gst_caps_from_string ("audio/x-raw,rate=44100,channels=1");
388   c2 = gst_caps_merge (c2, c1);
389   GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
390   fail_unless (gst_caps_get_size (c2) == 1, NULL);
391   test = gst_caps_from_string ("audio/x-raw,rate=44100,channels=1");
392   fail_unless (gst_caps_is_equal (c2, test));
393   gst_caps_unref (test);
394   gst_caps_unref (c2);
395
396   /* and so is this */
397   c1 = gst_caps_from_string ("audio/x-raw,rate=44100,channels=1");
398   c2 = gst_caps_from_string ("audio/x-raw,channels=1,rate=44100");
399   c2 = gst_caps_merge (c2, c1);
400   GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
401   fail_unless (gst_caps_get_size (c2) == 1, NULL);
402   gst_caps_unref (c2);
403
404   c1 = gst_caps_from_string ("video/x-foo, data=(buffer)AA");
405   c2 = gst_caps_from_string ("video/x-foo, data=(buffer)AABB");
406   c2 = gst_caps_merge (c2, c1);
407   GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
408   fail_unless (gst_caps_get_size (c2) == 2, NULL);
409   gst_caps_unref (c2);
410
411   c1 = gst_caps_from_string ("video/x-foo, data=(buffer)AABB");
412   c2 = gst_caps_from_string ("video/x-foo, data=(buffer)AA");
413   c2 = gst_caps_merge (c2, c1);
414   GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
415   fail_unless (gst_caps_get_size (c2) == 2, NULL);
416   gst_caps_unref (c2);
417
418   c1 = gst_caps_from_string ("video/x-foo, data=(buffer)AA");
419   c2 = gst_caps_from_string ("video/x-foo, data=(buffer)AA");
420   c2 = gst_caps_merge (c2, c1);
421   GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
422   fail_unless (gst_caps_get_size (c2) == 1, NULL);
423   gst_caps_unref (c2);
424
425   c1 = gst_caps_from_string ("video/x-foo, data=(buffer)AA");
426   c2 = gst_caps_from_string ("video/x-bar, data=(buffer)AA");
427   c2 = gst_caps_merge (c2, c1);
428   GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
429   fail_unless (gst_caps_get_size (c2) == 2, NULL);
430   gst_caps_unref (c2);
431 }
432
433 GST_END_TEST;
434
435 GST_START_TEST (test_merge_subset)
436 {
437   GstCaps *c1, *c2, *test;
438
439   /* the 2nd is already covered */
440   c2 = gst_caps_from_string ("audio/x-raw,channels=[1,2]");
441   c1 = gst_caps_from_string ("audio/x-raw,channels=1");
442   c2 = gst_caps_merge (c2, c1);
443   GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
444   fail_unless (gst_caps_get_size (c2) == 1, NULL);
445   test = gst_caps_from_string ("audio/x-raw,channels=[1,2]");
446   fail_unless (gst_caps_is_equal (c2, test));
447   gst_caps_unref (c2);
448   gst_caps_unref (test);
449
450   /* here it is not */
451   c2 = gst_caps_from_string ("audio/x-raw,channels=1,rate=44100");
452   c1 = gst_caps_from_string ("audio/x-raw,channels=[1,2],rate=44100");
453   c2 = gst_caps_merge (c2, c1);
454   GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
455   fail_unless (gst_caps_get_size (c2) == 2, NULL);
456   test = gst_caps_from_string ("audio/x-raw,channels=[1,2],rate=44100");
457   fail_unless (gst_caps_is_equal (c2, test));
458   gst_caps_unref (c2);
459   gst_caps_unref (test);
460
461   /* second one was already contained in the first one */
462   c2 = gst_caps_from_string ("audio/x-raw,channels=[1,3]");
463   c1 = gst_caps_from_string ("audio/x-raw,channels=[1,2]");
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) == 1, NULL);
467   test = gst_caps_from_string ("audio/x-raw,channels=[1,3]");
468   fail_unless (gst_caps_is_equal (c2, test));
469   gst_caps_unref (c2);
470   gst_caps_unref (test);
471
472   /* second one was already contained in the first one */
473   c2 = gst_caps_from_string ("audio/x-raw,channels=[1,4]");
474   c1 = gst_caps_from_string ("audio/x-raw,channels=[1,2]");
475   c2 = gst_caps_merge (c2, c1);
476   GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
477   fail_unless (gst_caps_get_size (c2) == 1, NULL);
478   test = gst_caps_from_string ("audio/x-raw,channels=[1,4]");
479   fail_unless (gst_caps_is_equal (c2, test));
480   gst_caps_unref (c2);
481   gst_caps_unref (test);
482
483   /* second one was already contained in the first one */
484   c2 = gst_caps_from_string ("audio/x-raw,channels=[1,4]");
485   c1 = gst_caps_from_string ("audio/x-raw,channels=[2,4]");
486   c2 = gst_caps_merge (c2, c1);
487   GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
488   fail_unless (gst_caps_get_size (c2) == 1, NULL);
489   test = gst_caps_from_string ("audio/x-raw,channels=[1,4]");
490   fail_unless (gst_caps_is_equal (c2, test));
491   gst_caps_unref (c2);
492   gst_caps_unref (test);
493
494   /* second one was already contained in the first one */
495   c2 = gst_caps_from_string ("audio/x-raw,channels=[1,4]");
496   c1 = gst_caps_from_string ("audio/x-raw,channels=[2,3]");
497   c2 = gst_caps_merge (c2, c1);
498   GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
499   fail_unless (gst_caps_get_size (c2) == 1, NULL);
500   test = gst_caps_from_string ("audio/x-raw,channels=[1,4]");
501   fail_unless (gst_caps_is_equal (c2, test));
502   gst_caps_unref (c2);
503   gst_caps_unref (test);
504
505   /* these caps cannot be merged */
506   c2 = gst_caps_from_string ("audio/x-raw,channels=[2,3]");
507   c1 = gst_caps_from_string ("audio/x-raw,channels=[1,4]");
508   c2 = gst_caps_merge (c2, c1);
509   GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
510   fail_unless (gst_caps_get_size (c2) == 2, NULL);
511   test =
512       gst_caps_from_string
513       ("audio/x-raw,channels=[2,3];audio/x-raw,channels=[1,4]");
514   fail_unless (gst_caps_is_equal (c2, test));
515   gst_caps_unref (c2);
516   gst_caps_unref (test);
517
518   /* these caps cannot be merged */
519   c2 = gst_caps_from_string ("audio/x-raw,channels=[1,2]");
520   c1 = gst_caps_from_string ("audio/x-raw,channels=[1,3]");
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) == 2, NULL);
524   test =
525       gst_caps_from_string
526       ("audio/x-raw,channels=[1,2];audio/x-raw,channels=[1,3]");
527   fail_unless (gst_caps_is_equal (c2, test));
528   gst_caps_unref (c2);
529   gst_caps_unref (test);
530
531   c2 = gst_caps_from_string ("audio/x-raw,channels={1,2}");
532   c1 = gst_caps_from_string ("audio/x-raw,channels={1,2,3,4}");
533   c2 = gst_caps_merge (c2, c1);
534   GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
535   fail_unless (gst_caps_get_size (c2) == 2, NULL);
536   test = gst_caps_from_string ("audio/x-raw,channels={1,2};"
537       "audio/x-raw,channels={1,2,3,4}");
538   fail_unless (gst_caps_is_equal (c2, test));
539   gst_caps_unref (c2);
540   gst_caps_unref (test);
541
542   c2 = gst_caps_from_string ("audio/x-raw,channels={1,2}");
543   c1 = gst_caps_from_string ("audio/x-raw,channels={1,3}");
544   c2 = gst_caps_merge (c2, c1);
545   GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
546   fail_unless (gst_caps_get_size (c2) == 2, NULL);
547   test = gst_caps_from_string ("audio/x-raw,channels={1,2};"
548       "audio/x-raw,channels={1,3}");
549   fail_unless (gst_caps_is_equal (c2, test));
550   gst_caps_unref (c2);
551   gst_caps_unref (test);
552
553   c2 = gst_caps_from_string ("video/x-raw, framerate=(fraction){ 15/2, 5/1 }");
554   c1 = gst_caps_from_string ("video/x-raw, framerate=(fraction){ 15/1, 5/1 }");
555   test = gst_caps_copy (c1);
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_is_subset (test, c2));
559   gst_caps_unref (test);
560   gst_caps_unref (c2);
561
562   c2 = gst_caps_from_string ("audio/x-raw");
563   c1 = gst_caps_from_string ("audio/x-raw,channels=1");
564   c2 = gst_caps_merge (c2, c1);
565   GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
566   fail_unless (gst_caps_get_size (c2) == 1, NULL);
567   test = gst_caps_from_string ("audio/x-raw");
568   fail_unless (gst_caps_is_equal (c2, test));
569   gst_caps_unref (c2);
570   gst_caps_unref (test);
571
572   c2 = gst_caps_from_string ("audio/x-raw,channels=1");
573   c1 = gst_caps_from_string ("audio/x-raw");
574   c2 = gst_caps_merge (c2, c1);
575   GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
576   fail_unless (gst_caps_get_size (c2) == 2, NULL);
577   test = gst_caps_from_string ("audio/x-raw,channels=1; audio/x-raw");
578   fail_unless (gst_caps_is_equal (c2, test));
579   gst_caps_unref (c2);
580   gst_caps_unref (test);
581 }
582
583 GST_END_TEST;
584
585 GST_START_TEST (test_intersect)
586 {
587   GstStructure *s;
588   GstCaps *c1, *c2, *ci1, *ci2;
589
590   /* field not specified = any value possible, so the intersection
591    * should keep fields which are only part of one set of caps */
592   c2 = gst_caps_from_string ("video/x-raw,format=(string)I420,width=20");
593   c1 = gst_caps_from_string ("video/x-raw,format=(string)I420");
594
595   ci1 = gst_caps_intersect (c2, c1);
596   GST_DEBUG ("intersected: %" GST_PTR_FORMAT, ci1);
597   fail_unless (gst_caps_get_size (ci1) == 1, NULL);
598   s = gst_caps_get_structure (ci1, 0);
599   fail_unless (gst_structure_has_name (s, "video/x-raw"));
600   fail_unless (gst_structure_get_value (s, "format") != NULL);
601   fail_unless (gst_structure_get_value (s, "width") != NULL);
602
603   /* with changed order */
604   ci2 = gst_caps_intersect (c1, c2);
605   GST_DEBUG ("intersected: %" GST_PTR_FORMAT, ci2);
606   fail_unless (gst_caps_get_size (ci2) == 1, NULL);
607   s = gst_caps_get_structure (ci2, 0);
608   fail_unless (gst_structure_has_name (s, "video/x-raw"));
609   fail_unless (gst_structure_get_value (s, "format") != NULL);
610   fail_unless (gst_structure_get_value (s, "width") != NULL);
611
612   fail_unless (gst_caps_is_equal (ci1, ci2));
613
614   gst_caps_unref (ci1);
615   gst_caps_unref (ci2);
616
617   gst_caps_unref (c1);
618   gst_caps_unref (c2);
619
620   /* ========== */
621
622   c2 = gst_caps_from_string ("video/x-raw,format=(string)I420,width=20");
623   c1 = gst_caps_from_string ("video/x-raw,format=(string)I420,width=30");
624
625   ci1 = gst_caps_intersect (c2, c1);
626   GST_DEBUG ("intersected: %" GST_PTR_FORMAT, ci1);
627   fail_unless (gst_caps_is_empty (ci1), NULL);
628
629   /* with changed order */
630   ci2 = gst_caps_intersect (c1, c2);
631   GST_DEBUG ("intersected: %" GST_PTR_FORMAT, ci2);
632   fail_unless (gst_caps_is_empty (ci2), NULL);
633
634   fail_unless (gst_caps_is_equal (ci1, ci2));
635
636   gst_caps_unref (ci1);
637   gst_caps_unref (ci2);
638
639   gst_caps_unref (c1);
640   gst_caps_unref (c2);
641
642   /* ========== */
643
644   c2 = gst_caps_from_string ("video/x-raw,format=(string)I420,width=20");
645   c1 = gst_caps_from_string ("video/x-raw2,format=(string)I420,width=20");
646
647   ci1 = gst_caps_intersect (c2, c1);
648   GST_DEBUG ("intersected: %" GST_PTR_FORMAT, ci1);
649   fail_unless (gst_caps_is_empty (ci1), NULL);
650
651   /* with changed order */
652   ci2 = gst_caps_intersect (c1, c2);
653   GST_DEBUG ("intersected: %" GST_PTR_FORMAT, ci2);
654   fail_unless (gst_caps_is_empty (ci2), NULL);
655
656   fail_unless (gst_caps_is_equal (ci1, ci2));
657
658   gst_caps_unref (ci1);
659   gst_caps_unref (ci2);
660
661   gst_caps_unref (c1);
662   gst_caps_unref (c2);
663
664   /* ========== */
665
666   c2 = gst_caps_from_string ("video/x-raw,format=(string)I420,width=20");
667   c1 = gst_caps_from_string ("video/x-raw,format=(string)I420,height=30");
668
669   ci1 = gst_caps_intersect (c2, c1);
670   GST_DEBUG ("intersected: %" GST_PTR_FORMAT, ci1);
671   fail_unless (gst_caps_get_size (ci1) == 1, NULL);
672   s = gst_caps_get_structure (ci1, 0);
673   fail_unless (gst_structure_has_name (s, "video/x-raw"));
674   fail_unless (gst_structure_get_value (s, "format") != NULL);
675   fail_unless (gst_structure_get_value (s, "width") != NULL);
676   fail_unless (gst_structure_get_value (s, "height") != NULL);
677
678   /* with changed order */
679   ci2 = gst_caps_intersect (c1, c2);
680   GST_DEBUG ("intersected: %" GST_PTR_FORMAT, ci2);
681   fail_unless (gst_caps_get_size (ci2) == 1, NULL);
682   s = gst_caps_get_structure (ci2, 0);
683   fail_unless (gst_structure_has_name (s, "video/x-raw"));
684   fail_unless (gst_structure_get_value (s, "format") != NULL);
685   fail_unless (gst_structure_get_value (s, "height") != NULL);
686   fail_unless (gst_structure_get_value (s, "width") != NULL);
687
688   fail_unless (gst_caps_is_equal (ci1, ci2));
689
690   gst_caps_unref (ci1);
691   gst_caps_unref (ci2);
692
693   gst_caps_unref (c1);
694   gst_caps_unref (c2);
695 }
696
697 GST_END_TEST;
698
699 GST_START_TEST (test_intersect2)
700 {
701   GstCaps *caps1, *caps2, *icaps;
702
703   /* tests array subtraction */
704   caps1 = gst_caps_from_string ("audio/x-raw, "
705       "channel-positions=(int)<                      "
706       "{ 1, 2, 3, 4, 5, 6 },                         "
707       "{ 1, 2, 3, 4, 5, 6 },                         "
708       "{ 1, 2, 3, 4, 5, 6 },                         "
709       "{ 1, 2, 3, 4, 5, 6 },                         "
710       "{ 1, 2, 3, 4, 5, 6 },                         " "{ 1, 2, 3, 4, 5, 6 }>");
711   caps2 = gst_caps_from_string ("audio/x-raw, "
712       "channel-positions=(int)< 1, 2, 3, 4, 5, 6 >");
713   icaps = gst_caps_intersect (caps1, caps2);
714   GST_LOG ("intersected caps: %" GST_PTR_FORMAT, icaps);
715   fail_if (gst_caps_is_empty (icaps));
716   fail_unless (gst_caps_is_equal (icaps, caps2));
717   gst_caps_unref (caps1);
718   gst_caps_unref (caps2);
719   gst_caps_unref (icaps);
720
721   /* ===== */
722
723   caps1 = gst_caps_from_string ("some/type, foo=(int)< { 1, 2 }, { 3, 4} >");
724   caps2 = gst_caps_from_string ("some/type, foo=(int)< 1, 3 >");
725   icaps = gst_caps_intersect (caps1, caps2);
726   GST_LOG ("intersected caps: %" GST_PTR_FORMAT, icaps);
727   fail_if (gst_caps_is_empty (icaps));
728   fail_unless (gst_caps_is_equal (icaps, caps2));
729   gst_caps_unref (caps1);
730   gst_caps_unref (caps2);
731   gst_caps_unref (icaps);
732 }
733
734 GST_END_TEST;
735
736 GST_START_TEST (test_intersect_list_duplicate)
737 {
738   GstCaps *caps1, *caps2, *icaps;
739
740   /* make sure we don't take too long to intersect these.. */
741   caps1 = gst_caps_from_string ("video/x-raw, format=(string)YV12; "
742       "video/x-raw, format=(string)I420; video/x-raw, format=(string)YUY2; "
743       "video/x-raw, format=(string)UYVY; "
744       "video/x-raw, format=(string){ I420, YV12, YUY2, UYVY, AYUV, RGBx, BGRx,"
745       " xRGB, xBGR, { RGBA, RGBA, { RGBA, RGBA }, "
746       "{ RGBA, RGBA, { RGBA, RGBA } }, { RGBA, RGBA, { RGBA, RGBA }, "
747       "{ RGBA, RGBA, { RGBA, RGBA } } }, { RGBA, RGBA, { RGBA, RGBA }, "
748       "{ RGBA, RGBA, { RGBA, RGBA } }, { RGBA, RGBA, { RGBA, RGBA }, "
749       "{ RGBA, RGBA, { RGBA, RGBA } } } }, { RGBA, RGBA, { RGBA, RGBA }, "
750       "{ RGBA, RGBA, { RGBA, RGBA } }, { RGBA, RGBA, { RGBA, RGBA }, "
751       "{ RGBA, RGBA, { RGBA, RGBA } } }, { RGBA, RGBA, { RGBA, RGBA }, "
752       "{ RGBA, RGBA, { RGBA, RGBA } }, { RGBA, RGBA, { RGBA, RGBA }, "
753       "{ RGBA, RGBA, { RGBA, RGBA } } } } } }, BGRA, ARGB, { ABGR, ABGR, "
754       "{ ABGR, ABGR }, { ABGR, ABGR, { ABGR, ABGR } }, "
755       "{ ABGR, ABGR, { ABGR, ABGR }, { ABGR, ABGR, { ABGR, ABGR } } }, "
756       "{ ABGR, ABGR, { ABGR, ABGR }, { ABGR, ABGR, { ABGR, ABGR } }, "
757       "{ ABGR, ABGR, { ABGR, ABGR }, { ABGR, ABGR, { ABGR, ABGR } } } }, "
758       "{ ABGR, ABGR, { ABGR, ABGR }, { ABGR, ABGR, { ABGR, ABGR } }, "
759       "{ ABGR, ABGR, { ABGR, ABGR }, { ABGR, ABGR, { ABGR, ABGR } } }, "
760       "{ ABGR, ABGR, { ABGR, ABGR }, { ABGR, ABGR, { ABGR, ABGR } }, "
761       "{ ABGR, ABGR, { ABGR, ABGR }, { ABGR, ABGR, { ABGR, ABGR } } } } } }, "
762       "RGB, BGR, Y41B, Y42B, YVYU, Y444 }; "
763       "video/x-raw, format=(string){ I420, YV12, YUY2, UYVY, AYUV, RGBx, BGRx, "
764       "xRGB, xBGR, { RGBA, RGBA, { RGBA, RGBA }, "
765       "{ RGBA, RGBA, { RGBA, RGBA } }, { RGBA, RGBA, { RGBA, RGBA }, "
766       "{ RGBA, RGBA, { RGBA, RGBA } } }, { RGBA, RGBA, { RGBA, RGBA }, "
767       "{ RGBA, RGBA, { RGBA, RGBA } }, { RGBA, RGBA, { RGBA, RGBA }, "
768       "{ RGBA, RGBA, { RGBA, RGBA } } } }, { RGBA, RGBA, { RGBA, RGBA }, "
769       "{ RGBA, RGBA, { RGBA, RGBA } }, { RGBA, RGBA, { RGBA, RGBA }, "
770       "{ RGBA, RGBA, { RGBA, RGBA } } }, { RGBA, RGBA, { RGBA, RGBA }, "
771       "{ RGBA, RGBA, { RGBA, RGBA } }, { RGBA, RGBA, { RGBA, RGBA }, "
772       "{ RGBA, RGBA, { RGBA, RGBA } } } } } }, BGRA, ARGB, "
773       "{ ABGR, ABGR, { ABGR, ABGR }, { ABGR, ABGR, { ABGR, ABGR } }, "
774       "{ ABGR, ABGR, { ABGR, ABGR }, { ABGR, ABGR, { ABGR, ABGR } } }, "
775       "{ ABGR, ABGR, { ABGR, ABGR }, { ABGR, ABGR, { ABGR, ABGR } }, "
776       "{ ABGR, ABGR, { ABGR, ABGR }, { ABGR, ABGR, { ABGR, ABGR } } } }, "
777       "{ ABGR, ABGR, { ABGR, ABGR }, { ABGR, ABGR, { ABGR, ABGR } }, "
778       "{ ABGR, ABGR, { ABGR, ABGR }, { ABGR, ABGR, { ABGR, ABGR } } }, "
779       "{ ABGR, ABGR, { ABGR, ABGR }, { ABGR, ABGR, { ABGR, ABGR } }, "
780       "{ ABGR, ABGR, { ABGR, ABGR }, { ABGR, ABGR, { ABGR, ABGR } } } } } }, "
781       "RGB, BGR, Y41B, Y42B, YVYU, Y444, NV12, NV21 }; "
782       "video/x-raw, format=(string){ I420, YV12, YUY2, UYVY, AYUV, RGBx, "
783       "BGRx, xRGB, xBGR, { RGBA, RGBA, { RGBA, RGBA }, "
784       "{ RGBA, RGBA, { RGBA, RGBA } }, { RGBA, RGBA, { RGBA, RGBA }, "
785       "{ RGBA, RGBA, { RGBA, RGBA } } } }, BGRA, ARGB, "
786       "{ ABGR, ABGR, { ABGR, ABGR }, { ABGR, ABGR, { ABGR, ABGR } }, "
787       "{ ABGR, ABGR, { ABGR, ABGR }, { ABGR, ABGR, { ABGR, ABGR } } } }, "
788       "RGB, BGR, Y41B, Y42B, YVYU, Y444, NV12, NV21 }");
789
790   caps2 = gst_caps_copy (caps1);
791
792   icaps = gst_caps_intersect (caps1, caps2);
793
794   gst_caps_unref (caps1);
795   gst_caps_unref (caps2);
796   gst_caps_unref (icaps);
797 }
798
799 GST_END_TEST;
800
801 GST_START_TEST (test_intersect_zigzag)
802 {
803   GstCaps *caps1, *caps2, *icaps, *result;
804
805   /* tests if caps order is maintained */
806   caps1 = gst_caps_from_string ("format/A; format/B; format/C; format/D");
807   caps2 = gst_caps_from_string ("format/D; format/A; format/B; format/C");
808
809   icaps = gst_caps_intersect_full (caps1, caps2, GST_CAPS_INTERSECT_ZIG_ZAG);
810   result = gst_caps_from_string ("format/B; format/A; format/D; format/C");
811   GST_LOG ("intersected caps: %" GST_PTR_FORMAT, icaps);
812   fail_if (gst_caps_is_empty (icaps));
813   fail_unless (gst_caps_is_equal (icaps, result));
814   gst_caps_unref (icaps);
815   gst_caps_unref (result);
816
817   icaps = gst_caps_intersect_full (caps2, caps1, GST_CAPS_INTERSECT_FIRST);
818   result = gst_caps_from_string ("format/A; format/B; format/D; format/C");
819   GST_LOG ("intersected caps: %" GST_PTR_FORMAT, icaps);
820   fail_if (gst_caps_is_empty (icaps));
821   fail_unless (gst_caps_is_equal (icaps, result));
822   gst_caps_unref (icaps);
823   gst_caps_unref (result);
824
825   gst_caps_unref (caps1);
826   gst_caps_unref (caps2);
827 }
828
829 GST_END_TEST;
830
831
832 GST_START_TEST (test_intersect_first)
833 {
834   GstCaps *caps1, *caps2, *icaps, *result;
835
836   /* tests if caps order is maintained */
837   caps1 = gst_caps_from_string ("format/A; format/B; format/C; format/D");
838   caps2 = gst_caps_from_string ("format/C; format/D; format/A");
839   icaps = gst_caps_intersect_full (caps1, caps2, GST_CAPS_INTERSECT_FIRST);
840   result = gst_caps_from_string ("format/A; format/C; format/D");
841   GST_LOG ("intersected caps: %" GST_PTR_FORMAT, icaps);
842   fail_if (gst_caps_is_empty (icaps));
843   fail_unless (gst_caps_is_equal (icaps, result));
844   gst_caps_unref (caps1);
845   gst_caps_unref (caps2);
846   gst_caps_unref (icaps);
847   gst_caps_unref (result);
848 }
849
850 GST_END_TEST;
851
852
853 GST_START_TEST (test_intersect_first2)
854 {
855   GstCaps *caps1, *caps2, *icaps, *result;
856
857   /* tests if caps order is maintained */
858   caps1 = gst_caps_from_string ("format/A; format/B; format/C; format/D");
859   caps2 = gst_caps_from_string ("format/D; format/A; format/B; format/C");
860
861   icaps = gst_caps_intersect_full (caps1, caps2, GST_CAPS_INTERSECT_FIRST);
862   result = gst_caps_from_string ("format/A; format/B; format/C; format/D");
863   GST_LOG ("intersected caps: %" GST_PTR_FORMAT, icaps);
864   fail_if (gst_caps_is_empty (icaps));
865   fail_unless (gst_caps_is_equal (icaps, result));
866   gst_caps_unref (icaps);
867   gst_caps_unref (result);
868
869   icaps = gst_caps_intersect_full (caps2, caps1, GST_CAPS_INTERSECT_FIRST);
870   result = gst_caps_from_string ("format/D; format/A; format/B; format/C");
871   GST_LOG ("intersected caps: %" GST_PTR_FORMAT, icaps);
872   fail_if (gst_caps_is_empty (icaps));
873   fail_unless (gst_caps_is_equal (icaps, result));
874   gst_caps_unref (icaps);
875   gst_caps_unref (result);
876
877   gst_caps_unref (caps1);
878   gst_caps_unref (caps2);
879 }
880
881 GST_END_TEST;
882
883 GST_START_TEST (test_intersect_duplication)
884 {
885   GstCaps *c1, *c2, *test;
886
887   c1 = gst_caps_from_string
888       ("audio/x-raw, format=(string)S16_LE, rate=(int)[ 1, 2147483647 ], channels=(int)[ 1, 2 ]");
889   c2 = gst_caps_from_string
890       ("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 ]");
891
892   test = gst_caps_intersect_full (c1, c2, GST_CAPS_INTERSECT_FIRST);
893   fail_unless_equals_int (gst_caps_get_size (test), 1);
894   fail_unless (gst_caps_is_equal (c1, test));
895   gst_caps_unref (c1);
896   gst_caps_unref (c2);
897   gst_caps_unref (test);
898 }
899
900 GST_END_TEST;
901
902 static gboolean
903 _caps_is_fixed_foreach (GQuark field_id, const GValue * value, gpointer unused)
904 {
905   return gst_value_is_fixed (value);
906 }
907
908
909 GST_START_TEST (test_normalize)
910 {
911   GstCaps *in, *norm, *out;
912   guint i;
913
914   in = gst_caps_from_string ("some/type, foo=(int){ 1 , 2 }");
915   out = gst_caps_from_string ("some/type, foo=(int) 1; some/type, foo=(int) 2");
916   norm = gst_caps_normalize (in);
917   fail_if (gst_caps_is_empty (norm));
918   fail_unless (gst_caps_is_equal (norm, out));
919   for (i = 0; i < gst_caps_get_size (norm); i++) {
920     GstStructure *st = gst_caps_get_structure (norm, i);
921     /* Make sure all fields of all structures are fixed */
922     fail_unless (gst_structure_foreach (st, _caps_is_fixed_foreach, NULL));
923   }
924
925   gst_caps_unref (out);
926   gst_caps_unref (norm);
927
928   in = gst_caps_from_string
929       ("some/type, foo=(int){ 1 , 2 }, bar=(int){ 3, 4 }");
930   out =
931       gst_caps_from_string
932       ("some/type, foo=(int) 1, bar=(int) 3; some/type, foo=(int) 2, bar=(int) 3;"
933       "some/type, foo=(int) 1, bar=(int) 4; some/type, foo=(int) 2, bar=(int) 4;");
934   norm = gst_caps_normalize (in);
935   fail_if (gst_caps_is_empty (norm));
936   fail_unless (gst_caps_is_equal (norm, out));
937   for (i = 0; i < gst_caps_get_size (norm); i++) {
938     GstStructure *st = gst_caps_get_structure (norm, i);
939     /* Make sure all fields of all structures are fixed */
940     fail_unless (gst_structure_foreach (st, _caps_is_fixed_foreach, NULL));
941   }
942
943   gst_caps_unref (out);
944   gst_caps_unref (norm);
945
946   in = gst_caps_from_string
947       ("some/type, foo=(string){ 1 , 2 }, bar=(string) { 3 }");
948   out =
949       gst_caps_from_string
950       ("some/type, foo=(string) 1, bar=(string) 3; some/type, foo=(string) 2, bar=(string) 3");
951   norm = gst_caps_normalize (in);
952   fail_if (gst_caps_is_empty (norm));
953   fail_unless (gst_caps_is_equal (norm, out));
954   for (i = 0; i < gst_caps_get_size (norm); i++) {
955     GstStructure *st = gst_caps_get_structure (norm, i);
956     /* Make sure all fields of all structures are fixed */
957     fail_unless (gst_structure_foreach (st, _caps_is_fixed_foreach, NULL));
958   }
959
960   gst_caps_unref (out);
961   gst_caps_unref (norm);
962 }
963
964 GST_END_TEST;
965
966 GST_START_TEST (test_broken)
967 {
968   GstCaps *c1;
969
970   /* NULL is not valid for media_type */
971   ASSERT_CRITICAL (c1 =
972       gst_caps_new_simple (NULL, "field", G_TYPE_INT, 1, NULL));
973   fail_if (c1);
974
975 #ifndef G_DISABLE_CHECKS
976   /* such a name is not valid, see gst_structure_validate_name() */
977   ASSERT_CRITICAL (c1 =
978       gst_caps_new_simple ("1#@abc", "field", G_TYPE_INT, 1, NULL));
979   fail_if (c1);
980 #endif
981 }
982
983 GST_END_TEST;
984
985 GST_START_TEST (test_features)
986 {
987   GstCaps *c1, *c2, *c3;
988   GstStructure *s1, *s2;
989   GstCapsFeatures *f1, *f2;
990   gchar *str1;
991   static GstStaticCaps scaps =
992       GST_STATIC_CAPS
993       ("video/x-raw(memory:EGLImage), width=320, height=[ 240, 260 ]");
994
995   c1 = gst_caps_new_empty ();
996   fail_unless (c1 != NULL);
997   s1 = gst_structure_new ("video/x-raw", "width", G_TYPE_INT, 320, "height",
998       GST_TYPE_INT_RANGE, 240, 260, NULL);
999   fail_unless (s1 != NULL);
1000   f1 = gst_caps_features_new ("memory:EGLImage", NULL);
1001   fail_unless (f1 != NULL);
1002
1003   gst_caps_append_structure_full (c1, s1, f1);
1004   s2 = gst_caps_get_structure (c1, 0);
1005   fail_unless (s1 == s2);
1006   f2 = gst_caps_get_features (c1, 0);
1007   fail_unless (f1 == f2);
1008
1009   str1 = gst_caps_to_string (c1);
1010   fail_unless (str1 != NULL);
1011   c2 = gst_caps_from_string (str1);
1012   fail_unless (c2 != NULL);
1013   g_free (str1);
1014
1015   fail_unless (gst_caps_is_equal (c1, c2));
1016   fail_unless (gst_caps_is_subset (c1, c2));
1017   fail_unless (gst_caps_is_subset (c2, c1));
1018   fail_unless (gst_caps_can_intersect (c1, c2));
1019
1020   gst_caps_unref (c2);
1021
1022   c2 = gst_caps_new_empty ();
1023   fail_unless (c2 != NULL);
1024   s2 = gst_structure_new ("video/x-raw", "width", G_TYPE_INT, 320, "height",
1025       GST_TYPE_INT_RANGE, 240, 260, NULL);
1026   fail_unless (s2 != NULL);
1027   f2 = gst_caps_features_new ("memory:VASurface", "meta:VAMeta", NULL);
1028   fail_unless (f2 != NULL);
1029   gst_caps_append_structure_full (c2, s2, f2);
1030
1031   fail_if (gst_caps_is_equal (c1, c2));
1032   fail_if (gst_caps_is_subset (c1, c2));
1033   fail_if (gst_caps_is_subset (c2, c1));
1034   fail_if (gst_caps_can_intersect (c1, c2));
1035
1036   str1 = gst_caps_to_string (c2);
1037   fail_unless (str1 != NULL);
1038   c3 = gst_caps_from_string (str1);
1039   fail_unless (c3 != NULL);
1040   g_free (str1);
1041
1042   fail_unless (gst_caps_is_equal (c2, c3));
1043   fail_unless (gst_caps_is_subset (c2, c3));
1044   fail_unless (gst_caps_is_subset (c3, c2));
1045   fail_unless (gst_caps_can_intersect (c2, c3));
1046
1047   f1 = gst_caps_get_features (c3, 0);
1048   fail_unless (f1 != NULL);
1049   fail_if (f1 == f2);
1050   gst_caps_features_contains (f1, "memory:VASurface");
1051   gst_caps_features_remove (f1, "memory:VASurface");
1052   fail_if (gst_caps_is_equal (c2, c3));
1053   fail_if (gst_caps_is_subset (c2, c3));
1054   fail_if (gst_caps_is_subset (c3, c2));
1055   fail_if (gst_caps_can_intersect (c2, c3));
1056
1057   gst_caps_unref (c3);
1058   gst_caps_unref (c2);
1059
1060   c2 = gst_static_caps_get (&scaps);
1061   fail_unless (c2 != NULL);
1062   fail_unless (gst_caps_is_equal (c1, c2));
1063   fail_unless (gst_caps_is_subset (c1, c2));
1064   fail_unless (gst_caps_is_subset (c2, c1));
1065   fail_unless (gst_caps_can_intersect (c1, c2));
1066   gst_caps_unref (c2);
1067
1068   c2 = gst_caps_from_string
1069       ("video/x-raw(ANY), width=320, height=[ 240, 260 ]");
1070   fail_unless (c2 != NULL);
1071   fail_if (gst_caps_is_equal (c1, c2));
1072   fail_unless (gst_caps_is_subset (c1, c2));
1073   fail_if (gst_caps_is_subset (c2, c1));
1074   fail_unless (gst_caps_can_intersect (c1, c2));
1075
1076   c3 = gst_caps_intersect (c1, c2);
1077   fail_unless (gst_caps_is_equal (c3, c1));
1078
1079   gst_caps_unref (c3);
1080   gst_caps_unref (c2);
1081   gst_caps_unref (c1);
1082 }
1083
1084 GST_END_TEST;
1085
1086 static Suite *
1087 gst_caps_suite (void)
1088 {
1089   Suite *s = suite_create ("GstCaps");
1090   TCase *tc_chain = tcase_create ("operations");
1091
1092   suite_add_tcase (s, tc_chain);
1093   tcase_add_test (tc_chain, test_from_string);
1094   tcase_add_test (tc_chain, test_double_append);
1095   tcase_add_test (tc_chain, test_mutability);
1096   tcase_add_test (tc_chain, test_static_caps);
1097   tcase_add_test (tc_chain, test_simplify);
1098   tcase_add_test (tc_chain, test_truncate);
1099   tcase_add_test (tc_chain, test_subset);
1100   tcase_add_test (tc_chain, test_merge_fundamental);
1101   tcase_add_test (tc_chain, test_merge_same);
1102   tcase_add_test (tc_chain, test_merge_subset);
1103   tcase_add_test (tc_chain, test_intersect);
1104   tcase_add_test (tc_chain, test_intersect2);
1105   tcase_add_test (tc_chain, test_intersect_list_duplicate);
1106   tcase_add_test (tc_chain, test_intersect_zigzag);
1107   tcase_add_test (tc_chain, test_intersect_first);
1108   tcase_add_test (tc_chain, test_intersect_first2);
1109   tcase_add_test (tc_chain, test_intersect_duplication);
1110   tcase_add_test (tc_chain, test_normalize);
1111   tcase_add_test (tc_chain, test_broken);
1112   tcase_add_test (tc_chain, test_features);
1113
1114   return s;
1115 }
1116
1117 GST_CHECK_MAIN (gst_caps);