diff --git a/ChangeLog b/ChangeLog index 290471f7e5..df4b917945 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2006-07-11 Jan Schmidt + + * gst/gstvalue.c: (gst_value_compare_list), + (gst_value_compare_array), (_gst_value_initialize): + * tests/check/gst/gstvalue.c: (GST_START_TEST): + Make GstValueArray comparison be order dependent as designed. + Add checks for value lists and value array comparisons. + Fixes #347221 + 2006-07-11 Edward Hervey * gst/gstbin.c: (activate_pads), diff --git a/gst/gstvalue.c b/gst/gstvalue.c index d455359623..f1748eb22b 100644 --- a/gst/gstvalue.c +++ b/gst/gstvalue.c @@ -456,8 +456,9 @@ gst_value_transform_array_string (const GValue * src_value, GValue * dest_value) gst_value_transform_any_list_string (src_value, dest_value, "< ", " >"); } +/* Do an unordered compare of the contents of a list */ static int -gst_value_compare_list_or_array (const GValue * value1, const GValue * value2) +gst_value_compare_list (const GValue * value1, const GValue * value2) { guint i, j; GArray *array1 = value1->data[0].v_pointer; @@ -483,6 +484,29 @@ gst_value_compare_list_or_array (const GValue * value1, const GValue * value2) return GST_VALUE_EQUAL; } +/* Perform an ordered comparison of the contents of an array */ +static int +gst_value_compare_array (const GValue * value1, const GValue * value2) +{ + guint i; + GArray *array1 = value1->data[0].v_pointer; + GArray *array2 = value2->data[0].v_pointer; + GValue *v1; + GValue *v2; + + if (array1->len != array2->len) + return GST_VALUE_UNORDERED; + + for (i = 0; i < array1->len; i++) { + v1 = &g_array_index (array1, GValue, i); + v2 = &g_array_index (array2, GValue, i); + if (gst_value_compare (v1, v2) != GST_VALUE_EQUAL) + return GST_VALUE_UNORDERED; + } + + return GST_VALUE_EQUAL; +} + static gchar * gst_value_serialize_list (const GValue * value) { @@ -3879,7 +3903,7 @@ _gst_value_initialize (void) { static GstValueTable gst_value = { 0, - gst_value_compare_list_or_array, + gst_value_compare_list, gst_value_serialize_list, gst_value_deserialize_list, }; @@ -3891,7 +3915,7 @@ _gst_value_initialize (void) { static GstValueTable gst_value = { 0, - gst_value_compare_list_or_array, + gst_value_compare_array, gst_value_serialize_array, gst_value_deserialize_array, }; diff --git a/tests/check/gst/gstvalue.c b/tests/check/gst/gstvalue.c index efb1bcb424..7303adeda6 100644 --- a/tests/check/gst/gstvalue.c +++ b/tests/check/gst/gstvalue.c @@ -470,6 +470,7 @@ GST_START_TEST (test_value_compare) { GValue value1 = { 0 }; GValue value2 = { 0 }; + GValue tmp = { 0 }; g_value_init (&value1, G_TYPE_INT); g_value_set_int (&value1, 10); @@ -552,6 +553,91 @@ GST_START_TEST (test_value_compare) g_value_unset (&value1); g_value_unset (&value2); + /* Check that lists are equal regardless of order */ + g_value_init (&value1, GST_TYPE_LIST); + g_value_init (&tmp, G_TYPE_INT); + g_value_set_int (&tmp, 1); + gst_value_list_append_value (&value1, &tmp); + g_value_set_int (&tmp, 2); + gst_value_list_append_value (&value1, &tmp); + g_value_set_int (&tmp, 3); + gst_value_list_append_value (&value1, &tmp); + g_value_set_int (&tmp, 4); + gst_value_list_append_value (&value1, &tmp); + + g_value_init (&value2, GST_TYPE_LIST); + g_value_set_int (&tmp, 4); + gst_value_list_append_value (&value2, &tmp); + g_value_set_int (&tmp, 3); + gst_value_list_append_value (&value2, &tmp); + g_value_set_int (&tmp, 2); + gst_value_list_append_value (&value2, &tmp); + g_value_set_int (&tmp, 1); + gst_value_list_append_value (&value2, &tmp); + + fail_unless (gst_value_compare (&value1, &value2) == GST_VALUE_EQUAL, + "value lists with different order were not equal when they should be"); + fail_unless (gst_value_compare (&value1, &value1) == GST_VALUE_EQUAL, + "value lists with same order were not equal when they should be"); + fail_unless (gst_value_compare (&value2, &value2) == GST_VALUE_EQUAL, + "value lists with same order were not equal when they should be"); + + /* Carry over the lists to this next check: */ + /* Lists with different sizes are unequal */ + g_value_set_int (&tmp, 1); + gst_value_list_append_value (&value2, &tmp); + + fail_if (gst_value_compare (&value1, &value2) == GST_VALUE_EQUAL, + "Value lists with different size were equal when they shouldn't be"); + + g_value_unset (&value1); + g_value_unset (&value2); + g_value_unset (&tmp); + + /* Arrays are only equal when in the same order */ + g_value_init (&value1, GST_TYPE_ARRAY); + g_value_init (&tmp, G_TYPE_INT); + g_value_set_int (&tmp, 1); + gst_value_array_append_value (&value1, &tmp); + g_value_set_int (&tmp, 2); + gst_value_array_append_value (&value1, &tmp); + g_value_set_int (&tmp, 3); + gst_value_array_append_value (&value1, &tmp); + g_value_set_int (&tmp, 4); + gst_value_array_append_value (&value1, &tmp); + + g_value_init (&value2, GST_TYPE_ARRAY); + g_value_set_int (&tmp, 4); + gst_value_array_append_value (&value2, &tmp); + g_value_set_int (&tmp, 3); + gst_value_array_append_value (&value2, &tmp); + g_value_set_int (&tmp, 2); + gst_value_array_append_value (&value2, &tmp); + g_value_set_int (&tmp, 1); + gst_value_array_append_value (&value2, &tmp); + + fail_if (gst_value_compare (&value1, &value2) == GST_VALUE_EQUAL, + "Value arrays with different order were equal when they shouldn't be"); + fail_unless (gst_value_compare (&value1, &value1) == GST_VALUE_EQUAL, + "Identical value arrays were not equal when they should be"); + fail_unless (gst_value_compare (&value2, &value2) == GST_VALUE_EQUAL, + "Identical value arrays were not equal when they should be"); + + /* Carry over the arrays to this next check: */ + /* Arrays with different sizes are unequal */ + g_value_unset (&value2); + g_value_init (&value2, GST_TYPE_ARRAY); + g_value_copy (&value1, &value2); + + g_value_set_int (&tmp, 1); + gst_value_array_append_value (&value2, &tmp); + + fail_if (gst_value_compare (&value1, &value2) == GST_VALUE_EQUAL, + "Value arrays with different size were equal when they shouldn't be"); + + g_value_unset (&value1); + g_value_unset (&value2); + g_value_unset (&tmp); } GST_END_TEST;