#include #include #include #include #include #include typedef struct { const gchar *name; const gchar *opt; const gchar *err; } SchemaTest; static void test_schema (gpointer data) { SchemaTest *test = (SchemaTest *) data; 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[] = { "../glib-compile-schemas", "--dry-run", "--schema-file", path, (gchar *)test->opt, NULL }; gchar *envp[] = { NULL }; execve (argv[0], argv, envp); g_free (filename); g_free (path); } if (test->err) { g_test_trap_assert_failed (); g_test_trap_assert_stderr (test->err); } else g_test_trap_assert_passed(); } static const SchemaTest tests[] = { { "no-default", NULL, "* is required in *" }, { "missing-quotes", NULL, "*unknown keyword*" }, { "incomplete-list", NULL, "*to follow array element*" }, { "wrong-category", NULL, "*attribute 'l10n' invalid*" }, { "bad-type", NULL, "*invalid GVariant type string*" }, { "overflow", NULL, "*out of range*" }, { "range-wrong-type", NULL, "* not allowed for keys of type*" }, { "range-missing-min", NULL, "*element 'range' requires attribute 'min'*" }, { "range-missing-max", NULL, "*element 'range' requires attribute 'max'*" }, { "default-out-of-range", NULL, "* is not contained in the specified range*" }, { "choices-wrong-type", NULL, "* not allowed for keys of type*" }, { "choice-missing-value", NULL, "*element 'choice' requires attribute 'value'*" }, { "default-not-in-choices", NULL, "* contains string not in *" }, { "array-default-not-in-choices", NULL, "* contains string not in *" }, { "bad-key", NULL, "*invalid name*" }, { "invalid-path", NULL, "*must begin and end with a slash*" }, { "bad-key", "--allow-any-name", NULL }, { "bad-key2", NULL, "*invalid name*" }, { "bad-key2", "--allow-any-name", NULL }, { "bad-key3", NULL, "*invalid name*" }, { "bad-key3", "--allow-any-name", NULL }, { "bad-key4", NULL, "*invalid name*" }, { "bad-key4", "--allow-any-name", NULL }, { "empty-key", NULL, "*empty names*" }, { "empty-key", "--allow-any-name", "*empty names*" }, { "enum", NULL, NULL }, { "enum-with-aliases", NULL, NULL }, { "enum-with-invalid-alias", NULL, "*'banger' is not in enumerated type*" }, { "enum-with-repeated-alias", NULL, "* already specified*" }, { "enum-with-chained-alias", NULL, "*'sausages' is not in enumerated type*" }, { "enum-with-shadow-alias", NULL, "*'mash' is already a member of the enum*" }, { "enum-with-choice", NULL, "* can not be specified*" }, { "enum-with-bad-default", NULL, "* is not a valid member*" }, { "choice", NULL, NULL }, { "choice-upside-down", NULL, NULL }, { "bad-choice", NULL, "* contains string not in *" }, { "choice-bad", NULL, "* contains string not in *" }, { "choice-badtype", NULL, "* not allowed for keys of type 'i'*" }, { "bare-alias", NULL, "*enumerated types or after *" }, { "choice-alias", NULL, NULL }, { "default-in-aliases", NULL, "* contains string not in *" }, { "choice-invalid-alias", NULL, "*'befor' is not in *" }, { "choice-shadowed-alias", NULL, "*given when was already*" }, { "range", NULL, NULL }, { "range-badtype", NULL, "* not allowed for keys of type 's'*" }, { "range-low-default", NULL, "* is not contained in the specified range*" }, { "range-high-default", NULL, "* is not contained in the specified range*" }, { "range-default-low", NULL, "* is not contained in the specified range*" }, { "range-default-high", NULL, "* is not contained in the specified range*" }, { "range-parse-error", NULL, "*invalid character in number*" }, { "from-docs", NULL, NULL } }; int main (int argc, char *argv[]) { guint i; setlocale (LC_ALL, ""); g_type_init (); g_test_init (&argc, &argv, NULL); for (i = 0; i < G_N_ELEMENTS (tests); ++i) { gchar *name = g_strdup_printf ("/gschema/%s%s", tests[i].name, tests[i].opt ? "/opt" : ""); g_test_add_data_func (name, &tests[i], (gpointer) test_schema); g_free (name); } return g_test_run (); }