From 52864794671e00e169b8c70ac957c9ae8efa8b80 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sebastian=20Dr=C3=B6ge?= Date: Wed, 13 Nov 2013 19:55:41 +0100 Subject: [PATCH] value: Lists with all equal elements are equal to a single value Otherwise caps containing f={X, X} are not compatible with f=X https://bugzilla.gnome.org/show_bug.cgi?id=709253 --- gst/gstvalue.c | 39 +++++++++++++++++++++++++++++++++------ tests/check/gst/gstcaps.c | 23 ++++++++++++++++++++++- 2 files changed, 55 insertions(+), 7 deletions(-) diff --git a/gst/gstvalue.c b/gst/gstvalue.c index 9dadb85912..ad9b353cf6 100644 --- a/gst/gstvalue.c +++ b/gst/gstvalue.c @@ -4466,24 +4466,51 @@ gst_value_compare (const GValue * value1, const GValue * value2) as well as lists and ranges ("{ 1, 2 }" and "[ 1, 2 ]" are equal) */ ltype = gst_value_list_get_type (); if (G_VALUE_HOLDS (value1, ltype) && !G_VALUE_HOLDS (value2, ltype)) { + gint i, n, ret; if (gst_value_list_equals_range (value1, value2)) { return GST_VALUE_EQUAL; - } else if (gst_value_list_get_size (value1) == 1) { + } + + n = gst_value_list_get_size (value1); + if (n == 0) + return GST_VALUE_UNORDERED; + + for (i = 0; i < n; i++) { const GValue *elt; - elt = gst_value_list_get_value (value1, 0); - return gst_value_compare (elt, value2); + elt = gst_value_list_get_value (value1, i); + ret = gst_value_compare (elt, value2); + if (ret != GST_VALUE_EQUAL && n == 1) + return ret; + else if (ret != GST_VALUE_EQUAL) + return GST_VALUE_UNORDERED; } + + return GST_VALUE_EQUAL; } else if (G_VALUE_HOLDS (value2, ltype) && !G_VALUE_HOLDS (value1, ltype)) { + gint i, n, ret; + if (gst_value_list_equals_range (value2, value1)) { return GST_VALUE_EQUAL; - } else if (gst_value_list_get_size (value2) == 1) { + } + + n = gst_value_list_get_size (value2); + if (n == 0) + return GST_VALUE_UNORDERED; + + for (i = 0; i < n; i++) { const GValue *elt; - elt = gst_value_list_get_value (value2, 0); - return gst_value_compare (elt, value1); + elt = gst_value_list_get_value (value2, i); + ret = gst_value_compare (elt, value1); + if (ret != GST_VALUE_EQUAL && n == 1) + return ret; + else if (ret != GST_VALUE_EQUAL) + return GST_VALUE_UNORDERED; } + + return GST_VALUE_EQUAL; } if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2)) diff --git a/tests/check/gst/gstcaps.c b/tests/check/gst/gstcaps.c index 0f1bcb2298..4d26462345 100644 --- a/tests/check/gst/gstcaps.c +++ b/tests/check/gst/gstcaps.c @@ -340,9 +340,30 @@ GST_START_TEST (test_subset_duplication) GstCaps *c1, *c2; c1 = gst_caps_from_string ("audio/x-raw, format=(string)F32LE"); + c2 = gst_caps_from_string ("audio/x-raw, format=(string)F32LE"); + + fail_unless (gst_caps_is_subset (c1, c2)); + fail_unless (gst_caps_is_subset (c2, c1)); + + gst_caps_unref (c2); + c2 = gst_caps_from_string ("audio/x-raw, format=(string){ F32LE }"); + + fail_unless (gst_caps_is_subset (c1, c2)); + fail_unless (gst_caps_is_subset (c2, c1)); + + gst_caps_unref (c2); c2 = gst_caps_from_string ("audio/x-raw, format=(string){ F32LE, F32LE }"); fail_unless (gst_caps_is_subset (c1, c2)); + fail_unless (gst_caps_is_subset (c2, c1)); + + gst_caps_unref (c2); + c2 = gst_caps_from_string + ("audio/x-raw, format=(string){ F32LE, F32LE, F32LE }"); + + fail_unless (gst_caps_is_subset (c1, c2)); + fail_unless (gst_caps_is_subset (c2, c1)); + gst_caps_unref (c1); gst_caps_unref (c2); } @@ -1111,7 +1132,7 @@ gst_caps_suite (void) tcase_add_test (tc_chain, test_simplify); tcase_add_test (tc_chain, test_truncate); tcase_add_test (tc_chain, test_subset); - tcase_skip_broken_test (tc_chain, test_subset_duplication); + tcase_add_test (tc_chain, test_subset_duplication); tcase_add_test (tc_chain, test_merge_fundamental); tcase_add_test (tc_chain, test_merge_same); tcase_add_test (tc_chain, test_merge_subset); -- 2.34.1