9f1123c8e02726e1b0074d0f4d5f00d3f3dddd8a
[platform/upstream/glib.git] / gio / tests / gschema-compile.c
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
8 typedef struct {
9   const gchar *name;
10   const gchar *opt;
11   const gchar *err;
12 } SchemaTest;
13
14 static void
15 test_schema (gpointer data)
16 {
17   SchemaTest *test = (SchemaTest *) data;
18
19   if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
20     {
21       gchar *filename = g_strconcat (test->name, ".gschema.xml", NULL);
22       gchar *path = g_build_filename (SRCDIR, "schema-tests", filename, NULL);
23       gchar *argv[] = {
24         "../glib-compile-schemas",
25         "--dry-run",
26         "--schema-file", path,
27         (gchar *)test->opt,
28         NULL
29       };
30       gchar *envp[] = { NULL };
31       execve (argv[0], argv, envp);
32       g_free (filename);
33       g_free (path);
34     }
35   if (test->err)
36     {
37       g_test_trap_assert_failed ();
38       g_test_trap_assert_stderr (test->err);
39     }
40   else
41     g_test_trap_assert_passed();
42 }
43
44 static const SchemaTest tests[] = {
45   { "no-default",                   NULL, "*<default> is required in <key>*"                    },
46   { "missing-quotes",               NULL, "*unknown keyword*"                                   },
47   { "incomplete-list",              NULL, "*to follow array element*"                           },
48   { "wrong-category",               NULL, "*attribute 'l10n' invalid*"                          },
49   { "bad-type",                     NULL, "*invalid GVariant type string*"                      },
50   { "overflow",                     NULL, "*out of range*"                                      },
51   { "range-wrong-type",             NULL, "*<range> not allowed for keys of type*"              },
52   { "range-missing-min",            NULL, "*element 'range' requires attribute 'min'*"          },
53   { "range-missing-max",            NULL, "*element 'range' requires attribute 'max'*"          },
54   { "default-out-of-range",         NULL, "*<default> is not contained in the specified range*" },
55   { "choices-wrong-type",           NULL, "*<choices> not allowed for keys of type*"            },
56   { "choice-missing-value",         NULL, "*element 'choice' requires attribute 'value'*"       },
57   { "default-not-in-choices",       NULL, "*<default> contains string not in <choices>*"        },
58   { "array-default-not-in-choices", NULL, "*<default> contains string not in <choices>*"        },
59   { "bad-key",                      NULL, "*invalid name*"                                      },
60   { "invalid-path",                 NULL, "*must begin and end with a slash*"                   },
61   { "bad-key",                      "--allow-any-name", NULL                                    },
62   { "bad-key2",                     NULL, "*invalid name*"                                      },
63   { "bad-key2",                     "--allow-any-name", NULL                                    },
64   { "bad-key3",                     NULL, "*invalid name*"                                      },
65   { "bad-key3",                     "--allow-any-name", NULL                                    },
66   { "bad-key4",                     NULL, "*invalid name*"                                      },
67   { "bad-key4",                     "--allow-any-name", NULL                                    },
68   { "empty-key",                    NULL, "*empty names*"                                       },
69   { "empty-key",                    "--allow-any-name", "*empty names*"                         },
70   { "enum",                         NULL, NULL                                                  },
71   { "enum-with-aliases",            NULL, NULL                                                  },
72   { "enum-with-invalid-alias",      NULL, "*'banger' is not in enumerated type*"                },
73   { "enum-with-repeated-alias",     NULL, "*<alias value='sausages'/> already specified*"       },
74   { "enum-with-repeated-nick",      NULL, "*<value nick='spam'/> already specified*"            },
75   { "enum-with-repeated-value",     NULL, "*value='1' already specified*"                       },
76   { "enum-with-chained-alias",      NULL, "*'sausages' is not in enumerated type*"              },
77   { "enum-with-shadow-alias",       NULL, "*'mash' is already a member of the enum*"            },
78   { "enum-with-choice",             NULL, "*<choices> can not be specified*"                    },
79   { "enum-with-bad-default",        NULL, "*<default> is not a valid member*"                   },
80   { "choice",                       NULL, NULL                                                  },
81   { "choice-upside-down",           NULL, NULL                                                  },
82   { "bad-choice",                   NULL, "*<default> contains string not in <choices>*"        },
83   { "choice-bad",                   NULL, "*<default> contains string not in <choices>*"        },
84   { "choice-badtype",               NULL, "*<choices> not allowed for keys of type 'i'*"        },
85   { "bare-alias",                   NULL, "*enumerated or flags types or after <choices>*"      },
86   { "choice-alias",                 NULL, NULL                                                  },
87   { "default-in-aliases",           NULL, "*<default> contains string not in <choices>*"        },
88   { "choice-invalid-alias",         NULL, "*'befor' is not in <choices>*"                       },
89   { "choice-shadowed-alias",        NULL, "*given when <choice value='before'/> was already*"   },
90   { "range",                        NULL, NULL                                                  },
91   { "range-badtype",                NULL, "*<range> not allowed for keys of type 's'*"          },
92   { "range-low-default",            NULL, "*<default> is not contained in the specified range*" },
93   { "range-high-default",           NULL, "*<default> is not contained in the specified range*" },
94   { "range-default-low",            NULL, "*<default> is not contained in the specified range*" },
95   { "range-default-high",           NULL, "*<default> is not contained in the specified range*" },
96   { "range-parse-error",            NULL, "*invalid character in number*"                       },
97   { "from-docs",                    NULL, NULL                                                  },
98   { "extending",                    NULL, NULL                                                  },
99   { "extend-missing",               NULL, "*extends not yet existing schema*"                   },
100   { "extend-nonlist",               NULL, "*which is not a list*"                               },
101   { "extend-self",                  NULL, "*not yet existing*"                                  },
102   { "extend-wrong-list-indirect",   NULL, "*'y' does not extend 'x'*"                           },
103   { "extend-wrong-list",            NULL, "*'y' does not extend 'x'*"                           },
104   { "key-in-list-indirect",         NULL, "*can not add keys to a 'list*"                        },
105   { "key-in-list",                  NULL, "*can not add keys to a 'list*"                        },
106   { "list-of-missing",              NULL, "*is list of not yet existing schema*"                },
107   { "extend-and-shadow",            NULL, "*shadows*use <override>*"                            },
108   { "extend-and-shadow-indirect",   NULL, "*shadows*use <override>*"                            },
109   { "override",                     NULL, NULL                                                  },
110   { "override-missing",             NULL, "*no <key name='bar'> to override*"                   },
111   { "override-range-error",         NULL, "*<override> is not contained in the specified range*"},
112   { "override-then-key",            NULL, "*shadows <key name='foo'> in <schema id='base'>*"    },
113   { "override-twice",               NULL, "*<override name='foo'> already specified*"           },
114   { "override-type-error",          NULL, "*invalid character in number*"                       },
115   { "flags-aliased-default",        NULL, "*<default> * not in the specified flags type*"       },
116   { "flags-bad-default",            NULL, "*<default> * not in the specified flags type*"       },
117   { "flags-more-than-one-bit",      NULL, "*flags values must have at most 1 bit set*"          },
118   { "flags-with-enum-attr",         NULL, "*<enum id='flags'> not (yet) defined*"               },
119   { "flags-with-enum-tag",          NULL, "*<flags id='flags'> not (yet) defined*"              }
120 };
121
122 int
123 main (int argc, char *argv[])
124 {
125   guint i;
126
127   setlocale (LC_ALL, "");
128
129   g_type_init ();
130   g_test_init (&argc, &argv, NULL);
131
132   for (i = 0; i < G_N_ELEMENTS (tests); ++i)
133     {
134       gchar *name = g_strdup_printf ("/gschema/%s%s", tests[i].name, tests[i].opt ? "/opt" : "");
135       g_test_add_data_func (name, &tests[i], (gpointer) test_schema);
136       g_free (name);
137     }
138
139   return g_test_run ();
140 }