validate:scenario: Enhance the set_property action to handle enum props
authorThibault Saunier <thibault.saunier@osg.samsung.com>
Fri, 30 Jun 2017 13:46:57 +0000 (09:46 -0400)
committerThibault Saunier <thibault.saunier@osg.samsung.com>
Fri, 30 Jun 2017 13:46:57 +0000 (09:46 -0400)
User needs to specify the enum value as a string, to be used
as with gst_util_set_object_arg.

Also enhance reporting and verify that the set value has actually
been taken into account.

validate/gst/validate/gst-validate-scenario.c

index 57d92be..5b271b6 100644 (file)
@@ -2328,12 +2328,15 @@ _get_target_elements_by_klass (GstValidateScenario * scenario,
   return result;
 }
 
-static gboolean
-_object_set_property (GObject * object, const gchar * property,
+static GstValidateActionReturn
+_object_set_property (GstValidateScenario * scenario,
+    GObject * object, const gchar * property,
     const GValue * value, gboolean optional)
 {
-  GObjectClass *klass = G_OBJECT_GET_CLASS (object);
   GParamSpec *paramspec;
+  GObjectClass *klass = G_OBJECT_GET_CLASS (object);
+  GstValidateExecuteActionReturn res = GST_VALIDATE_EXECUTE_ACTION_OK;
+  GValue cvalue = G_VALUE_INIT, nvalue = G_VALUE_INIT;
 
   paramspec = g_object_class_find_property (klass, property);
   if (paramspec == NULL) {
@@ -2343,9 +2346,49 @@ _object_set_property (GObject * object, const gchar * property,
     return FALSE;
   }
 
-  g_object_set_property (object, property, value);
+  g_value_init (&cvalue, paramspec->value_type);
+  if (paramspec->value_type != G_VALUE_TYPE (value) &&
+      (G_VALUE_TYPE (value) == G_TYPE_STRING)) {
+    if (!gst_value_deserialize (&cvalue, g_value_get_string (value))) {
+      GST_VALIDATE_REPORT (scenario, SCENARIO_ACTION_EXECUTION_ERROR,
+          "Could not set %" GST_PTR_FORMAT "::%s as value %s"
+          " could not be deserialize to %s", object, property,
+          g_value_get_string (value), G_PARAM_SPEC_TYPE_NAME (paramspec));
 
-  return TRUE;
+      return GST_VALIDATE_EXECUTE_ACTION_ERROR_REPORTED;
+    }
+  } else {
+    if (!g_value_transform (value, &cvalue)) {
+      GST_VALIDATE_REPORT (scenario, SCENARIO_ACTION_EXECUTION_ERROR,
+          "Could not set %" GST_PTR_FORMAT " property %s to type %s"
+          " (wanted type %s)", object, property, G_VALUE_TYPE_NAME (value),
+          G_PARAM_SPEC_TYPE_NAME (paramspec));
+
+      return GST_VALIDATE_EXECUTE_ACTION_ERROR_REPORTED;
+    }
+
+  }
+
+  g_object_set_property (object, property, &cvalue);
+
+  g_value_init (&nvalue, paramspec->value_type);
+  g_object_get_property (object, property, &nvalue);
+
+  if (gst_value_compare (&cvalue, &nvalue) != GST_VALUE_EQUAL) {
+    gchar *nvalstr = gst_value_serialize (&nvalue);
+    gchar *cvalstr = gst_value_serialize (&cvalue);
+    GST_VALIDATE_REPORT (scenario, SCENARIO_ACTION_EXECUTION_ERROR,
+        "Setting value %" GST_PTR_FORMAT "::%s failed, expected value: %s"
+        " value after setting %s", object, property, cvalstr, nvalstr);
+
+    res = GST_VALIDATE_EXECUTE_ACTION_ERROR_REPORTED;
+    g_free (nvalstr);
+    g_free (cvalstr);
+  }
+
+  g_value_reset (&cvalue);
+  g_value_reset (&nvalue);
+  return res;
 }
 
 static gboolean
@@ -2380,9 +2423,11 @@ _execute_set_property (GstValidateScenario * scenario,
       "property-value");
 
   for (l = targets; l != NULL; l = g_list_next (l)) {
-    if (!_object_set_property (G_OBJECT (l->data), property, property_value,
-            action->priv->optional))
-      ret = FALSE;
+    GstValidateActionReturn tmpres = _object_set_property (scenario,
+        G_OBJECT (l->data), property, property_value, action->priv->optional);
+
+    if (!tmpres)
+      ret = tmpres;
   }
 
   g_list_free_full (targets, gst_object_unref);
@@ -3234,7 +3279,7 @@ _element_added_cb (GstBin * bin, GstElement * element,
       GstValidateActionType *action_type;
       action_type = _find_action_type (action->type);
       GST_DEBUG_OBJECT (element, "Executing set-property action");
-      if (action_type->execute (scenario, action)) {
+      if (gst_validate_execute_action (action_type, action)) {
         priv->on_addition_actions =
             g_list_remove_link (priv->on_addition_actions, tmp);
         gst_mini_object_unref (GST_MINI_OBJECT (action));