gschema-compile.c 9.88 KB
Newer Older
1 2 3 4
#include <stdlib.h>
#include <unistd.h>
#include <locale.h>
#include <libintl.h>
5
#include <gio/gio.h>
6 7
#include <gstdio.h>

8 9
typedef struct {
  const gchar *name;
10
  const gchar *opt;
11
  const gchar *err;
12
} SchemaTest;
13

14 15 16 17 18
static void
test_schema_do_compile (gpointer data)
{
  SchemaTest *test = (SchemaTest *) data;
  gchar *filename = g_strconcat (test->name, ".gschema.xml", NULL);
19
  gchar *path = g_test_build_filename (G_TEST_DIST, "schema-tests", filename, NULL);
20
  const gchar *argv[] = {
21
    GLIB_COMPILE_SCHEMAS,  /* defined in meson.build */
22 23 24
    "--strict",
    "--dry-run",
    "--schema-file", path,
25
    test->opt,
26 27 28 29
    NULL
  };
  gchar *envp[] = { NULL };

30
  execve (argv[0], (char **) argv, envp);
31 32 33
  g_assert_not_reached ();
}

34
static void
35
test_schema (gpointer data)
36
{
37
  SchemaTest *test = (SchemaTest *) data;
38 39 40 41 42
  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);
43

44
  if (test->err)
45 46
    {
      g_test_trap_assert_failed ();
47 48
      g_test_trap_assert_stderr_unmatched ("*CRITICAL*");
      g_test_trap_assert_stderr_unmatched ("*WARNING*");
49
      g_test_trap_assert_stderr (test->err);
50 51 52
    }
  else
    g_test_trap_assert_passed();
53 54
}

55
static const SchemaTest tests[] = {
56 57 58
  { "no-default",                   NULL, "*<default> is required in <key>*"                    },
  { "missing-quotes",               NULL, "*unknown keyword*"                                   },
  { "incomplete-list",              NULL, "*to follow array element*"                           },
59
  { "wrong-category",               NULL, "*unsupported l10n category*"                         },
60
  { "bad-type",                     NULL, "*Invalid GVariant type string*"                      },
61 62
  { "overflow",                     NULL, "*out of range*"                                      },
  { "range-wrong-type",             NULL, "*<range> not allowed for keys of type*"              },
63 64
  { "range-missing-min",            NULL, NULL                                                  },
  { "range-missing-max",            NULL, NULL                                                  },
65 66 67
  { "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'*"       },
68 69 70
  { "default-not-in-choices",       NULL, "*<default> contains a string not in <choices>*"        },
  { "array-default-not-in-choices", NULL, "*<default> contains a string not in <choices>*"        },
  { "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 80
  { "empty-key",                    NULL, "*Empty names*"                                       },
  { "empty-key",                    "--allow-any-name", "*Empty names*"                         },
81 82
  { "enum",                         NULL, NULL                                                  },
  { "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 87
  { "enum-with-repeated-nick",      NULL, "*<value nick='spam'/> already specified*"            },
  { "enum-with-repeated-value",     NULL, "*value='1' already specified*"                       },
88 89
  { "enum-with-chained-alias",      NULL, "*“sausages” is not in enumerated type*"              },
  { "enum-with-shadow-alias",       NULL, "*“mash” is already a member of the enum*"            },
90
  { "enum-with-choice",             NULL, "*<choices> cannot be specified*"                     },
91 92 93
  { "enum-with-bad-default",        NULL, "*<default> is not a valid member*"                   },
  { "choice",                       NULL, NULL                                                  },
  { "choice-upside-down",           NULL, NULL                                                  },
94 95 96
  { "bad-choice",                   NULL, "*<default> contains a string not in <choices>*"        },
  { "choice-bad",                   NULL, "*<default> contains a string not in <choices>*"        },
  { "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 100
  { "default-in-aliases",           NULL, "*<default> contains a string not in <choices>*"        },
  { "choice-invalid-alias",         NULL, "*“befor” is not in <choices>*"                       },
101 102
  { "choice-shadowed-alias",        NULL, "*given when <choice value='before'/> was already*"   },
  { "range",                        NULL, NULL                                                  },
103
  { "range-badtype",                NULL, "*<range> not allowed for keys of type “s”*"          },
104 105 106 107
  { "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*" },
Allison Karlitskaya's avatar
Allison Karlitskaya committed
108
  { "range-parse-error",            NULL, "*invalid character in number*"                       },
109 110
  { "from-docs",                    NULL, NULL                                                  },
  { "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 115 116 117
  { "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*"                        },
118
  { "list-of-missing",              NULL, "*is list of not yet existing schema*"                },
119 120 121
  { "extend-and-shadow",            NULL, "*shadows*use <override>*"                            },
  { "extend-and-shadow-indirect",   NULL, "*shadows*use <override>*"                            },
  { "override",                     NULL, NULL                                                  },
122
  { "override-missing",             NULL, "*No <key name='bar'> to override*"                   },
123 124 125
  { "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*"           },
126 127 128 129 130
  { "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*"               },
131
  { "flags-with-enum-tag",          NULL, "*<flags id='flags'> not (yet) defined*"              },
132 133
  { "summary-xmllang",              NULL, "*Only one <summary> element allowed*"                },
  { "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 137
  { "range-type-test",              NULL, NULL                                                  },
  { "cdata",                        NULL, NULL                                                  }
138
};
139

140

141 142 143
int
main (int argc, char *argv[])
{
144 145
  guint i;

146 147 148 149
  setlocale (LC_ALL, "");

  g_test_init (&argc, &argv, NULL);

150 151
  for (i = 0; i < G_N_ELEMENTS (tests); ++i)
    {
152 153 154
      gchar *name;

      name = g_strdup_printf ("/gschema/%s%s", tests[i].name, tests[i].opt ? "/opt" : "");
155 156
      g_test_add_data_func (name, &tests[i], (gpointer) test_schema);
      g_free (name);
157 158 159 160

      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);
161
    }
162 163 164

  return g_test_run ();
}