mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-24 22:46:15 +01:00
Add some more schema compiler tests
This commit is contained in:
parent
564714bc95
commit
c83a976245
@ -159,7 +159,12 @@ EXTRA_DIST += \
|
|||||||
schema-tests/missing-quotes.gschema.xml \
|
schema-tests/missing-quotes.gschema.xml \
|
||||||
schema-tests/no-default.gschema.xml \
|
schema-tests/no-default.gschema.xml \
|
||||||
schema-tests/wrong-category.gschema.xml \
|
schema-tests/wrong-category.gschema.xml \
|
||||||
schema-tests/overflow.gschema.xml
|
schema-tests/overflow.gschema.xml \
|
||||||
|
schema-tests/bad-key.gschema.xml \
|
||||||
|
schema-tests/bad-key2.gschema.xml \
|
||||||
|
schema-tests/bad-key3.gschema.xml \
|
||||||
|
schema-tests/bad-key4.gschema.xml \
|
||||||
|
schema-tests/empty-key.gschema.xml
|
||||||
|
|
||||||
MISC_STUFF = gschemas.compiled test.mo
|
MISC_STUFF = gschemas.compiled test.mo
|
||||||
|
|
||||||
|
@ -5,140 +5,65 @@
|
|||||||
#include <gio.h>
|
#include <gio.h>
|
||||||
#include <gstdio.h>
|
#include <gstdio.h>
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
const gchar *name;
|
||||||
|
const gchar *stderr;
|
||||||
|
} SchemaTest;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_no_default (void)
|
test_schema (gpointer data)
|
||||||
{
|
{
|
||||||
g_remove ("gschemas.compiled");
|
SchemaTest *test = (SchemaTest *) data;
|
||||||
|
|
||||||
if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
|
if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
|
||||||
{
|
{
|
||||||
|
gchar *filename = g_strconcat (test->name, ".gschema.xml", NULL);
|
||||||
|
gchar *path = g_build_filename (SRCDIR, "schema-tests", filename, NULL);
|
||||||
gchar *argv[] = {
|
gchar *argv[] = {
|
||||||
"../gschema-compile",
|
"../gschema-compile",
|
||||||
SRCDIR "/schema-tests/no-default/",
|
"--dry-run",
|
||||||
"--targetdir=.",
|
"--one-schema-file", path,
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
gchar *envp[] = { NULL };
|
gchar *envp[] = { NULL };
|
||||||
execve (argv[0], argv, envp);
|
execve (argv[0], argv, envp);
|
||||||
|
g_free (filename);
|
||||||
|
g_free (path);
|
||||||
}
|
}
|
||||||
g_test_trap_assert_failed ();
|
g_test_trap_assert_failed ();
|
||||||
g_test_trap_assert_stderr ("*<default> is required in <key>*");
|
g_test_trap_assert_stderr (test->stderr);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static const SchemaTest tests[] = {
|
||||||
test_missing_quotes (void)
|
{ "no-default", "*<default> is required in <key>*" },
|
||||||
{
|
{ "missing-quotes", "*unknown keyword*" },
|
||||||
g_remove ("gschemas.compiled");
|
{ "incomplete-list", "*to follow array element*" },
|
||||||
|
{ "wrong-category", "*attribute 'l10n' invalid*" },
|
||||||
if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
|
{ "bad-type", "*invalid GVariant type string*" },
|
||||||
{
|
{ "overflow", "*out of range*" },
|
||||||
gchar *argv[] = {
|
{ "bad-key", "*invalid name*" },
|
||||||
"../gschema-compile",
|
{ "bad-key2", "*invalid name*" },
|
||||||
SRCDIR "/schema-tests/missing-quotes/",
|
{ "bad-key3", "*invalid name*" },
|
||||||
"--targetdir=.",
|
{ "bad-key4", "*invalid name*" },
|
||||||
NULL
|
{ "empty-key", "*empty names*" },
|
||||||
};
|
};
|
||||||
gchar *envp[] = { NULL };
|
|
||||||
execve (argv[0], argv, envp);
|
|
||||||
}
|
|
||||||
g_test_trap_assert_failed ();
|
|
||||||
g_test_trap_assert_stderr ("*unknown keyword*");
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
test_incomplete_list (void)
|
|
||||||
{
|
|
||||||
g_remove ("gschemas.compiled");
|
|
||||||
|
|
||||||
if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
|
|
||||||
{
|
|
||||||
gchar *argv[] = {
|
|
||||||
"../gschema-compile",
|
|
||||||
SRCDIR "/schema-tests/incomplete-list/",
|
|
||||||
"--targetdir=.",
|
|
||||||
NULL
|
|
||||||
};
|
|
||||||
gchar *envp[] = { NULL };
|
|
||||||
execve (argv[0], argv, envp);
|
|
||||||
}
|
|
||||||
g_test_trap_assert_failed ();
|
|
||||||
g_test_trap_assert_stderr ("*to follow array element*");
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
test_wrong_category (void)
|
|
||||||
{
|
|
||||||
g_remove ("gschemas.compiled");
|
|
||||||
|
|
||||||
if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
|
|
||||||
{
|
|
||||||
gchar *argv[] = {
|
|
||||||
"../gschema-compile",
|
|
||||||
SRCDIR "/schema-tests/wrong-category/",
|
|
||||||
"--targetdir=.",
|
|
||||||
NULL
|
|
||||||
};
|
|
||||||
gchar *envp[] = { NULL };
|
|
||||||
execve (argv[0], argv, envp);
|
|
||||||
}
|
|
||||||
g_test_trap_assert_failed ();
|
|
||||||
g_test_trap_assert_stderr ("*attribute 'l10n' invalid*");
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
test_bad_type (void)
|
|
||||||
{
|
|
||||||
g_remove ("gschemas.compiled");
|
|
||||||
|
|
||||||
if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
|
|
||||||
{
|
|
||||||
gchar *argv[] = {
|
|
||||||
"../gschema-compile",
|
|
||||||
SRCDIR "/schema-tests/bad-type/",
|
|
||||||
"--targetdir=.",
|
|
||||||
NULL
|
|
||||||
};
|
|
||||||
gchar *envp[] = { NULL };
|
|
||||||
execve (argv[0], argv, envp);
|
|
||||||
}
|
|
||||||
g_test_trap_assert_failed ();
|
|
||||||
g_test_trap_assert_stderr ("*invalid GVariant type string*");
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
test_overflow (void)
|
|
||||||
{
|
|
||||||
g_remove ("gschemas.compiled");
|
|
||||||
|
|
||||||
if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
|
|
||||||
{
|
|
||||||
gchar *argv[] = {
|
|
||||||
"../gschema-compile",
|
|
||||||
SRCDIR "/schema-tests/overflow/",
|
|
||||||
"--targetdir=.",
|
|
||||||
NULL
|
|
||||||
};
|
|
||||||
gchar *envp[] = { NULL };
|
|
||||||
execve (argv[0], argv, envp);
|
|
||||||
}
|
|
||||||
g_test_trap_assert_failed ();
|
|
||||||
g_test_trap_assert_stderr ("*out of range*");
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc, char *argv[])
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
guint i;
|
||||||
|
|
||||||
setlocale (LC_ALL, "");
|
setlocale (LC_ALL, "");
|
||||||
|
|
||||||
g_type_init ();
|
g_type_init ();
|
||||||
g_test_init (&argc, &argv, NULL);
|
g_test_init (&argc, &argv, NULL);
|
||||||
|
|
||||||
g_test_add_func ("/gschema/no-default", test_no_default);
|
for (i = 0; i < G_N_ELEMENTS (tests); ++i)
|
||||||
g_test_add_func ("/gschema/missing-quotes", test_missing_quotes);
|
{
|
||||||
g_test_add_func ("/gschema/incomplete-list", test_incomplete_list);
|
gchar *name = g_strdup_printf ("/gschema/%s", tests[i].name);
|
||||||
g_test_add_func ("/gschema/wrong-category", test_wrong_category);
|
g_test_add_data_func (name, &tests[i], (gpointer) test_schema);
|
||||||
g_test_add_func ("/gschema/bad-type", test_bad_type);
|
g_free (name);
|
||||||
g_test_add_func ("/gschema/overflow", test_overflow);
|
}
|
||||||
|
|
||||||
return g_test_run ();
|
return g_test_run ();
|
||||||
}
|
}
|
||||||
|
7
gio/tests/schema-tests/bad-key.gschema.xml
Normal file
7
gio/tests/schema-tests/bad-key.gschema.xml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<schemalist>
|
||||||
|
<schema id="no-default" path="/tests/">
|
||||||
|
<key name="bad_key" type="s">
|
||||||
|
<default></default>
|
||||||
|
</key>
|
||||||
|
</schema>
|
||||||
|
</schemalist>
|
7
gio/tests/schema-tests/bad-key2.gschema.xml
Normal file
7
gio/tests/schema-tests/bad-key2.gschema.xml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<schemalist>
|
||||||
|
<schema id="no-default" path="/tests/">
|
||||||
|
<key name="BAD-key" type="s">
|
||||||
|
<default></default>
|
||||||
|
</key>
|
||||||
|
</schema>
|
||||||
|
</schemalist>
|
7
gio/tests/schema-tests/bad-key3.gschema.xml
Normal file
7
gio/tests/schema-tests/bad-key3.gschema.xml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<schemalist>
|
||||||
|
<schema id="no-default" path="/tests/">
|
||||||
|
<key name="bad--key" type="s">
|
||||||
|
<default></default>
|
||||||
|
</key>
|
||||||
|
</schema>
|
||||||
|
</schemalist>
|
7
gio/tests/schema-tests/bad-key4.gschema.xml
Normal file
7
gio/tests/schema-tests/bad-key4.gschema.xml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<schemalist>
|
||||||
|
<schema id="no-default" path="/tests/">
|
||||||
|
<key name="bad-key-" type="s">
|
||||||
|
<default></default>
|
||||||
|
</key>
|
||||||
|
</schema>
|
||||||
|
</schemalist>
|
7
gio/tests/schema-tests/empty-key.gschema.xml
Normal file
7
gio/tests/schema-tests/empty-key.gschema.xml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<schemalist>
|
||||||
|
<schema id="no-default" path="/tests/">
|
||||||
|
<key name="" type="s">
|
||||||
|
<default></default>
|
||||||
|
</key>
|
||||||
|
</schema>
|
||||||
|
</schemalist>
|
Loading…
Reference in New Issue
Block a user