gst/gstcaps.c: Fix subset test.

Original commit message from CVS:
* gst/gstcaps.c: (gst_caps_structure_is_subset_field):
Fix subset test.
* tests/check/gst/gstcaps.c: (GST_START_TEST):
Improve unit test subset tests and add a testcase for the subset failure
cases.
* tests/check/gst/gstvalue.c: (GST_START_TEST), (gst_value_suite):
Improve subtraction unit test.
This commit is contained in:
Wim Taymans 2008-08-07 12:28:28 +00:00
parent 3897306e70
commit b08cd83cbb
4 changed files with 205 additions and 27 deletions

View file

@ -1,3 +1,15 @@
2008-08-07 Wim Taymans <wim.taymans@collabora.co.uk>
* gst/gstcaps.c: (gst_caps_structure_is_subset_field):
Fix subset test.
* tests/check/gst/gstcaps.c: (GST_START_TEST):
Improve unit test subset tests and add a testcase for the subset failure
cases.
* tests/check/gst/gstvalue.c: (GST_START_TEST), (gst_value_suite):
Improve subtraction unit test.
2008-08-07 Stefan Kost <ensonic@users.sf.net>
* plugins/elements/gsttee.c:

View file

@ -518,37 +518,43 @@ gst_caps_structure_is_subset_field (GQuark field_id, const GValue * value,
GstStructure *subtract_from = user_data;
GValue subtraction = { 0, };
const GValue *other;
gint res;
other = gst_structure_id_get_value (subtract_from, field_id);
if (!other) {
if (!(other = gst_structure_id_get_value (subtract_from, field_id)))
/* field is missing in one set */
return FALSE;
}
/*
* [1,2] - 1 = 2
* 1 - [1,2] = ???
*/
if (!gst_value_subtract (&subtraction, other, value)) {
/* empty result -> values are the same, or first was a value and
* second was a list
* verify that result is empty by swapping args */
if (!gst_value_subtract (&subtraction, value, other)) {
return TRUE;
}
g_value_unset (&subtraction);
return FALSE;
}
res = gst_value_compare (&subtraction, other);
g_value_unset (&subtraction);
if (res == GST_VALUE_EQUAL) {
/* value was empty ? */
return FALSE;
} else {
/* equal values are subset */
if (gst_value_compare (other, value) == GST_VALUE_EQUAL)
return TRUE;
/*
* 1 - [1,2] = empty
* -> !subset
*
* [1,2] - 1 = 2
* -> 1 - [1,2] = empty
* -> subset
*
* [1,3] - [1,2] = 3
* -> [1,2] - [1,3] = empty
* -> subset
*
* {1,2} - {1,3} = 2
* -> {1,3} - {1,2} = 3
* -> !subset
*
* First caps subtraction needs to return a non-empty set, second
* subtractions needs to give en empty set.
*/
if (gst_value_subtract (&subtraction, other, value)) {
g_value_unset (&subtraction);
/* !empty result, swapping must be empty */
if (!gst_value_subtract (&subtraction, value, other))
return TRUE;
g_value_unset (&subtraction);
}
return FALSE;
}
static gboolean

View file

@ -393,7 +393,7 @@ GST_END_TEST;
GST_START_TEST (test_merge_same)
{
GstCaps *c1, *c2;
GstCaps *c1, *c2, *test;
/* this is the same */
c1 = gst_caps_from_string ("audio/x-raw-int,rate=44100,channels=1");
@ -401,6 +401,9 @@ GST_START_TEST (test_merge_same)
gst_caps_merge (c2, c1);
GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
fail_unless (gst_caps_get_size (c2) == 1, NULL);
test = gst_caps_from_string ("audio/x-raw-int,rate=44100,channels=1");
fail_unless (gst_caps_is_equal (c2, test));
gst_caps_unref (test);
gst_caps_unref (c2);
/* and so is this */
@ -444,7 +447,7 @@ GST_END_TEST;
GST_START_TEST (test_merge_subset)
{
GstCaps *c1, *c2;
GstCaps *c1, *c2, *test;
/* the 2nd is already covered */
c2 = gst_caps_from_string ("audio/x-raw-int,channels=[1,2]");
@ -452,7 +455,10 @@ GST_START_TEST (test_merge_subset)
gst_caps_merge (c2, c1);
GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
fail_unless (gst_caps_get_size (c2) == 1, NULL);
test = gst_caps_from_string ("audio/x-raw-int,channels=[1,2]");
fail_unless (gst_caps_is_equal (c2, test));
gst_caps_unref (c2);
gst_caps_unref (test);
/* here it is not */
c2 = gst_caps_from_string ("audio/x-raw-int,channels=1,rate=44100");
@ -460,7 +466,112 @@ GST_START_TEST (test_merge_subset)
gst_caps_merge (c2, c1);
GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
fail_unless (gst_caps_get_size (c2) == 2, NULL);
test = gst_caps_from_string ("audio/x-raw-int,channels=[1,2],rate=44100");
fail_unless (gst_caps_is_equal (c2, test));
gst_caps_unref (c2);
gst_caps_unref (test);
/* second one was already contained in the first one */
c2 = gst_caps_from_string ("audio/x-raw-int,channels=[1,3]");
c1 = gst_caps_from_string ("audio/x-raw-int,channels=[1,2]");
gst_caps_merge (c2, c1);
GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
fail_unless (gst_caps_get_size (c2) == 1, NULL);
test = gst_caps_from_string ("audio/x-raw-int,channels=[1,3]");
fail_unless (gst_caps_is_equal (c2, test));
gst_caps_unref (c2);
gst_caps_unref (test);
/* second one was already contained in the first one */
c2 = gst_caps_from_string ("audio/x-raw-int,channels=[1,4]");
c1 = gst_caps_from_string ("audio/x-raw-int,channels=[1,2]");
gst_caps_merge (c2, c1);
GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
fail_unless (gst_caps_get_size (c2) == 1, NULL);
test = gst_caps_from_string ("audio/x-raw-int,channels=[1,4]");
fail_unless (gst_caps_is_equal (c2, test));
gst_caps_unref (c2);
gst_caps_unref (test);
/* second one was already contained in the first one */
c2 = gst_caps_from_string ("audio/x-raw-int,channels=[1,4]");
c1 = gst_caps_from_string ("audio/x-raw-int,channels=[2,4]");
gst_caps_merge (c2, c1);
GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
fail_unless (gst_caps_get_size (c2) == 1, NULL);
test = gst_caps_from_string ("audio/x-raw-int,channels=[1,4]");
fail_unless (gst_caps_is_equal (c2, test));
gst_caps_unref (c2);
gst_caps_unref (test);
/* second one was already contained in the first one */
c2 = gst_caps_from_string ("audio/x-raw-int,channels=[1,4]");
c1 = gst_caps_from_string ("audio/x-raw-int,channels=[2,3]");
gst_caps_merge (c2, c1);
GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
fail_unless (gst_caps_get_size (c2) == 1, NULL);
test = gst_caps_from_string ("audio/x-raw-int,channels=[1,4]");
fail_unless (gst_caps_is_equal (c2, test));
gst_caps_unref (c2);
gst_caps_unref (test);
/* these caps cannot be merged */
c2 = gst_caps_from_string ("audio/x-raw-int,channels=[2,3]");
c1 = gst_caps_from_string ("audio/x-raw-int,channels=[1,4]");
gst_caps_merge (c2, c1);
GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
fail_unless (gst_caps_get_size (c2) == 2, NULL);
test =
gst_caps_from_string
("audio/x-raw-int,channels=[2,3];audio/x-raw-int,channels=[1,4]");
fail_unless (gst_caps_is_equal (c2, test));
gst_caps_unref (c2);
gst_caps_unref (test);
/* these caps cannot be merged */
c2 = gst_caps_from_string ("audio/x-raw-int,channels=[1,2]");
c1 = gst_caps_from_string ("audio/x-raw-int,channels=[1,3]");
gst_caps_merge (c2, c1);
GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
fail_unless (gst_caps_get_size (c2) == 2, NULL);
test =
gst_caps_from_string
("audio/x-raw-int,channels=[1,2];audio/x-raw-int,channels=[1,3]");
fail_unless (gst_caps_is_equal (c2, test));
gst_caps_unref (c2);
gst_caps_unref (test);
c2 = gst_caps_from_string ("audio/x-raw-int,channels={1,2}");
c1 = gst_caps_from_string ("audio/x-raw-int,channels={1,2,3,4}");
gst_caps_merge (c2, c1);
GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
fail_unless (gst_caps_get_size (c2) == 2, NULL);
test = gst_caps_from_string ("audio/x-raw-int,channels={1,2};"
"audio/x-raw-int,channels={1,2,3,4}");
fail_unless (gst_caps_is_equal (c2, test));
gst_caps_unref (c2);
gst_caps_unref (test);
c2 = gst_caps_from_string ("audio/x-raw-int,channels={1,2}");
c1 = gst_caps_from_string ("audio/x-raw-int,channels={1,3}");
gst_caps_merge (c2, c1);
GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
fail_unless (gst_caps_get_size (c2) == 2, NULL);
test = gst_caps_from_string ("audio/x-raw-int,channels={1,2};"
"audio/x-raw-int,channels={1,3}");
fail_unless (gst_caps_is_equal (c2, test));
gst_caps_unref (c2);
gst_caps_unref (test);
c2 = gst_caps_from_string
("video/x-raw-yuv, framerate=(fraction){ 15/2, 5/1 }");
c1 = gst_caps_from_string
("video/x-raw-yuv, framerate=(fraction){ 15/1, 5/1 }");
test = gst_caps_copy (c1);
gst_caps_merge (c2, c1);
GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2);
fail_unless (gst_caps_is_subset (test, c2));
gst_caps_unref (test);
gst_caps_unref (c2);
}

View file

@ -1506,6 +1506,54 @@ GST_START_TEST (test_value_subtract_fraction_range)
GST_END_TEST;
/* Test set subtraction operations on fraction lists */
GST_START_TEST (test_value_subtract_fraction_list)
{
GValue list1 = { 0 };
GValue list2 = { 0 };
GValue val1 = { 0 };
GValue val2 = { 0 };
GValue tmp = { 0 };
gboolean ret;
g_value_init (&list1, GST_TYPE_LIST);
g_value_init (&val1, GST_TYPE_FRACTION);
gst_value_set_fraction (&val1, 15, 2);
gst_value_list_append_value (&list1, &val1);
g_value_init (&tmp, GST_TYPE_FRACTION);
gst_value_set_fraction (&tmp, 5, 1);
gst_value_list_append_value (&list1, &tmp);
g_value_unset (&tmp);
g_value_init (&list2, GST_TYPE_LIST);
g_value_init (&val2, GST_TYPE_FRACTION);
gst_value_set_fraction (&val2, 15, 1);
gst_value_list_append_value (&list2, &val2);
g_value_init (&tmp, GST_TYPE_FRACTION);
gst_value_set_fraction (&tmp, 5, 1);
gst_value_list_append_value (&list2, &tmp);
g_value_unset (&tmp);
/* should subtract all common elements */
ret = gst_value_subtract (&tmp, &list1, &list2);
fail_unless (ret == TRUE);
fail_unless (gst_value_compare (&tmp, &val1) == GST_VALUE_EQUAL);
g_value_unset (&val1);
g_value_unset (&tmp);
ret = gst_value_subtract (&tmp, &list2, &list1);
fail_unless (ret == TRUE);
fail_unless (gst_value_compare (&tmp, &val2) == GST_VALUE_EQUAL);
g_value_unset (&val2);
g_value_unset (&tmp);
g_value_unset (&list1);
g_value_unset (&list2);
}
GST_END_TEST;
GST_START_TEST (test_date)
{
GstStructure *s;
@ -1726,6 +1774,7 @@ gst_value_suite (void)
tcase_add_test (tc_chain, test_value_subtract_double);
tcase_add_test (tc_chain, test_value_subtract_fraction);
tcase_add_test (tc_chain, test_value_subtract_fraction_range);
tcase_add_test (tc_chain, test_value_subtract_fraction_list);
tcase_add_test (tc_chain, test_date);
tcase_add_test (tc_chain, test_fraction_range);
tcase_add_test (tc_chain, test_serialize_deserialize_caps);