Simplify gschema-compile test suite
authorMatthias Clasen <mclasen@redhat.com>
Wed, 21 Apr 2010 03:28:49 +0000 (23:28 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Wed, 21 Apr 2010 03:28:49 +0000 (23:28 -0400)
Add --one-schema-file option to gschema-compile to allow easier test
setup. Simplify the test setup.

Bug #616276.

gio/gschema-compile.c
gio/tests/Makefile.am
gio/tests/schema-tests/bad-type.gschema.xml [new file with mode: 0644]
gio/tests/schema-tests/incomplete-list.gschema.xml [new file with mode: 0644]
gio/tests/schema-tests/missing-quotes.gschema.xml [new file with mode: 0644]
gio/tests/schema-tests/no-default.gschema.xml [new file with mode: 0644]
gio/tests/schema-tests/overflow.gschema.xml [new file with mode: 0644]
gio/tests/schema-tests/wrong-category.gschema.xml [new file with mode: 0644]

index 51c4307..ffeb547 100644 (file)
@@ -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;
 }
index 4f38a84..88c69b2 100644 (file)
@@ -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 (file)
index 0000000..9b74684
--- /dev/null
@@ -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 (file)
index 0000000..df33e84
--- /dev/null
@@ -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 (file)
index 0000000..4400a62
--- /dev/null
@@ -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 (file)
index 0000000..5496ce3
--- /dev/null
@@ -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 (file)
index 0000000..19d4176
--- /dev/null
@@ -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 (file)
index 0000000..5c1ec79
--- /dev/null
@@ -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>