diff options
author | Benjamin Otte <otte@gnome.org> | 2004-04-21 03:25:13 +0000 |
---|---|---|
committer | Benjamin Otte <otte@gnome.org> | 2004-04-21 03:25:13 +0000 |
commit | 614b4d162727c8c8c955a2489c09756a4b8529a8 (patch) | |
tree | d126b9abf8ebec9ba0b69588a2b1124159395a36 /testsuite/caps | |
parent | bdb8c10b5c4d22cddbef5e8099bdaaff5dddaeb6 (diff) |
gst/gstcaps.c: check for ANY caps before appending/unioning
Original commit message from CVS:
* gst/gstcaps.c: (gst_caps_append), (gst_caps_union):
check for ANY caps before appending/unioning
* gst/gstcaps.c: (gst_caps_is_subset),
(gst_caps_is_equal), (gst_caps_structure_subtract_field),
(gst_caps_structure_subtract), (gst_caps_subtract):
* gst/gstcaps.h:
add gst_caps_is_equal, gst_caps_is_subset and gst_caps_subtract to
the API. deprecate gst_caps_is_equal_fixed
* gst/gstpad.c: (gst_pad_try_set_caps):
* gst/gstqueue.c: (gst_queue_link):
s/gst_caps_is_equal_fixed/gst_caps_is_equal/
* gst/gststructure.c: (gst_structure_get_name_id):
* gst/gststructure.h:
add function gst_structure_get_name_id
* gst/gstvalue.c: (gst_value_subtract_int_int_range),
(gst_value_create_new_range), (gst_value_subtract_int_range_int),
(gst_value_subtract_int_range_int_range),
(gst_value_subtract_double_double_range),
(gst_value_subtract_double_range_double),
(gst_value_subtract_double_range_double_range),
(gst_value_subtract_from_list), (gst_value_subtract_list),
(gst_value_can_intersect), (gst_value_subtract),
(gst_value_can_subtract), (gst_value_register_subtract_func),
(_gst_value_initialize):
* gst/gstvalue.h:
add support for subtracting values from each other. Note that
subtracting means subtracting as in set theory. Required for caps
stuff above.
* testsuite/caps/.cvsignore:
* testsuite/caps/Makefile.am:
* testsuite/caps/erathostenes.c: (erathostenes), (main):
* testsuite/caps/sets.c: (check_caps), (main):
* testsuite/caps/subtract.c: (check_caps), (main):
add tests for subtraction and equality code.
Diffstat (limited to 'testsuite/caps')
-rw-r--r-- | testsuite/caps/.gitignore | 7 | ||||
-rw-r--r-- | testsuite/caps/Makefile.am | 13 | ||||
-rw-r--r-- | testsuite/caps/erathostenes.c | 71 | ||||
-rw-r--r-- | testsuite/caps/sets.c | 91 | ||||
-rw-r--r-- | testsuite/caps/subtract.c | 63 |
5 files changed, 240 insertions, 5 deletions
diff --git a/testsuite/caps/.gitignore b/testsuite/caps/.gitignore index 75f6cf76c..3ff4a8ee4 100644 --- a/testsuite/caps/.gitignore +++ b/testsuite/caps/.gitignore @@ -12,11 +12,14 @@ Makefile.in app_fixate caps compatibility +erathostenes +fixed +intersect2 intersection normalisation union -fixed +sets string-conversions -intersect2 +subtract value_compare value_intersect diff --git a/testsuite/caps/Makefile.am b/testsuite/caps/Makefile.am index 52949f017..2b7eb477f 100644 --- a/testsuite/caps/Makefile.am +++ b/testsuite/caps/Makefile.am @@ -15,7 +15,10 @@ tests_pass = \ value_intersect \ value_serialize \ audioscale \ - filtercaps + filtercaps \ + erathostenes \ + subtract \ + sets tests_fail = tests_ignore = @@ -38,6 +41,10 @@ intersect2_LDADD = $(GST_LIBS) intersect2_CFLAGS = $(GST_CFLAGS) $(XML_CFLAGS) filtercaps_LDADD = $(GST_LIBS) filtercaps_CFLAGS = $(GST_CFLAGS) $(XML_CFLAGS) - - +erathostenes_LDADD = $(GST_LIBS) +ersthostenes_CFLAGS = $(GST_CFLAGS) $(XML_CFLAGS) +subtract_LDADD = $(GST_LIBS) +subtract_CFLAGS = $(GST_CFLAGS) $(XML_CFLAGS) +sets_LDADD = $(GST_LIBS) +sets_CFLAGS = $(GST_CFLAGS) $(XML_CFLAGS) diff --git a/testsuite/caps/erathostenes.c b/testsuite/caps/erathostenes.c new file mode 100644 index 000000000..9d9866a7a --- /dev/null +++ b/testsuite/caps/erathostenes.c @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2004 Benjamin Otte <in7y118@public.uni-hamburg.de> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include <gst/gst.h> +#include <stdlib.h> + +#define MAX_SIEVE 20 + +static void +erathostenes (GValue * sieve, gboolean up, int size) +{ + guint i, j; + GValue temp = { 0, }; + GValue list = { 0, }; + + g_value_init (sieve, GST_TYPE_INT_RANGE); + gst_value_set_int_range (sieve, 2, size * size); + for (i = up ? 2 : size; up ? (i <= size) : (i >= 2); i += up ? 1 : -1) { + g_value_init (&list, GST_TYPE_LIST); + for (j = 2 * i; j <= size * size; j += i) { + GValue v = { 0, }; + + g_value_init (&v, G_TYPE_INT); + g_value_set_int (&v, j); + gst_value_list_append_value (&list, &v); + g_value_unset (&v); + } + gst_value_subtract (&temp, sieve, &list); + g_value_unset (sieve); + gst_value_init_and_copy (sieve, &temp); + g_value_unset (&temp); + g_value_unset (&list); + /* g_print ("%2u: %s\n", i, gst_value_serialize (sieve)); */ + } + + g_print ("%s\n", gst_value_serialize (sieve)); +} + +gint +main (gint argc, gchar ** argv) +{ + GValue up = { 0, }; + GValue down = { 0, }; + guint size = MAX_SIEVE; + + gst_init (&argc, &argv); + + if (argc > 1) + size = atol (argv[1]); + + erathostenes (&up, TRUE, size); + erathostenes (&down, FALSE, size); + + g_assert (gst_value_compare (&up, &down) == GST_VALUE_EQUAL); + return 0; +} diff --git a/testsuite/caps/sets.c b/testsuite/caps/sets.c new file mode 100644 index 000000000..740039f1b --- /dev/null +++ b/testsuite/caps/sets.c @@ -0,0 +1,91 @@ +/* + * Copyright (C) 2004 Benjamin Otte <in7y118@public.uni-hamburg.de> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include <gst/gst.h> +#include <string.h> + +static const gchar *caps[] = { + "video/x-raw-yuv, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], framerate=(double)[ 0, 1.7976931348623157e+308 ], format=(fourcc)I420; video/x-raw-yuv, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], framerate=(double)[ 0, 1.7976931348623157e+308 ], format=(fourcc)YUY2; video/x-raw-rgb, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], framerate=(double)[ 0, 1.7976931348623157e+308 ], bpp=(int)24, depth=(int)24, red_mask=(int)16711680, green_mask=(int)65280, blue_mask=(int)255, endianness=(int)4321; video/x-raw-rgb, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], framerate=(double)[ 0, 1.7976931348623157e+308 ], bpp=(int)24, depth=(int)24, red_mask=(int)255, green_mask=(int)65280, blue_mask=(int)16711680, endianness=(int)4321; video/x-raw-yuv, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], framerate=(double)[ 0, 1.7976931348623157e+308 ], format=(fourcc)Y42B; video/x-raw-rgb, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], framerate=(double)[ 0, 1.7976931348623157e+308 ], bpp=(int)32, depth=(int)24, red_mask=(int)65280, green_mask=(int)16711680, blue_mask=(int)-16777216, endianness=(int)4321; video/x-raw-yuv, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], framerate=(double)[ 0, 1.7976931348623157e+308 ], format=(fourcc)YUV9; video/x-raw-yuv, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], framerate=(double)[ 0, 1.7976931348623157e+308 ], format=(fourcc)Y41B; video/x-raw-rgb, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], framerate=(double)[ 0, 1.7976931348623157e+308 ], bpp=(int)16, depth=(int)16, red_mask=(int)63488, green_mask=(int)2016, blue_mask=(int)31, endianness=(int)1234; video/x-raw-rgb, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], framerate=(double)[ 0, 1.7976931348623157e+308 ], bpp=(int)16, depth=(int)15, red_mask=(int)31744, green_mask=(int)992, blue_mask=(int)31, endianness=(int)1234", + "video/x-raw-yuv, format=(fourcc){ YUY2, I420 }, width=(int)[ 1, 2147483647 ], height=(int)[ 1, 2147483647 ]; video/x-jpeg, width=(int)[ 1, 2147483647 ], height=(int)[ 1, 2147483647 ]; video/x-divx, divxversion=(int)[ 3, 5 ], width=(int)[ 1, 2147483647 ], height=(int)[ 1, 2147483647 ]; video/x-xvid, width=(int)[ 1, 2147483647 ], height=(int)[ 1, 2147483647 ]; video/x-3ivx, width=(int)[ 1, 2147483647 ], height=(int)[ 1, 2147483647 ]; video/x-msmpeg, msmpegversion=(int)[ 41, 43 ], width=(int)[ 1, 2147483647 ], height=(int)[ 1, 2147483647 ]; video/mpeg, mpegversion=(int)1, systemstream=(boolean)false, width=(int)[ 1, 2147483647 ], height=(int)[ 1, 2147483647 ]; video/x-h263, width=(int)[ 1, 2147483647 ], height=(int)[ 1, 2147483647 ]; video/x-dv, systemstream=(boolean)false, width=(int)720, height=(int){ 576, 480 }; video/x-huffyuv, width=(int)[ 1, 2147483647 ], height=(int)[ 1, 2147483647 ]", + "video/x-raw-yuv, format=(fourcc){ YUY2, I420 }, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ]; image/jpeg, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ]; video/x-divx, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], divxversion=(int)[ 3, 5 ]; video/x-xvid, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ]; video/x-3ivx, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ]; video/x-msmpeg, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], msmpegversion=(int)[ 41, 43 ]; video/mpeg, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], mpegversion=(int)1, systemstream=(boolean)false; video/x-h263, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ]; video/x-dv, width=(int)720, height=(int){ 576, 480 }, systemstream=(boolean)false; video/x-huffyuv, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ]", + "video/x-raw-rgb, bpp=(int)32, depth=(int)24, endianness=(int)4321, red_mask=(int)65280, green_mask=(int)16711680, blue_mask=(int)-16777216, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], framerate=(double)[ 0, 1.7976931348623157e+308 ]; video/x-raw-rgb, bpp=(int)32, depth=(int)24, endianness=(int)4321, red_mask=(int)-16777216, green_mask=(int)16711680, blue_mask=(int)65280, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], framerate=(double)[ 0, 1.7976931348623157e+308 ]", + "video/x-raw-rgb, bpp=(int)32, depth=(int)24, endianness=(int)4321, red_mask=(int)65280, green_mask=(int)16711680, blue_mask=(int)-16777216, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], framerate=(double)[ 0, 1.7976931348623157e+308 ]", + "video/x-raw-yuv, format=(fourcc){ I420 }, width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ]", + "ANY", + "EMPTY" +}; + +static void +check_caps (const gchar * eins, const gchar * zwei) +{ + GstCaps *one, *two, *test, *test2, *test3, *test4; + + one = gst_caps_from_string (eins); + two = gst_caps_from_string (zwei); + g_print (" A = %u\n", strlen (eins)); + g_print (" B = %u\n", strlen (zwei)); + + test = gst_caps_intersect (one, two); + if (gst_caps_is_equal (one, two)) { + g_print (" EQUAL\n\n"); + g_assert (gst_caps_is_equal (one, test)); + g_assert (gst_caps_is_equal (two, test)); + } else if (!gst_caps_is_any (one) || gst_caps_is_empty (two)) { + test2 = gst_caps_subtract (one, test); + g_print (" A - B = %u\n", strlen (gst_caps_to_string (test2))); + /* test2 = one - (one A two) = one - two */ + test3 = gst_caps_intersect (test2, two); + g_print (" empty = %s\n", gst_caps_to_string (test3)); + g_assert (gst_caps_is_empty (test3)); + gst_caps_free (test3); + test3 = gst_caps_union (test2, two); + g_print (" A + B = %u\n", strlen (gst_caps_to_string (test3))); + /* test3 = one - two + two = one + two */ + g_print (" A + B = %s\n", gst_caps_to_string (gst_caps_subtract (one, + test3))); + g_assert (gst_caps_is_subset (one, test3)); + test4 = gst_caps_union (one, two); + g_assert (gst_caps_is_equal (test3, test4)); + g_print (" NOT EQUAL\n\n"); + gst_caps_free (test2); + gst_caps_free (test3); + gst_caps_free (test4); + } else { + g_print (" ANY CAPS\n\n"); + } + gst_caps_free (test); + gst_caps_free (two); + gst_caps_free (one); +} + +gint +main (gint argc, gchar ** argv) +{ + guint i, j; + + gst_init (&argc, &argv); + + for (i = 0; i < G_N_ELEMENTS (caps); i++) { + for (j = 0; j < G_N_ELEMENTS (caps); j++) { + g_print ("%u - %u\n", i, j); + check_caps (caps[i], caps[j]); + } + } + + return 0; +} diff --git a/testsuite/caps/subtract.c b/testsuite/caps/subtract.c new file mode 100644 index 000000000..fe80d444a --- /dev/null +++ b/testsuite/caps/subtract.c @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2004 Benjamin Otte <in7y118@public.uni-hamburg.de> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include <gst/gst.h> + +static void +check_caps (const gchar * set, const gchar * subset) +{ + GstCaps *one, *two, *test, *test2; + + g_print (" A = %s\n", set); + one = gst_caps_from_string (set); + g_print (" B = %s\n", subset); + two = gst_caps_from_string (subset); + /* basics */ + test = gst_caps_subtract (one, one); + g_assert (gst_caps_is_empty (test)); + gst_caps_free (test); + test = gst_caps_subtract (two, two); + g_assert (gst_caps_is_empty (test)); + gst_caps_free (test); + test = gst_caps_subtract (two, one); + g_assert (gst_caps_is_empty (test)); + gst_caps_free (test); + /* now the nice part */ + test = gst_caps_subtract (one, two); + g_assert (!gst_caps_is_empty (test)); + g_print (" A - B = %s\n", gst_caps_to_string (test)); + test2 = gst_caps_union (test, two); + g_print ("A - B + B = %s\n", gst_caps_to_string (test2)); + gst_caps_free (test); + test = gst_caps_subtract (test2, one); + g_assert (gst_caps_is_empty (test)); + gst_caps_free (test); +} + +gint +main (gint argc, gchar ** argv) +{ + gst_init (&argc, &argv); + + check_caps ("some/mime, _int = [ 1, 2 ], list = { \"A\", \"B\", \"C\" }", + "some/mime, _int = 1, list = \"A\""); + check_caps ("some/mime, _double = (double) 1.0; other/mime, _int = { 1, 2 }", + "some/mime, _double = (double) 1.0"); + + return 0; +} |