Simplify gschema-compile test suite

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

Bug #616276.
This commit is contained in:
Matthias Clasen 2010-04-20 23:28:49 -04:00
parent 463203ee0a
commit afff087785
8 changed files with 85 additions and 28 deletions

View 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,6 +537,13 @@ main (int argc, char **argv)
target = g_build_filename (targetdir, "gschemas.compiled", NULL);
files = g_ptr_array_new ();
if (one_schema_file)
{
g_ptr_array_add (files, one_schema_file);
}
else
{
dir = g_dir_open (srcdir, 0, &error);
if (dir == NULL)
{
@ -535,29 +551,29 @@ main (int argc, char **argv)
return 1;
}
files = g_ptr_array_new ();
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;
}

View File

@ -154,12 +154,12 @@ 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
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

View File

@ -0,0 +1,7 @@
<schemalist>
<schema id="bad-type" path="/tests/">
<key name="test" type="-%$#*(a!">
<default></default>
</key>
</schema>
</schemalist>

View File

@ -0,0 +1,7 @@
<schemalist>
<schema id="incomplete-list" path="/tests/">
<key name="test" type="ai">
<default>[1,2,3</default>
</key>
</schema>
</schemalist>

View File

@ -0,0 +1,7 @@
<schemalist>
<schema id="missing-quotes" path="/tests/">
<key name="test" type="s">
<default>foo</default>
</key>
</schema>
</schemalist>

View File

@ -0,0 +1,6 @@
<schemalist>
<schema id="no-default" path="/tests/">
<key name="test" type="s">
</key>
</schema>
</schemalist>

View File

@ -0,0 +1,7 @@
<schemalist>
<schema id="test">
<key name="test" type="y">
<default>512</default>
</key>
</schema>
</schemalist>

View File

@ -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>