Merge branch '976-disable-assert-checks' into 'master'
[glib.git] / gio / tests / gschema-compile.c
blob81ded83fa2e35b362c7cac40f5a8fd78216ccc2c
1 #include <stdlib.h>
2 #include <unistd.h>
3 #include <locale.h>
4 #include <libintl.h>
5 #include <gio/gio.h>
6 #include <gstdio.h>
8 typedef struct {
9 const gchar *name;
10 const gchar *opt;
11 const gchar *err;
12 } SchemaTest;
14 /* Meson build defines this, autotools build does not */
15 #ifndef GLIB_COMPILE_SCHEMAS
16 #define GLIB_COMPILE_SCHEMAS "../glib-compile-schemas"
17 #endif
19 static void
20 test_schema_do_compile (gpointer data)
22 SchemaTest *test = (SchemaTest *) data;
23 gchar *filename = g_strconcat (test->name, ".gschema.xml", NULL);
24 gchar *path = g_test_build_filename (G_TEST_DIST, "schema-tests", filename, NULL);
25 const gchar *argv[] = {
26 GLIB_COMPILE_SCHEMAS,
27 "--strict",
28 "--dry-run",
29 "--schema-file", path,
30 test->opt,
31 NULL
33 gchar *envp[] = { NULL };
35 execve (argv[0], (char **) argv, envp);
36 g_assert_not_reached ();
39 static void
40 test_schema (gpointer data)
42 SchemaTest *test = (SchemaTest *) data;
43 gchar *child_name;
45 child_name = g_strdup_printf ("/gschema/%s%s/subprocess/do_compile", test->name, test->opt ? "/opt" : "");
46 g_test_trap_subprocess (child_name, 0, 0);
47 g_free (child_name);
49 if (test->err)
51 g_test_trap_assert_failed ();
52 g_test_trap_assert_stderr_unmatched ("*CRITICAL*");
53 g_test_trap_assert_stderr_unmatched ("*WARNING*");
54 g_test_trap_assert_stderr (test->err);
56 else
57 g_test_trap_assert_passed();
60 static const SchemaTest tests[] = {
61 { "no-default", NULL, "*<default> is required in <key>*" },
62 { "missing-quotes", NULL, "*unknown keyword*" },
63 { "incomplete-list", NULL, "*to follow array element*" },
64 { "wrong-category", NULL, "*unsupported l10n category*" },
65 { "bad-type", NULL, "*Invalid GVariant type string*" },
66 { "overflow", NULL, "*out of range*" },
67 { "range-wrong-type", NULL, "*<range> not allowed for keys of type*" },
68 { "range-missing-min", NULL, NULL },
69 { "range-missing-max", NULL, NULL },
70 { "default-out-of-range", NULL, "*<default> is not contained in the specified range*" },
71 { "choices-wrong-type", NULL, "*<choices> not allowed for keys of type*" },
72 { "choice-missing-value", NULL, "*element 'choice' requires attribute 'value'*" },
73 { "default-not-in-choices", NULL, "*<default> contains a string not in <choices>*" },
74 { "array-default-not-in-choices", NULL, "*<default> contains a string not in <choices>*" },
75 { "bad-key", NULL, "*Invalid name*" },
76 { "invalid-path", NULL, "*must begin and end with a slash*" },
77 { "bad-key", "--allow-any-name", NULL },
78 { "bad-key2", NULL, "*Invalid name*" },
79 { "bad-key2", "--allow-any-name", NULL },
80 { "bad-key3", NULL, "*Invalid name*" },
81 { "bad-key3", "--allow-any-name", NULL },
82 { "bad-key4", NULL, "*Invalid name*" },
83 { "bad-key4", "--allow-any-name", NULL },
84 { "empty-key", NULL, "*Empty names*" },
85 { "empty-key", "--allow-any-name", "*Empty names*" },
86 { "enum", NULL, NULL },
87 { "enum-with-aliases", NULL, NULL },
88 { "enum-with-invalid-alias", NULL, "*“banger” is not in enumerated type*" },
89 { "enum-with-invalid-value", NULL, "*Invalid numeric value*" },
90 { "enum-with-repeated-alias", NULL, "*<alias value='sausages'/> already specified*" },
91 { "enum-with-repeated-nick", NULL, "*<value nick='spam'/> already specified*" },
92 { "enum-with-repeated-value", NULL, "*value='1' already specified*" },
93 { "enum-with-chained-alias", NULL, "*“sausages” is not in enumerated type*" },
94 { "enum-with-shadow-alias", NULL, "*“mash” is already a member of the enum*" },
95 { "enum-with-choice", NULL, "*<choices> cannot be specified*" },
96 { "enum-with-bad-default", NULL, "*<default> is not a valid member*" },
97 { "choice", NULL, NULL },
98 { "choice-upside-down", NULL, NULL },
99 { "bad-choice", NULL, "*<default> contains a string not in <choices>*" },
100 { "choice-bad", NULL, "*<default> contains a string not in <choices>*" },
101 { "choice-badtype", NULL, "*<choices> not allowed for keys of type “i”*" },
102 { "bare-alias", NULL, "*enumerated or flags types or after <choices>*" },
103 { "choice-alias", NULL, NULL },
104 { "default-in-aliases", NULL, "*<default> contains a string not in <choices>*" },
105 { "choice-invalid-alias", NULL, "*“befor” is not in <choices>*" },
106 { "choice-shadowed-alias", NULL, "*given when <choice value='before'/> was already*" },
107 { "range", NULL, NULL },
108 { "range-badtype", NULL, "*<range> not allowed for keys of type “s”*" },
109 { "range-low-default", NULL, "*<default> is not contained in the specified range*" },
110 { "range-high-default", NULL, "*<default> is not contained in the specified range*" },
111 { "range-default-low", NULL, "*<default> is not contained in the specified range*" },
112 { "range-default-high", NULL, "*<default> is not contained in the specified range*" },
113 { "range-parse-error", NULL, "*invalid character in number*" },
114 { "from-docs", NULL, NULL },
115 { "extending", NULL, NULL },
116 { "extend-missing", NULL, "*extends not yet existing schema*" },
117 { "extend-nonlist", NULL, "*which is not a list*" },
118 { "extend-self", NULL, "*not yet existing*" },
119 { "extend-wrong-list-indirect", NULL, "*“y” does not extend “x”*" },
120 { "extend-wrong-list", NULL, "*“y” does not extend “x”*" },
121 { "key-in-list-indirect", NULL, "*Cannot add keys to a “list*" },
122 { "key-in-list", NULL, "*Cannot add keys to a “list*" },
123 { "list-of-missing", NULL, "*is list of not yet existing schema*" },
124 { "extend-and-shadow", NULL, "*shadows*use <override>*" },
125 { "extend-and-shadow-indirect", NULL, "*shadows*use <override>*" },
126 { "override", NULL, NULL },
127 { "override-missing", NULL, "*No <key name='bar'> to override*" },
128 { "override-range-error", NULL, "*<override> is not contained in the specified range*"},
129 { "override-then-key", NULL, "*shadows <key name='foo'> in <schema id='base'>*" },
130 { "override-twice", NULL, "*<override name='foo'> already specified*" },
131 { "override-type-error", NULL, "*invalid character in number*" },
132 { "flags-aliased-default", NULL, "*<default> * not in the specified flags type*" },
133 { "flags-bad-default", NULL, "*<default> * not in the specified flags type*" },
134 { "flags-more-than-one-bit", NULL, "*flags values must have at most 1 bit set*" },
135 { "flags-with-enum-attr", NULL, "*<enum id='flags'> not (yet) defined*" },
136 { "flags-with-enum-tag", NULL, "*<flags id='flags'> not (yet) defined*" },
137 { "summary-xmllang", NULL, "*Only one <summary> element allowed*" },
138 { "description-xmllang", NULL, "*Only one <description> element allowed*" },
139 { "summary-xmllang-and-attrs", NULL, "*attribute 'lang' invalid for element 'summary'*" },
140 { "inherit-gettext-domain", NULL, NULL },
141 { "range-type-test", NULL, NULL },
142 { "cdata", NULL, NULL }
147 main (int argc, char *argv[])
149 guint i;
151 setlocale (LC_ALL, "");
153 g_test_init (&argc, &argv, NULL);
155 for (i = 0; i < G_N_ELEMENTS (tests); ++i)
157 gchar *name;
159 name = g_strdup_printf ("/gschema/%s%s", tests[i].name, tests[i].opt ? "/opt" : "");
160 g_test_add_data_func (name, &tests[i], (gpointer) test_schema);
161 g_free (name);
163 name = g_strdup_printf ("/gschema/%s%s/subprocess/do_compile", tests[i].name, tests[i].opt ? "/opt" : "");
164 g_test_add_data_func (name, &tests[i], (gpointer) test_schema_do_compile);
165 g_free (name);
168 return g_test_run ();