[glib] Simplify gschema-compile test suite



commit afff087785e1206c4a112367aaf3445dd5cf0c08
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Apr 20 23:28:49 2010 -0400

    Simplify gschema-compile test suite
    
    Add --one-schema-file option to gschema-compile to allow easier test
    setup. Simplify the test setup.
    
    Bug #616276.

 gio/gschema-compile.c                              |   52 +++++++++++++-------
 gio/tests/Makefile.am                              |   20 ++++----
 gio/tests/schema-tests/bad-type.gschema.xml        |    7 +++
 gio/tests/schema-tests/incomplete-list.gschema.xml |    7 +++
 gio/tests/schema-tests/missing-quotes.gschema.xml  |    7 +++
 gio/tests/schema-tests/no-default.gschema.xml      |    6 ++
 gio/tests/schema-tests/overflow.gschema.xml        |    7 +++
 gio/tests/schema-tests/wrong-category.gschema.xml  |    7 +++
 8 files changed, 85 insertions(+), 28 deletions(-)
---
diff --git a/gio/gschema-compile.c b/gio/gschema-compile.c
index 51c4307..ffeb547 100644
--- a/gio/gschema-compile.c
+++ b/gio/gschema-compile.c
@@ -492,9 +492,16 @@ main (int argc, char **argv)
   gchar *srcdir;
   gchar *targetdir = NULL;
   gchar *target;
+  gboolean dry_run = FALSE;
+  gchar *one_schema_file = NULL;
   GOptionContext *context;
   GOptionEntry entries[] = {
     { "targetdir", 0, 0, G_OPTION_ARG_FILENAME, &targetdir, N_("where to store the gschemas.compiled file"), N_("DIRECTORY") },
+    { "dry-run", 0, 0, G_OPTION_ARG_NONE, &dry_run, N_("Do not write the gschema.compiled file"), NULL },
+
+    /* These options are only for use in the gschema-compile tests */
+    { "one-schema-file", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_FILENAME, &one_schema_file, NULL, NULL },
+
     { NULL }
   };
 
@@ -515,7 +522,9 @@ main (int argc, char **argv)
       return 1;
     }
 
-  if (argc != 2)
+  g_option_context_free (context);
+
+  if (!one_schema_file && argc != 2)
     {
       fprintf (stderr, _("You should give exactly one directory name\n"));
       return 1;
@@ -528,36 +537,43 @@ main (int argc, char **argv)
 
   target = g_build_filename (targetdir, "gschemas.compiled", NULL);
 
-  dir = g_dir_open (srcdir, 0, &error);
-  if (dir == NULL)
-    {
-      fprintf (stderr, "%s\n", error->message);
-      return 1;
-    }
-
   files = g_ptr_array_new ();
-  while ((file = g_dir_read_name (dir)) != NULL)
+  if (one_schema_file)
     {
-      if (g_str_has_suffix (file, ".gschema.xml"))
-	{
-	  g_ptr_array_add (files, g_build_filename (srcdir, file, NULL));
-	}
+      g_ptr_array_add (files, one_schema_file);
     }
-
-  if (files->len == 0)
+  else
     {
-      fprintf (stderr, _("No schema files found\n"));
-      return 1;
+      dir = g_dir_open (srcdir, 0, &error);
+      if (dir == NULL)
+        {
+          fprintf (stderr, "%s\n", error->message);
+          return 1;
+        }
+
+      while ((file = g_dir_read_name (dir)) != NULL)
+        {
+          if (g_str_has_suffix (file, ".gschema.xml"))
+            g_ptr_array_add (files, g_build_filename (srcdir, file, NULL));
+        }
+
+      if (files->len == 0)
+        {
+          fprintf (stderr, _("No schema files found\n"));
+          return 1;
+        }
     }
 
   g_ptr_array_add (files, NULL);
 
   if (!(table = parse_gschema_files ((gchar **) files->pdata, byteswap, &error)) ||
-      !gvdb_table_write_contents (table, target, byteswap, &error))
+      (!dry_run && !gvdb_table_write_contents (table, target, byteswap, &error)))
     {
       fprintf (stderr, "%s\n", error->message);
       return 1;
     }
 
+  g_free (target);
+
   return 0;
 }
diff --git a/gio/tests/Makefile.am b/gio/tests/Makefile.am
index 4f38a84..88c69b2 100644
--- a/gio/tests/Makefile.am
+++ b/gio/tests/Makefile.am
@@ -150,16 +150,16 @@ gsettings_LDADD		  = $(progs_ldadd)
 gschema_compile_SOURCES	  = gschema-compile.c
 gschema_compile_LDADD	  = $(progs_ldadd)
 
-EXTRA_DIST +=                                          \
-	org.gtk.test.gschema                           \
-	org.gtk.test.gschema.xml                       \
-	de.po                                          \
-	schema-tests/bad-type/test.gschema.xml         \
-	schema-tests/incomplete-list/test.gschema.xml  \
-	schema-tests/missing-quotes/test.gschema.xml   \
-	schema-tests/no-default/test.gschema.xml       \
-	schema-tests/wrong-category/test.gschema.xml   \
-	schema-tests/overflow/test.gschema.xml
+EXTRA_DIST +=                                     \
+	org.gtk.test.gschema                      \
+	org.gtk.test.gschema.xml                  \
+	de.po                                     \
+	schema-tests/bad-type.gschema.xml         \
+	schema-tests/incomplete-list.gschema.xml  \
+	schema-tests/missing-quotes.gschema.xml   \
+	schema-tests/no-default.gschema.xml       \
+	schema-tests/wrong-category.gschema.xml   \
+	schema-tests/overflow.gschema.xml
 
 MISC_STUFF = gschemas.compiled test.mo
 
diff --git a/gio/tests/schema-tests/bad-type.gschema.xml b/gio/tests/schema-tests/bad-type.gschema.xml
new file mode 100644
index 0000000..9b74684
--- /dev/null
+++ b/gio/tests/schema-tests/bad-type.gschema.xml
@@ -0,0 +1,7 @@
+<schemalist>
+  <schema id="bad-type" path="/tests/">
+    <key name="test" type="-%$#*(a!">
+      <default></default>
+    </key>
+  </schema>
+</schemalist>
diff --git a/gio/tests/schema-tests/incomplete-list.gschema.xml b/gio/tests/schema-tests/incomplete-list.gschema.xml
new file mode 100644
index 0000000..df33e84
--- /dev/null
+++ b/gio/tests/schema-tests/incomplete-list.gschema.xml
@@ -0,0 +1,7 @@
+<schemalist>
+  <schema id="incomplete-list" path="/tests/">
+    <key name="test" type="ai">
+      <default>[1,2,3</default>
+    </key>
+  </schema>
+</schemalist>
diff --git a/gio/tests/schema-tests/missing-quotes.gschema.xml b/gio/tests/schema-tests/missing-quotes.gschema.xml
new file mode 100644
index 0000000..4400a62
--- /dev/null
+++ b/gio/tests/schema-tests/missing-quotes.gschema.xml
@@ -0,0 +1,7 @@
+<schemalist>
+  <schema id="missing-quotes" path="/tests/">
+    <key name="test" type="s">
+      <default>foo</default>
+    </key>
+  </schema>
+</schemalist>
diff --git a/gio/tests/schema-tests/no-default.gschema.xml b/gio/tests/schema-tests/no-default.gschema.xml
new file mode 100644
index 0000000..5496ce3
--- /dev/null
+++ b/gio/tests/schema-tests/no-default.gschema.xml
@@ -0,0 +1,6 @@
+<schemalist>
+  <schema id="no-default" path="/tests/">
+    <key name="test" type="s">
+    </key>
+  </schema>
+</schemalist>
diff --git a/gio/tests/schema-tests/overflow.gschema.xml b/gio/tests/schema-tests/overflow.gschema.xml
new file mode 100644
index 0000000..19d4176
--- /dev/null
+++ b/gio/tests/schema-tests/overflow.gschema.xml
@@ -0,0 +1,7 @@
+<schemalist>
+    <schema id="test">
+      <key name="test" type="y">
+        <default>512</default>
+      </key>
+    </schema>
+</schemalist>
diff --git a/gio/tests/schema-tests/wrong-category.gschema.xml b/gio/tests/schema-tests/wrong-category.gschema.xml
new file mode 100644
index 0000000..5c1ec79
--- /dev/null
+++ b/gio/tests/schema-tests/wrong-category.gschema.xml
@@ -0,0 +1,7 @@
+<schemalist>
+  <schema id="wrong-category" path="/tests/" gettext-domain="test">
+    <key name="test" type="s" l10n="not-a-category">
+      <default>'foo'</default>
+    </key>
+  </schema>
+</schemalist>



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