File: gschema-compile.c

package info (click to toggle)
glib2.0 2.42.1-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-backports, jessie-kfreebsd, jessie-kfreebsd-proposed-updates
  • size: 82,084 kB
  • sloc: ansic: 411,692; xml: 15,280; sh: 12,977; python: 5,145; makefile: 3,567; perl: 1,422; cpp: 9
file content (158 lines) | stat: -rw-r--r-- 9,517 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#include <stdlib.h>
#include <unistd.h>
#include <locale.h>
#include <libintl.h>
#include <gio/gio.h>
#include <gstdio.h>

typedef struct {
  const gchar *name;
  const gchar *opt;
  const gchar *err;
} SchemaTest;

static void
test_schema_do_compile (gpointer data)
{
  SchemaTest *test = (SchemaTest *) data;
  gchar *filename = g_strconcat (test->name, ".gschema.xml", NULL);
  gchar *path = g_test_build_filename (G_TEST_DIST, "schema-tests", filename, NULL);
  gchar *argv[] = {
    "../glib-compile-schemas",
    "--strict",
    "--dry-run",
    "--schema-file", path,
    (gchar *)test->opt,
    NULL
  };
  gchar *envp[] = { NULL };

  execve (argv[0], argv, envp);
  g_assert_not_reached ();
}

static void
test_schema (gpointer data)
{
  SchemaTest *test = (SchemaTest *) data;
  gchar *child_name;

  child_name = g_strdup_printf ("/gschema/%s%s/subprocess/do_compile", test->name, test->opt ? "/opt" : "");
  g_test_trap_subprocess (child_name, 0, 0);
  g_free (child_name);

  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, "*<default> is required in <key>*"                    },
  { "missing-quotes",               NULL, "*unknown keyword*"                                   },
  { "incomplete-list",              NULL, "*to follow array element*"                           },
  { "wrong-category",               NULL, "*unsupported l10n category*"                         },
  { "bad-type",                     NULL, "*invalid GVariant type string*"                      },
  { "overflow",                     NULL, "*out of range*"                                      },
  { "range-wrong-type",             NULL, "*<range> not allowed for keys of type*"              },
  { "range-missing-min",            NULL, NULL                                                  },
  { "range-missing-max",            NULL, NULL                                                  },
  { "default-out-of-range",         NULL, "*<default> is not contained in the specified range*" },
  { "choices-wrong-type",           NULL, "*<choices> not allowed for keys of type*"            },
  { "choice-missing-value",         NULL, "*element 'choice' requires attribute 'value'*"       },
  { "default-not-in-choices",       NULL, "*<default> contains string not in <choices>*"        },
  { "array-default-not-in-choices", NULL, "*<default> contains string not in <choices>*"        },
  { "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, "*<alias value='sausages'/> already specified*"       },
  { "enum-with-repeated-nick",      NULL, "*<value nick='spam'/> already specified*"            },
  { "enum-with-repeated-value",     NULL, "*value='1' 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, "*<choices> cannot be specified*"                     },
  { "enum-with-bad-default",        NULL, "*<default> is not a valid member*"                   },
  { "choice",                       NULL, NULL                                                  },
  { "choice-upside-down",           NULL, NULL                                                  },
  { "bad-choice",                   NULL, "*<default> contains string not in <choices>*"        },
  { "choice-bad",                   NULL, "*<default> contains string not in <choices>*"        },
  { "choice-badtype",               NULL, "*<choices> not allowed for keys of type 'i'*"        },
  { "bare-alias",                   NULL, "*enumerated or flags types or after <choices>*"      },
  { "choice-alias",                 NULL, NULL                                                  },
  { "default-in-aliases",           NULL, "*<default> contains string not in <choices>*"        },
  { "choice-invalid-alias",         NULL, "*'befor' is not in <choices>*"                       },
  { "choice-shadowed-alias",        NULL, "*given when <choice value='before'/> was already*"   },
  { "range",                        NULL, NULL                                                  },
  { "range-badtype",                NULL, "*<range> not allowed for keys of type 's'*"          },
  { "range-low-default",            NULL, "*<default> is not contained in the specified range*" },
  { "range-high-default",           NULL, "*<default> is not contained in the specified range*" },
  { "range-default-low",            NULL, "*<default> is not contained in the specified range*" },
  { "range-default-high",           NULL, "*<default> is not contained in the specified range*" },
  { "range-parse-error",            NULL, "*invalid character in number*"                       },
  { "from-docs",                    NULL, NULL                                                  },
  { "extending",                    NULL, NULL                                                  },
  { "extend-missing",               NULL, "*extends not yet existing schema*"                   },
  { "extend-nonlist",               NULL, "*which is not a list*"                               },
  { "extend-self",                  NULL, "*not yet existing*"                                  },
  { "extend-wrong-list-indirect",   NULL, "*'y' does not extend 'x'*"                           },
  { "extend-wrong-list",            NULL, "*'y' does not extend 'x'*"                           },
  { "key-in-list-indirect",         NULL, "*cannot add keys to a 'list*"                        },
  { "key-in-list",                  NULL, "*cannot add keys to a 'list*"                        },
  { "list-of-missing",              NULL, "*is list of not yet existing schema*"                },
  { "extend-and-shadow",            NULL, "*shadows*use <override>*"                            },
  { "extend-and-shadow-indirect",   NULL, "*shadows*use <override>*"                            },
  { "override",                     NULL, NULL                                                  },
  { "override-missing",             NULL, "*no <key name='bar'> to override*"                   },
  { "override-range-error",         NULL, "*<override> is not contained in the specified range*"},
  { "override-then-key",            NULL, "*shadows <key name='foo'> in <schema id='base'>*"    },
  { "override-twice",               NULL, "*<override name='foo'> already specified*"           },
  { "override-type-error",          NULL, "*invalid character in number*"                       },
  { "flags-aliased-default",        NULL, "*<default> * not in the specified flags type*"       },
  { "flags-bad-default",            NULL, "*<default> * not in the specified flags type*"       },
  { "flags-more-than-one-bit",      NULL, "*flags values must have at most 1 bit set*"          },
  { "flags-with-enum-attr",         NULL, "*<enum id='flags'> not (yet) defined*"               },
  { "flags-with-enum-tag",          NULL, "*<flags id='flags'> not (yet) defined*"              },
  { "inherit-gettext-domain",       NULL, NULL                                                  },
  { "range-type-test",              NULL, NULL                                                  },
  { "cdata",                        NULL, NULL                                                  }
};


int
main (int argc, char *argv[])
{
  guint i;

  setlocale (LC_ALL, "");

  g_test_init (&argc, &argv, NULL);

  for (i = 0; i < G_N_ELEMENTS (tests); ++i)
    {
      gchar *name;

      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);

      name = g_strdup_printf ("/gschema/%s%s/subprocess/do_compile", tests[i].name, tests[i].opt ? "/opt" : "");
      g_test_add_data_func (name, &tests[i], (gpointer) test_schema_do_compile);
      g_free (name);
    }

  return g_test_run ();
}