[gtk+] tests: Make css-parser test take files as argument



commit 796d593cc11ae919e1479ac1e2edffbfd33b9c27
Author: Benjamin Otte <otte redhat com>
Date:   Sun Apr 10 01:53:43 2011 +0200

    tests: Make css-parser test take files as argument
    
    Takes the css files to be tested as argument and runs with it.

 tests/css/parser/test-css-parser.c |  105 +++++++++++++++++++++++------------
 1 files changed, 69 insertions(+), 36 deletions(-)
---
diff --git a/tests/css/parser/test-css-parser.c b/tests/css/parser/test-css-parser.c
index e105436..5756f6e 100644
--- a/tests/css/parser/test-css-parser.c
+++ b/tests/css/parser/test-css-parser.c
@@ -225,15 +225,57 @@ test_css_file (GFile *file)
   g_free (css_file);
 }
 
-int
-main (int argc, char **argv)
+static void
+add_test_for_file (GFile *file)
+{
+  g_test_add_vtable (g_file_get_path (file),
+                     0,
+                     g_object_ref (file),
+                     NULL,
+                     (GTestFixtureFunc) test_css_file,
+                     (GTestFixtureFunc) g_object_unref);
+}
+
+static void
+add_tests_for_files_in_directory (GFile *dir)
 {
-  const char *basedir;
-  GError *error = NULL;
-  GFile *dir;
   GFileEnumerator *enumerator;
   GFileInfo *info;
+  GError *error = NULL;
+
+  enumerator = g_file_enumerate_children (dir, G_FILE_ATTRIBUTE_STANDARD_NAME, 0, NULL, &error);
+  g_assert_no_error (error);
+
+  while ((info = g_file_enumerator_next_file (enumerator, NULL, &error)))
+    {
+      GFile *file;
+      const char *filename;
+
+      filename = g_file_info_get_name (info);
+
+      if (!g_str_has_suffix (filename, ".css") ||
+          g_str_has_suffix (filename, ".out.css") ||
+          g_str_has_suffix (filename, ".ref.css"))
+        {
+          g_object_unref (info);
+          continue;
+        }
+
+      file = g_file_get_child (dir, filename);
+
+      add_test_for_file (file);
 
+      g_object_unref (file);
+      g_object_unref (info);
+    }
+  
+  g_assert_no_error (error);
+  g_object_unref (enumerator);
+}
+
+int
+main (int argc, char **argv)
+{
   gtk_test_init (&argc, &argv);
 
   /* Add a bunch of properties so we can test that we parse them properly */
@@ -327,44 +369,35 @@ main (int argc, char **argv)
                                                               GTK_STATE_FLAG_NORMAL,
                                                               G_PARAM_READABLE));
 
-  if (g_getenv ("srcdir"))
-    basedir = g_getenv ("srcdir");
+  if (argc < 2)
+    {
+      const char *basedir;
+      GFile *dir;
+
+      if (g_getenv ("srcdir"))
+        basedir = g_getenv ("srcdir");
+      else
+        basedir = ".";
+        
+      dir = g_file_new_for_path (basedir);
+      
+      add_tests_for_files_in_directory (dir);
+
+      g_object_unref (dir);
+    }
   else
-    basedir = ".";
-    
-  dir = g_file_new_for_path (basedir);
-  enumerator = g_file_enumerate_children (dir, G_FILE_ATTRIBUTE_STANDARD_NAME, 0, NULL, &error);
-  g_assert_no_error (error);
-
-  while ((info = g_file_enumerator_next_file (enumerator, NULL, &error)))
     {
-      GFile *file;
-      const char *filename;
+      guint i;
 
-      filename = g_file_info_get_name (info);
-
-      if (!g_str_has_suffix (filename, ".css") ||
-          g_str_has_suffix (filename, ".out.css") ||
-          g_str_has_suffix (filename, ".ref.css"))
+      for (i = 1; i < argc; i++)
         {
-          g_object_unref (info);
-          continue;
-        }
+          GFile *file = g_file_new_for_commandline_arg (argv[i]);
 
-      file = g_file_get_child (dir, filename);
-
-      g_test_add_vtable (g_file_get_path (file),
-                         0,
-                         file,
-                         NULL,
-                         (GTestFixtureFunc) test_css_file,
-                         (GTestFixtureFunc) g_object_unref);
+          add_test_for_file (file);
 
-      g_object_unref (info);
+          g_object_unref (file);
+        }
     }
-  
-  g_assert_no_error (error);
-  g_object_unref (enumerator);
 
   return g_test_run ();
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]