mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-27 06:26:15 +01:00
Don't segfault when <default> is missing
Also add a framework for schema compiler tests. Fixes bug 616086.
This commit is contained in:
parent
ccbafd0f14
commit
4a605693fc
@ -390,6 +390,14 @@ end_element (GMarkupParseContext *context,
|
|||||||
|
|
||||||
else if (strcmp (element_name, "key") == 0)
|
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_value (state->key, state->value);
|
||||||
gvdb_item_set_options (state->key,
|
gvdb_item_set_options (state->key,
|
||||||
g_variant_builder_end (&state->key_options));
|
g_variant_builder_end (&state->key_options));
|
||||||
@ -521,7 +529,7 @@ main (int argc, char **argv)
|
|||||||
{
|
{
|
||||||
if (g_str_has_suffix (file, ".gschema.xml"))
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +34,8 @@ TEST_PROGS += \
|
|||||||
simple-async-result \
|
simple-async-result \
|
||||||
srvtarget \
|
srvtarget \
|
||||||
contexts \
|
contexts \
|
||||||
gsettings
|
gsettings \
|
||||||
|
gschema-compile
|
||||||
|
|
||||||
SAMPLE_PROGS = \
|
SAMPLE_PROGS = \
|
||||||
resolver \
|
resolver \
|
||||||
@ -146,7 +147,14 @@ contexts_LDADD = $(progs_ldadd) \
|
|||||||
gsettings_SOURCES = gsettings.c
|
gsettings_SOURCES = gsettings.c
|
||||||
gsettings_LDADD = $(progs_ldadd)
|
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
|
MISC_STUFF = gschemas.compiled test.mo
|
||||||
|
|
||||||
@ -158,4 +166,10 @@ test.mo: de.po
|
|||||||
gschemas.compiled:
|
gschemas.compiled:
|
||||||
$(top_builddir)/gio/gschema-compile --targetdir=$(abs_builddir) $(srcdir)
|
$(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
|
||||||
|
35
gio/tests/gschema-compile.c
Normal file
35
gio/tests/gschema-compile.c
Normal 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 ();
|
||||||
|
}
|
6
gio/tests/schema-tests/no-default/no-default.gschema.xml
Normal file
6
gio/tests/schema-tests/no-default/no-default.gschema.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<schemalist>
|
||||||
|
<schema id="no-default" path="/tests/">
|
||||||
|
<key name="test" type="s">
|
||||||
|
</key>
|
||||||
|
</schema>
|
||||||
|
</schemalist>
|
Loading…
Reference in New Issue
Block a user