From 3628b0b4992e9d1c915c38f8844eab9ba7a7112f Mon Sep 17 00:00:00 2001 From: Ryan Lortie Date: Tue, 29 Jun 2010 20:24:39 -0400 Subject: [PATCH] GSettings: add , tests, modify output Add tag, more tests, and actually output the results of these new tags to the gschemas.compiled file. --- gio/gschema-compile.c | 149 ++++++++++++++++-- gio/tests/Makefile.am | 8 + gio/tests/gschema-compile.c | 10 +- .../extend-and-shadow-indirect.gschema.xml | 17 ++ .../extend-and-shadow.gschema.xml | 17 ++ .../schema-tests/override-missing.gschema.xml | 11 ++ .../override-range-error.gschema.xml | 12 ++ .../override-then-key.gschema.xml | 15 ++ .../schema-tests/override-twice.gschema.xml | 12 ++ .../override-type-error.gschema.xml | 11 ++ gio/tests/schema-tests/override.gschema.xml | 34 ++++ 11 files changed, 284 insertions(+), 12 deletions(-) create mode 100644 gio/tests/schema-tests/extend-and-shadow-indirect.gschema.xml create mode 100644 gio/tests/schema-tests/extend-and-shadow.gschema.xml create mode 100644 gio/tests/schema-tests/override-missing.gschema.xml create mode 100644 gio/tests/schema-tests/override-range-error.gschema.xml create mode 100644 gio/tests/schema-tests/override-then-key.gschema.xml create mode 100644 gio/tests/schema-tests/override-twice.gschema.xml create mode 100644 gio/tests/schema-tests/override-type-error.gschema.xml create mode 100644 gio/tests/schema-tests/override.gschema.xml diff --git a/gio/gschema-compile.c b/gio/gschema-compile.c index 004a3b1e5..37ddf33e8 100644 --- a/gio/gschema-compile.c +++ b/gio/gschema-compile.c @@ -122,6 +122,7 @@ typedef struct gboolean has_choices; gboolean has_aliases; + gboolean is_override; gboolean checked; GVariant *serialised; @@ -146,6 +147,29 @@ key_state_new (const gchar *type_string, return state; } +static KeyState * +key_state_override (KeyState *state, + const gchar *gettext_domain) +{ + KeyState *copy; + + copy = g_slice_new0 (KeyState); + copy->type = g_variant_type_copy (state->type); + copy->have_gettext_domain = gettext_domain != NULL; + copy->strinfo = g_string_new_len (state->strinfo->str, + state->strinfo->len); + copy->is_enum = state->is_enum; + copy->is_override = TRUE; + + if (state->minimum) + { + copy->minimum = g_variant_ref (state->minimum); + copy->maximum = g_variant_ref (state->maximum); + } + + return copy; +} + static KeyState * key_state_new_child (const gchar *child_schema) { @@ -201,6 +225,10 @@ key_state_check_range (KeyState *state, { if (state->default_value) { + const gchar *tag; + + tag = state->is_override ? "override" : "default"; + if (state->minimum) { if (g_variant_compare (state->default_value, state->minimum) < 0 || @@ -208,8 +236,8 @@ key_state_check_range (KeyState *state, { g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, - " is not contained in " - "the specified range"); + "<%s> is not contained in " + "the specified range", tag); } } @@ -218,16 +246,16 @@ key_state_check_range (KeyState *state, if (!is_valid_choices (state->default_value, state->strinfo)) { if (state->is_enum) - g_set_error_literal (error, G_MARKUP_ERROR, - G_MARKUP_ERROR_INVALID_CONTENT, - " is not a valid member of " - "the specified enumerated type"); + g_set_error (error, G_MARKUP_ERROR, + G_MARKUP_ERROR_INVALID_CONTENT, + "<%s> is not a valid member of " + "the specified enumerated type", tag); else - g_set_error_literal (error, G_MARKUP_ERROR, - G_MARKUP_ERROR_INVALID_CONTENT, - " contains string not in " - ""); + g_set_error (error, G_MARKUP_ERROR, + G_MARKUP_ERROR_INVALID_CONTENT, + "<%s> contains string not in " + "", tag); } } } @@ -749,6 +777,7 @@ schema_state_add_key (SchemaState *state, GError **error) { GString *enum_data; + SchemaState *node; KeyState *key; if (state->list_of) @@ -770,6 +799,27 @@ schema_state_add_key (SchemaState *state, return NULL; } + for (node = state; node; node = node->extends) + if (node->extends) + { + KeyState *shadow; + + shadow = g_hash_table_lookup (node->extends->keys, name); + + /* in case of make sure we report the + * location of the original , not the . + */ + if (shadow && !shadow->is_override) + { + g_set_error (error, G_MARKUP_ERROR, + G_MARKUP_ERROR_INVALID_CONTENT, + " shadows in " + "; use to modify value", + name, name, node->extends_name); + return NULL; + } + } + if ((type_string == NULL) == (enum_type == NULL)) { g_set_error (error, G_MARKUP_ERROR, @@ -813,6 +863,61 @@ schema_state_add_key (SchemaState *state, return key; } +static void +schema_state_add_override (SchemaState *state, + KeyState **key_state, + GString **string, + const gchar *key, + const gchar *l10n, + const gchar *context, + GError **error) +{ + SchemaState *parent; + KeyState *original; + + if (state->extends == NULL) + { + g_set_error_literal (error, G_MARKUP_ERROR, + G_MARKUP_ERROR_INVALID_CONTENT, + " given but schema isn't " + "extending anything"); + return; + } + + for (parent = state->extends; parent; parent = parent->extends) + if ((original = g_hash_table_lookup (parent->keys, key))) + break; + + if (original == NULL) + { + g_set_error (error, G_MARKUP_ERROR, + G_MARKUP_ERROR_INVALID_CONTENT, + "no to override", key); + return; + } + + if (g_hash_table_lookup (state->keys, key)) + { + g_set_error (error, G_MARKUP_ERROR, + G_MARKUP_ERROR_INVALID_CONTENT, + " already specified", key); + return; + } + + *key_state = key_state_override (original, state->gettext_domain); + *string = key_state_start_default (*key_state, l10n, context, error); + g_hash_table_insert (state->keys, g_strdup (key), *key_state); +} + +static void +override_state_end (KeyState **key_state, + GString **string, + GError **error) +{ + key_state_end_default (*key_state, string, error); + *key_state = NULL; +} + /* Handling of toplevel state {{{1 */ typedef struct { @@ -1048,8 +1153,19 @@ start_element (GMarkupParseContext *context, name, schema, error); return; } - } + else if (strcmp (element_name, "override") == 0) + { + const gchar *name, *l10n, *context; + if (COLLECT (STRING, "name", &name, + OPTIONAL | STRING, "l10n", &l10n, + OPTIONAL | STRING, "context", &context)) + schema_state_add_override (state->schema_state, + &state->key_state, &state->string, + name, l10n, context, error); + return; + } + } /* children of {{{3 */ else if (strcmp (container, "key") == 0) @@ -1195,6 +1311,9 @@ end_element (GMarkupParseContext *context, else if (strcmp (element_name, "schema") == 0) schema_state_end (&state->schema_state, error); + else if (strcmp (element_name, "override") == 0) + override_state_end (&state->key_state, &state->string, error); + else if (strcmp (element_name, "key") == 0) key_state_end (&state->key_state, error); @@ -1308,6 +1427,14 @@ output_schema (gpointer key, if (state->path) gvdb_hash_table_insert_string (data.pair.table, ".path", state->path); + if (state->extends_name) + gvdb_hash_table_insert_string (data.pair.table, ".extends", + state->extends_name); + + if (state->list_of) + gvdb_hash_table_insert_string (data.pair.table, ".list-of", + state->extends_name); + if (data.l10n) gvdb_hash_table_insert_string (data.pair.table, ".gettext-domain", diff --git a/gio/tests/Makefile.am b/gio/tests/Makefile.am index 4ddf0d350..d95c6184a 100644 --- a/gio/tests/Makefile.am +++ b/gio/tests/Makefile.am @@ -302,6 +302,8 @@ schema_tests = \ schema-tests/enum-with-repeated-alias.gschema.xml \ schema-tests/enum-with-shadow-alias.gschema.xml \ schema-tests/enum.gschema.xml \ + schema-tests/extend-and-shadow-indirect.gschema.xml \ + schema-tests/extend-and-shadow.gschema.xml \ schema-tests/extend-missing.gschema.xml \ schema-tests/extend-nonlist.gschema.xml \ schema-tests/extend-self.gschema.xml \ @@ -317,6 +319,12 @@ schema_tests = \ schema-tests/missing-quotes.gschema.xml \ schema-tests/no-default.gschema.xml \ schema-tests/overflow.gschema.xml \ + schema-tests/override-missing.gschema.xml \ + schema-tests/override-range-error.gschema.xml \ + schema-tests/override-then-key.gschema.xml \ + schema-tests/override-twice.gschema.xml \ + schema-tests/override-type-error.gschema.xml \ + schema-tests/override.gschema.xml \ schema-tests/range-badtype.gschema.xml \ schema-tests/range-default-high.gschema.xml \ schema-tests/range-default-low.gschema.xml \ diff --git a/gio/tests/gschema-compile.c b/gio/tests/gschema-compile.c index c3961d155..983a1c88b 100644 --- a/gio/tests/gschema-compile.c +++ b/gio/tests/gschema-compile.c @@ -101,7 +101,15 @@ static const SchemaTest tests[] = { { "extend-wrong-list", NULL, "*'y' does not extend 'x'*" }, { "key-in-list-indirect", NULL, "*can not add keys to a list*" }, { "key-in-list", NULL, "*can not add keys to a list*" }, - { "list-of-missing", NULL, "*is list of not yet existing schema*" } + { "list-of-missing", NULL, "*is list of not yet existing schema*" }, + { "extend-and-shadow", NULL, "*shadows*use *" }, + { "extend-and-shadow-indirect", NULL, "*shadows*use *" }, + { "override", NULL, NULL }, + { "override-missing", NULL, "*no to override*" }, + { "override-range-error", NULL, "* is not contained in the specified range*"}, + { "override-then-key", NULL, "*shadows in *" }, + { "override-twice", NULL, "* already specified*" }, + { "override-type-error", NULL, "*invalid character in number*" } }; int diff --git a/gio/tests/schema-tests/extend-and-shadow-indirect.gschema.xml b/gio/tests/schema-tests/extend-and-shadow-indirect.gschema.xml new file mode 100644 index 000000000..dc066dd3f --- /dev/null +++ b/gio/tests/schema-tests/extend-and-shadow-indirect.gschema.xml @@ -0,0 +1,17 @@ + + + + '' + + + + + + '' + + + + + + + diff --git a/gio/tests/schema-tests/extend-and-shadow.gschema.xml b/gio/tests/schema-tests/extend-and-shadow.gschema.xml new file mode 100644 index 000000000..79935b4f3 --- /dev/null +++ b/gio/tests/schema-tests/extend-and-shadow.gschema.xml @@ -0,0 +1,17 @@ + + + + '' + + + + + + '' + + + + + + + diff --git a/gio/tests/schema-tests/override-missing.gschema.xml b/gio/tests/schema-tests/override-missing.gschema.xml new file mode 100644 index 000000000..9a3c781e7 --- /dev/null +++ b/gio/tests/schema-tests/override-missing.gschema.xml @@ -0,0 +1,11 @@ + + + + 'bar' + + + + + 'baz' + + diff --git a/gio/tests/schema-tests/override-range-error.gschema.xml b/gio/tests/schema-tests/override-range-error.gschema.xml new file mode 100644 index 000000000..4887ac3b0 --- /dev/null +++ b/gio/tests/schema-tests/override-range-error.gschema.xml @@ -0,0 +1,12 @@ + + + + + 10 + + + + + 77 + + diff --git a/gio/tests/schema-tests/override-then-key.gschema.xml b/gio/tests/schema-tests/override-then-key.gschema.xml new file mode 100644 index 000000000..85b70bda8 --- /dev/null +++ b/gio/tests/schema-tests/override-then-key.gschema.xml @@ -0,0 +1,15 @@ + + + + 'bar' + + + + + 'baz' + + + + + + diff --git a/gio/tests/schema-tests/override-twice.gschema.xml b/gio/tests/schema-tests/override-twice.gschema.xml new file mode 100644 index 000000000..fe6bb64fa --- /dev/null +++ b/gio/tests/schema-tests/override-twice.gschema.xml @@ -0,0 +1,12 @@ + + + + 'bar' + + + + + 'baz' + 'baz' + + diff --git a/gio/tests/schema-tests/override-type-error.gschema.xml b/gio/tests/schema-tests/override-type-error.gschema.xml new file mode 100644 index 000000000..a16ec0203 --- /dev/null +++ b/gio/tests/schema-tests/override-type-error.gschema.xml @@ -0,0 +1,11 @@ + + + + 10 + + + + + 37.5 + + diff --git a/gio/tests/schema-tests/override.gschema.xml b/gio/tests/schema-tests/override.gschema.xml new file mode 100644 index 000000000..6309884d9 --- /dev/null +++ b/gio/tests/schema-tests/override.gschema.xml @@ -0,0 +1,34 @@ + + + + 'bar' + + + + + 10 + + + + + + + + + 'aaaaa' + + + + + + + + 'baz' + 0 + 'aaa' + + + + 'foo' + +