From 4a605693fce718a81f809245be2ebad9978031ac Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Mon, 19 Apr 2010 11:31:21 -0400 Subject: [PATCH] Don't segfault when is missing Also add a framework for schema compiler tests. Fixes bug 616086. --- gio/gschema-compile.c | 10 +++++- gio/tests/Makefile.am | 20 +++++++++-- gio/tests/gschema-compile.c | 35 +++++++++++++++++++ .../no-default/no-default.gschema.xml | 6 ++++ 4 files changed, 67 insertions(+), 4 deletions(-) create mode 100644 gio/tests/gschema-compile.c create mode 100644 gio/tests/schema-tests/no-default/no-default.gschema.xml diff --git a/gio/gschema-compile.c b/gio/gschema-compile.c index da861062b..3a657bbaf 100644 --- a/gio/gschema-compile.c +++ b/gio/gschema-compile.c @@ -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 is required in \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)); } } diff --git a/gio/tests/Makefile.am b/gio/tests/Makefile.am index ae3d110db..3d467d9e3 100644 --- a/gio/tests/Makefile.am +++ b/gio/tests/Makefile.am @@ -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 diff --git a/gio/tests/gschema-compile.c b/gio/tests/gschema-compile.c new file mode 100644 index 000000000..7a7a8e451 --- /dev/null +++ b/gio/tests/gschema-compile.c @@ -0,0 +1,35 @@ +#include +#include +#include +#include +#include +#include + +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 ("* is required in *"); +} + + +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 (); +} diff --git a/gio/tests/schema-tests/no-default/no-default.gschema.xml b/gio/tests/schema-tests/no-default/no-default.gschema.xml new file mode 100644 index 000000000..5496ce312 --- /dev/null +++ b/gio/tests/schema-tests/no-default/no-default.gschema.xml @@ -0,0 +1,6 @@ + + + + + +