Don't segfault when <default> is missing

Also add a framework for schema compiler tests.

Fixes bug 616086.
This commit is contained in:
Matthias Clasen 2010-04-19 11:31:21 -04:00
parent ccbafd0f14
commit 4a605693fc
4 changed files with 67 additions and 4 deletions

View File

@ -390,6 +390,14 @@ end_element (GMarkupParseContext *context,
else if (strcmp (element_name, "key") == 0)
{
if (state->value == NULL)
{
g_set_error_literal (error,
G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
"Element <default> is required in <key>\n");
return;
}
gvdb_item_set_value (state->key, state->value);
gvdb_item_set_options (state->key,
g_variant_builder_end (&state->key_options));
@ -521,7 +529,7 @@ main (int argc, char **argv)
{
if (g_str_has_suffix (file, ".gschema.xml"))
{
g_ptr_array_add (files, g_strdup (file));
g_ptr_array_add (files, g_build_filename (srcdir, file, NULL));
}
}

View File

@ -34,7 +34,8 @@ TEST_PROGS += \
simple-async-result \
srvtarget \
contexts \
gsettings
gsettings \
gschema-compile
SAMPLE_PROGS = \
resolver \
@ -146,7 +147,14 @@ contexts_LDADD = $(progs_ldadd) \
gsettings_SOURCES = gsettings.c
gsettings_LDADD = $(progs_ldadd)
EXTRA_DIST += org.gtk.test.gschema org.gtk.test.gschema.xml de.po
gschema_compile_SOURCES = gschema-compile.c
gschema_compile_LDADD = $(progs_ldadd)
EXTRA_DIST += \
org.gtk.test.gschema \
org.gtk.test.gschema.xml \
de.po \
schema-tests/no-default/no-default.gschema.xml \
MISC_STUFF = gschemas.compiled test.mo
@ -158,4 +166,10 @@ test.mo: de.po
gschemas.compiled:
$(top_builddir)/gio/gschema-compile --targetdir=$(abs_builddir) $(srcdir)
DISTCLEANFILES = applications/mimeinfo.cache de/LC_MESSAGES/test.mo test.mo gsettings.store
DISTCLEANFILES = \
applications/mimeinfo.cache \
de/LC_MESSAGES/test.mo \
test.mo \
gsettings.store \
gschemas.compiled \
schema-tests/no-schema/gschemas.compiled

View File

@ -0,0 +1,35 @@
#include <stdlib.h>
#include <unistd.h>
#include <locale.h>
#include <libintl.h>
#include <gio.h>
#include <gstdio.h>
static void
test_no_default (void)
{
g_remove ("schema-tests/no-default/gschemas.compiled");
if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
{
gchar *argv[] = { "../gschema-compile", "./schema-tests/no-default/", NULL };
gchar *envp[] = { NULL };
execve (argv[0], argv, envp);
}
g_test_trap_assert_failed ();
g_test_trap_assert_stderr ("*<default> is required in <key>*");
}
int
main (int argc, char *argv[])
{
setlocale (LC_ALL, "");
g_type_init ();
g_test_init (&argc, &argv, NULL);
g_test_add_func ("/gschema/no-default", test_no_default);
return g_test_run ();
}

View File

@ -0,0 +1,6 @@
<schemalist>
<schema id="no-default" path="/tests/">
<key name="test" type="s">
</key>
</schema>
</schemalist>