validate: Allow specifying scenarios to parse when lisiting them
authorThibault Saunier <tsaunier@gnome.org>
Wed, 30 Apr 2014 07:35:03 +0000 (09:35 +0200)
committerThibault Saunier <tsaunier@gnome.org>
Fri, 2 May 2014 16:30:22 +0000 (18:30 +0200)
It used to only handle the scenario present in proper paths, we
also need to handle special scenarios provided by users on the fly

validate/gst/validate/gst-validate-scenario.c
validate/gst/validate/gst-validate-scenario.h
validate/tools/gst-validate-transcoding.c
validate/tools/gst-validate.c

index 636ff4a527387d3809a430e97748e822c54585ec..d0e81da01b147d54a2ed5b343119703714f0c7d2 100644 (file)
@@ -1340,6 +1340,46 @@ _add_description (GQuark field_id, const GValue * value, KeyFileGroupName * kfg)
 }
 
 
+static gboolean
+_parse_scenario (GFile *f, GKeyFile * kf)
+{
+  gboolean ret = FALSE;
+  gchar *fname = g_file_get_basename (f);
+
+  if (g_str_has_suffix (fname, GST_VALIDATE_SCENARIO_SUFFIX)) {
+    GstStructure *desc = NULL;
+
+    gchar **name = g_strsplit (fname, GST_VALIDATE_SCENARIO_SUFFIX, 0);
+    GList *tmp, *structures = _scenario_file_get_structures (f);
+
+    for (tmp = structures; tmp; tmp = tmp->next) {
+      if (gst_structure_has_name (tmp->data, "description")) {
+        desc = tmp->data;
+        break;
+      }
+    }
+
+    if (desc) {
+      KeyFileGroupName kfg;
+
+      kfg.group_name = name[0];
+      kfg.kf = kf;
+
+      gst_structure_foreach (desc,
+          (GstStructureForeachFunc) _add_description, &kfg);
+    } else {
+      g_key_file_set_string (kf, name[0], "noinfo", "nothing");
+    }
+    g_list_free_full (structures, (GDestroyNotify) gst_structure_free);
+    g_strfreev (name);
+
+    ret = TRUE;
+  }
+
+  g_free (fname);
+  return ret;
+}
+
 static void
 _list_scenarios_in_dir (GFile * dir, GKeyFile * kf)
 {
@@ -1354,49 +1394,23 @@ _list_scenarios_in_dir (GFile * dir, GKeyFile * kf)
 
   for (info = g_file_enumerator_next_file (fenum, NULL, NULL);
       info; info = g_file_enumerator_next_file (fenum, NULL, NULL)) {
-    if (g_str_has_suffix (g_file_info_get_name (info),
-            GST_VALIDATE_SCENARIO_SUFFIX)) {
-      gchar **name = g_strsplit (g_file_info_get_name (info),
-          GST_VALIDATE_SCENARIO_SUFFIX, 0);
-
-
-      GstStructure *desc = NULL;
-      GFile *f = g_file_enumerator_get_child (fenum, info);
-      GList *tmp, *structures = _scenario_file_get_structures (f);
-
-      gst_object_unref (f);
-      for (tmp = structures; tmp; tmp = tmp->next) {
-        if (gst_structure_has_name (tmp->data, "description")) {
-          desc = tmp->data;
-          break;
-        }
-      }
+    GFile *f = g_file_enumerator_get_child (fenum, info);
 
-      if (desc) {
-        KeyFileGroupName kfg;
-
-        kfg.group_name = name[0];
-        kfg.kf = kf;
-
-        gst_structure_foreach (desc,
-            (GstStructureForeachFunc) _add_description, &kfg);
-      } else {
-        g_key_file_set_string (kf, name[0], "noinfo", "nothing");
-      }
-      g_list_free_full (structures, (GDestroyNotify) gst_structure_free);
-      g_strfreev (name);
-    }
+    _parse_scenario (f, kf);
+    gst_object_unref (f);
   }
 }
 
 gboolean
-gst_validate_list_scenarios (gchar * output_file)
+gst_validate_list_scenarios (gchar **scenarios, gint num_scenarios,
+    gchar * output_file)
 {
   gchar *result;
-
   gsize datalength;
+
   GError *err = NULL;
   GKeyFile *kf = NULL;
+  gint res = 0;
   const gchar *envvar;
   gchar **env_scenariodir = NULL;
   gchar *tldir = g_build_filename (g_get_user_data_dir (),
@@ -1404,11 +1418,28 @@ gst_validate_list_scenarios (gchar * output_file)
       NULL);
   GFile *dir = g_file_new_for_path (tldir);
 
+  kf = g_key_file_new ();
+  if (num_scenarios > 0) {
+    gint i;
+    GFile *file;
+
+    for (i = 0; i < num_scenarios; i++) {
+      file = g_file_new_for_path (scenarios[i]);
+      if (!_parse_scenario (file, kf)) {
+        GST_ERROR ("Could not parser scenario: %s", scenarios[i]);
+
+        gst_object_unref (file);
+        res = 1;
+      }
+    }
+
+    goto done;
+  }
+
   envvar = g_getenv ("GST_VALIDATE_SCENARIOS_PATH");
   if (envvar)
     env_scenariodir = g_strsplit (envvar, ":", 0);
 
-  kf = g_key_file_new ();
   _list_scenarios_in_dir (dir, kf);
   g_object_unref (dir);
   g_free (tldir);
@@ -1435,6 +1466,7 @@ gst_validate_list_scenarios (gchar * output_file)
   _list_scenarios_in_dir (dir, kf);
   g_object_unref (dir);
 
+done:
   result = g_key_file_to_data (kf, &datalength, &err);
   g_print ("All scenarios avalaible:\n%s", result);
 
@@ -1448,10 +1480,12 @@ gst_validate_list_scenarios (gchar * output_file)
     GST_WARNING ("Got error '%s' listing scenarios", err->message);
     g_clear_error (&err);
 
-    return FALSE;
+    res = FALSE;
   }
 
-  return TRUE;
+  g_key_file_free (kf);
+
+  return res;
 }
 
 static void
index d4881881bf3a0a0f4b2f1e043c1bee57779a5cc4..436873849e8407ff7bce1c1dea141346797a8c61 100644 (file)
@@ -76,7 +76,11 @@ GType gst_validate_scenario_get_type (void);
 GstValidateScenario * gst_validate_scenario_factory_create (GstValidateRunner *runner,
                                                 GstElement *pipeline,
                                                 const gchar *scenario_name);
-gboolean gst_validate_list_scenarios (gchar *output_file);
+gboolean
+gst_validate_list_scenarios       (gchar **scenarios,
+                                   gint num_scenarios,
+                                   gchar * output_file);
+
 void gst_validate_add_action_type (const gchar *type_name, GstValidateExecuteAction function,
                                    const gchar * const * mandatory_fields, const gchar *description,
                                    gboolean is_config);
index 7f412c1de231ff925df65217d17553fa675f3fa7..a9d0bc6c859632d01d9af848f1f55227c5ba5570 100644 (file)
@@ -811,7 +811,7 @@ main (int argc, gchar ** argv)
   gst_validate_init ();
 
   if (list_scenarios || output_file) {
-    if (gst_validate_list_scenarios (output_file))
+    if (gst_validate_list_scenarios (argv + 1, argc - 1, output_file))
         return 1;
     return 0;
   }
index afb03c7335e2c100121c1c8a0593d046b9d55c09..03e9c3237f34e3edb961d90868a8180906853d91 100644 (file)
@@ -328,7 +328,7 @@ main (int argc, gchar ** argv)
   gst_validate_init ();
 
   if (list_scenarios || output_file) {
-    if (gst_validate_list_scenarios (output_file))
+    if (gst_validate_list_scenarios (argv + 1, argc - 1, output_file))
         return 1;
     return 0;
   }