validate: Cleanup flags/enum_from_string
authorThibault Saunier <tsaunier@igalia.com>
Fri, 1 Feb 2019 21:41:07 +0000 (18:41 -0300)
committerMathieu Duponchelle <mduponchelle1@gmail.com>
Fri, 1 Feb 2019 23:46:21 +0000 (23:46 +0000)
validate/gst/validate/gst-validate-scenario.c
validate/gst/validate/gst-validate-utils.c

index 9723ff8..74e5d20 100644 (file)
@@ -1123,8 +1123,7 @@ execute_switch_track_pb (GstValidateScenario * scenario,
   if (!(type = gst_structure_get_string (action->structure, "type")))
     type = "audio";
 
-  tflag =
-      gst_validate_utils_flags_from_str (g_type_from_name ("GstPlayFlags"),
+  tflag = gst_validate_utils_flags_from_str (g_type_from_name ("GstPlayFlags"),
       type);
   current_txt = g_strdup_printf ("current-%s", type);
 
@@ -2897,7 +2896,6 @@ _load_scenario_file (GstValidateScenario * scenario,
     const gchar *type;
     GstStructure *structure = (GstStructure *) tmp->data;
 
-
     type = gst_structure_get_name (structure);
     if (!g_strcmp0 (type, "description")) {
       const gchar *pipeline_name;
index af8486b..15de102 100644 (file)
@@ -495,19 +495,18 @@ gst_validate_utils_parse_expression (const gchar * expr,
 guint
 gst_validate_utils_flags_from_str (GType type, const gchar * str_flags)
 {
-  guint i;
-  gint flags = 0;
-  GFlagsClass *class = g_type_class_ref (type);
+  guint flags;
+  GValue value = G_VALUE_INIT;
+  g_value_init (&value, type);
 
-  for (i = 0; i < class->n_values; i++) {
-    if (class->values[i].value_nick == NULL)
-      continue;
+  if (!gst_value_deserialize (&value, str_flags)) {
+    g_error ("Invalid flags: %s", str_flags);
 
-    if (g_strrstr (str_flags, class->values[i].value_nick)) {
-      flags |= class->values[i].value;
-    }
+    return 0;
   }
-  g_type_class_unref (class);
+
+  flags = g_value_get_flags (&value);
+  g_value_unset (&value);
 
   return flags;
 }
@@ -524,20 +523,19 @@ gboolean
 gst_validate_utils_enum_from_str (GType type, const gchar * str_enum,
     guint * enum_value)
 {
-  guint i;
-  GEnumClass *class = g_type_class_ref (type);
-  gboolean ret = FALSE;
+  GValue value = G_VALUE_INIT;
+  g_value_init (&value, type);
 
-  for (i = 0; i < class->n_values; i++) {
-    if (g_strrstr (str_enum, class->values[i].value_nick)) {
-      *enum_value = class->values[i].value;
-      ret = TRUE;
-    }
+  if (!gst_value_deserialize (&value, str_enum)) {
+    g_error ("Invalid enum: %s", str_enum);
+
+    return FALSE;
   }
 
-  g_type_class_unref (class);
+  *enum_value = g_value_get_enum (&value);
+  g_value_unset (&value);
 
-  return ret;
+  return TRUE;
 }
 
 /* Parse file that contains a list of GStructures */