value: Handle NULL caps for comparisons
authorThibault Saunier <tsaunier@igalia.com>
Fri, 13 Mar 2020 19:41:52 +0000 (16:41 -0300)
committerTim-Philipp Müller <tim@centricular.com>
Sat, 14 Mar 2020 00:35:10 +0000 (00:35 +0000)
Having a NULL caps in a GValue is legal and we should handle it
properly for comparisons.

gst/gstvalue.c
tests/check/gst/gstvalue.c

index 30f5b77a2fa9f96c8a692081fb4cc1390daa63b8..cdbd7eff649a37c22ca8208158cddd9e460b7c3e 100644 (file)
@@ -2087,6 +2087,12 @@ gst_value_compare_caps (const GValue * value1, const GValue * value2)
   GstCaps *caps1 = GST_CAPS (gst_value_get_caps (value1));
   GstCaps *caps2 = GST_CAPS (gst_value_get_caps (value2));
 
+  if (caps1 == caps2)
+    return GST_VALUE_EQUAL;
+
+  if (!caps1 || !caps2)
+    return GST_VALUE_UNORDERED;
+
   if (gst_caps_is_equal (caps1, caps2))
     return GST_VALUE_EQUAL;
   return GST_VALUE_UNORDERED;
index eb1634d4f3f03a0aa09a3cf781bc89f35c3bbc9e..adbcc2e4b40a63cd38eebf5b63639d901cf0a50e 100644 (file)
@@ -2720,6 +2720,31 @@ GST_START_TEST (test_serialize_deserialize_value_array)
 
 GST_END_TEST;
 
+GST_START_TEST (test_compare_caps)
+{
+  GValue value = { 0 }
+  , value2 = {
+  0};
+
+  g_value_init (&value, GST_TYPE_CAPS);
+  g_value_init (&value2, GST_TYPE_CAPS);
+  g_value_take_boxed (&value, NULL);
+  g_value_take_boxed (&value2, NULL);
+
+  fail_unless_equals_int (gst_value_compare (&value, &value2), GST_VALUE_EQUAL);
+
+  g_value_take_boxed (&value, gst_caps_new_empty_simple ("something"));
+
+  fail_unless_equals_int (gst_value_compare (&value, &value2),
+      GST_VALUE_UNORDERED);
+
+  g_value_unset (&value);
+  g_value_unset (&value2);
+
+}
+
+GST_END_TEST;
+
 GST_START_TEST (test_serialize_deserialize_caps)
 {
   GValue value = { 0 }
@@ -3510,6 +3535,7 @@ gst_value_suite (void)
   tcase_add_test (tc_chain, test_date_time);
   tcase_add_test (tc_chain, test_fraction_range);
   tcase_add_test (tc_chain, test_serialize_deserialize_caps);
+  tcase_add_test (tc_chain, test_compare_caps);
   tcase_add_test (tc_chain, test_int_range);
   tcase_add_test (tc_chain, test_int64_range);
   tcase_add_test (tc_chain, test_serialize_int64_range);