Commit 7e610042 authored by Jan Schmidt's avatar Jan Schmidt
Browse files

Make GstValueArray comparison be order dependent as designed.

Original commit message from CVS:
* 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
parent 4f9d5adb
2006-07-11 Jan Schmidt <thaytan@mad.scientist.com>
* 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 <edward@fluendo.com>
* gst/gstbin.c: (activate_pads),
......
......@@ -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,
};
......
......@@ -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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment