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

source code of gtk/subprojects/glib/gio/tests/gschema-compile.c