GSettings: enum/choices/aliases/range test cases
authorRyan Lortie <desrt@desrt.ca>
Thu, 17 Jun 2010 04:03:44 +0000 (00:03 -0400)
committerRyan Lortie <desrt@desrt.ca>
Thu, 17 Jun 2010 04:03:44 +0000 (00:03 -0400)
Fix a small bug that one of the tests uncovered.

29 files changed:
gio/gschema-compile.c
gio/strinfo.c
gio/tests/.gitignore
gio/tests/gschema-compile.c
gio/tests/schema-tests/bad-choice.gschema.xml [new file with mode: 0644]
gio/tests/schema-tests/bare-alias.gschema.xml [new file with mode: 0644]
gio/tests/schema-tests/choice-alias.gschema.xml [new file with mode: 0644]
gio/tests/schema-tests/choice-bad.gschema.xml [new file with mode: 0644]
gio/tests/schema-tests/choice-badtype.gschema.xml [new file with mode: 0644]
gio/tests/schema-tests/choice-invalid-alias.gschema.xml [new file with mode: 0644]
gio/tests/schema-tests/choice-shadowed-alias.gschema.xml [new file with mode: 0644]
gio/tests/schema-tests/choice-upside-down.gschema.xml [new file with mode: 0644]
gio/tests/schema-tests/choice.gschema.xml [new file with mode: 0644]
gio/tests/schema-tests/default-in-aliases.gschema.xml [new file with mode: 0644]
gio/tests/schema-tests/enum-with-aliases.gschema.xml [new file with mode: 0644]
gio/tests/schema-tests/enum-with-bad-default.gschema.xml [new file with mode: 0644]
gio/tests/schema-tests/enum-with-chained-alias.gschema.xml [new file with mode: 0644]
gio/tests/schema-tests/enum-with-choice.gschema.xml [new file with mode: 0644]
gio/tests/schema-tests/enum-with-invalid-alias.gschema.xml [new file with mode: 0644]
gio/tests/schema-tests/enum-with-repeated-alias.gschema.xml [new file with mode: 0644]
gio/tests/schema-tests/enum-with-shadow-alias.gschema.xml [new file with mode: 0644]
gio/tests/schema-tests/enum.gschema.xml [new file with mode: 0644]
gio/tests/schema-tests/range-badtype.gschema.xml [new file with mode: 0644]
gio/tests/schema-tests/range-default-high.gschema.xml [new file with mode: 0644]
gio/tests/schema-tests/range-default-low.gschema.xml [new file with mode: 0644]
gio/tests/schema-tests/range-high-default.gschema.xml [new file with mode: 0644]
gio/tests/schema-tests/range-low-default.gschema.xml [new file with mode: 0644]
gio/tests/schema-tests/range-parse-error.gschema.xml [new file with mode: 0644]
gio/tests/schema-tests/range.gschema.xml [new file with mode: 0644]

index 87fd3fb2e5c7cf1be845511b124d7ca9203cb3d5..dd4a4455618db08f933a74549e42dd627eed98ff 100644 (file)
@@ -252,7 +252,7 @@ key_state_set_range (KeyState     *state,
       gchar *type = g_variant_type_dup_string (state->type);
       g_set_error (error, G_MARKUP_ERROR,
                   G_MARKUP_ERROR_INVALID_CONTENT,
-                  "<range> not allowed for keys of type \"%s\"\n", type);
+                  "<range> not allowed for keys of type '%s'", type);
       g_free (type);
       return;
     }
@@ -1034,11 +1034,11 @@ start_element (GMarkupParseContext  *context,
 
   if (container)
     g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_UNKNOWN_ELEMENT,
-                 "Element <%s> not allowed inside <%s>\n",
+                 "Element <%s> not allowed inside <%s>",
                  element_name, container);
   else
     g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_UNKNOWN_ELEMENT,
-                 "Element <%s> not allowed at toplevel\n", element_name);
+                 "Element <%s> not allowed at toplevel", element_name);
 }
 /* 2}}} */
 /* End element {{{2 */
@@ -1056,7 +1056,7 @@ key_state_end (KeyState **state_ptr,
     {
       g_set_error_literal (error,
                            G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
-                           "element <default> is required in <key>\n");
+                           "element <default> is required in <key>");
       return;
     }
 }
@@ -1128,7 +1128,7 @@ text (GMarkupParseContext  *context,
 
         else
           g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
-                       "text may not appear inside <%s>\n",
+                       "text may not appear inside <%s>",
                        g_markup_parse_context_get_element (context));
 
         break;
index 04c90c0605eab4b83368bf03bed8df8308038b5b..9ba18aa40b78bc766c64a53fe1c9e02f8ec8c1bd 100644 (file)
@@ -304,5 +304,5 @@ strinfo_builder_contains (GString     *builder,
   return strinfo_find_string ((const guint32 *) builder->str,
                               builder->len / 4, string, FALSE) != -1 ||
          strinfo_find_string ((const guint32 *) builder->str,
-                              builder->len / 4, string, FALSE) != -1;
+                              builder->len / 4, string, TRUE) != -1;
 }
index f0a70bc141002bed2a2ae130f2bae74643523165..a4914e43214bc46ace12514b6539b3e43f741507 100644 (file)
@@ -58,3 +58,4 @@ test.mo
 unix-fd
 unix-streams
 utf8-input-streamgdbus-addresses
+org.gtk.test.enums.xml
index 9201abd8ea4cab2432b6ba4dc912d1955e0bc5d8..477bab9988b546ea7dc8e9ed66e136066bdf35ed 100644 (file)
@@ -66,7 +66,32 @@ static const SchemaTest tests[] = {
   { "bad-key4",                     NULL, "*invalid name*"                                      },
   { "bad-key4",                     "--allow-any-name", NULL                                    },
   { "empty-key",                    NULL, "*empty names*"                                       },
-  { "empty-key",                    "--allow-any-name", "*empty names*"                         }
+  { "empty-key",                    "--allow-any-name", "*empty names*"                         },
+  { "enum",                         NULL, NULL                                                  },
+  { "enum-with-aliases",            NULL, NULL                                                  },
+  { "enum-with-invalid-alias",      NULL, "*'banger' is not in enumerated type*"                },
+  { "enum-with-repeated-alias",     NULL, "*<alias value='sausages'/> already specified*"       },
+  { "enum-with-chained-alias",      NULL, "*'sausages' is not in enumerated type*"              },
+  { "enum-with-shadow-alias",       NULL, "*'mash' is already a member of the enum*"            },
+  { "enum-with-choice",             NULL, "*<choices> can not be specified*"                    },
+  { "enum-with-bad-default",        NULL, "*<default> is not a valid member*"                   },
+  { "choice",                       NULL, NULL                                                  },
+  { "choice-upside-down",           NULL, NULL                                                  },
+  { "bad-choice",                   NULL, "*<default> contains string not in <choices>*"        },
+  { "choice-bad",                   NULL, "*<default> contains string not in <choices>*"        },
+  { "choice-badtype",               NULL, "*<choices> not allowed for keys of type 'i'*"        },
+  { "bare-alias",                   NULL, "*enumerated types or after <choices>*"               },
+  { "choice-alias",                 NULL, NULL                                                  },
+  { "default-in-aliases",           NULL, "*<default> contains string not in <choices>*"        },
+  { "choice-invalid-alias",         NULL, "*'befor' is not in <choices>*"                       },
+  { "choice-shadowed-alias",        NULL, "*given when <choice value='before'/> was already*"   },
+  { "range",                        NULL, NULL                                                  },
+  { "range-badtype",                NULL, "*<range> not allowed for keys of type 's'*"          },
+  { "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*" },
+  { "range-parse-error",            NULL, "*invalid character in number*"                       }
 };
 
 int
diff --git a/gio/tests/schema-tests/bad-choice.gschema.xml b/gio/tests/schema-tests/bad-choice.gschema.xml
new file mode 100644 (file)
index 0000000..07640d5
--- /dev/null
@@ -0,0 +1,14 @@
+<schemalist>
+  <schema id='org.gtk.test.schema'>
+    <key name='test' type='s'>
+      <default>'how'</default>
+      <choices>
+        <choice value='who'/>
+        <choice value='what'/>
+        <choice value='where'/>
+        <choice value='when'/>
+        <choice value='why'/>
+      </choices>
+    </key>
+  </schema>
+</schemalist>
diff --git a/gio/tests/schema-tests/bare-alias.gschema.xml b/gio/tests/schema-tests/bare-alias.gschema.xml
new file mode 100644 (file)
index 0000000..52184cd
--- /dev/null
@@ -0,0 +1,7 @@
+<schemalist>
+  <schema id='org.gtk.test.schema'>
+    <key name='test' type='s'>
+      <aliases/>
+    </key>
+  </schema>
+</schemalist>
diff --git a/gio/tests/schema-tests/choice-alias.gschema.xml b/gio/tests/schema-tests/choice-alias.gschema.xml
new file mode 100644 (file)
index 0000000..d5c9279
--- /dev/null
@@ -0,0 +1,15 @@
+<schemalist>
+  <schema id='org.gtk.test.schema'>
+    <key name='test' type='s'>
+      <choices>
+        <choice value='before'/>
+        <choice value='after'/>
+      </choices>
+      <aliases>
+        <alias value='pre' target='before'/>
+        <alias value='post' target='after'/>
+      </aliases>
+      <default>'after'</default>
+    </key>
+  </schema>
+</schemalist>
diff --git a/gio/tests/schema-tests/choice-bad.gschema.xml b/gio/tests/schema-tests/choice-bad.gschema.xml
new file mode 100644 (file)
index 0000000..4a2dbc2
--- /dev/null
@@ -0,0 +1,14 @@
+<schemalist>
+  <schema id='org.gtk.test.schema'>
+    <key name='test' type='s'>
+      <choices>
+        <choice value='who'/>
+        <choice value='what'/>
+        <choice value='where'/>
+        <choice value='when'/>
+        <choice value='why'/>
+      </choices>
+      <default>'how'</default>
+    </key>
+  </schema>
+</schemalist>
diff --git a/gio/tests/schema-tests/choice-badtype.gschema.xml b/gio/tests/schema-tests/choice-badtype.gschema.xml
new file mode 100644 (file)
index 0000000..88104c5
--- /dev/null
@@ -0,0 +1,7 @@
+<schemalist>
+  <schema id='org.gtk.test.schema'>
+    <key name='test' type='i'>
+      <choices/>
+    </key>
+  </schema>
+</schemalist>
diff --git a/gio/tests/schema-tests/choice-invalid-alias.gschema.xml b/gio/tests/schema-tests/choice-invalid-alias.gschema.xml
new file mode 100644 (file)
index 0000000..ae5bcd3
--- /dev/null
@@ -0,0 +1,15 @@
+<schemalist>
+  <schema id='org.gtk.test.schema'>
+    <key name='test' type='s'>
+      <choices>
+        <choice value='before'/>
+        <choice value='after'/>
+      </choices>
+      <aliases>
+        <alias value='pre' target='befor'/>
+        <alias value='post' target='after'/>
+      </aliases>
+      <default>'after'</default>
+    </key>
+  </schema>
+</schemalist>
diff --git a/gio/tests/schema-tests/choice-shadowed-alias.gschema.xml b/gio/tests/schema-tests/choice-shadowed-alias.gschema.xml
new file mode 100644 (file)
index 0000000..fb68e32
--- /dev/null
@@ -0,0 +1,14 @@
+<schemalist>
+  <schema id='org.gtk.test.schema'>
+    <key name='test' type='s'>
+      <choices>
+        <choice value='before'/>
+        <choice value='after'/>
+      </choices>
+      <aliases>
+        <alias value='before' target='after'/>
+      </aliases>
+      <default>'after'</default>
+    </key>
+  </schema>
+</schemalist>
diff --git a/gio/tests/schema-tests/choice-upside-down.gschema.xml b/gio/tests/schema-tests/choice-upside-down.gschema.xml
new file mode 100644 (file)
index 0000000..ea6f532
--- /dev/null
@@ -0,0 +1,14 @@
+<schemalist>
+  <schema id='org.gtk.test.schema'>
+    <key name='test' type='s'>
+      <choices>
+        <choice value='who'/>
+        <choice value='what'/>
+        <choice value='where'/>
+        <choice value='when'/>
+        <choice value='why'/>
+      </choices>
+      <default>'who'</default>
+    </key>
+  </schema>
+</schemalist>
diff --git a/gio/tests/schema-tests/choice.gschema.xml b/gio/tests/schema-tests/choice.gschema.xml
new file mode 100644 (file)
index 0000000..c9d7426
--- /dev/null
@@ -0,0 +1,14 @@
+<schemalist>
+  <schema id='org.gtk.test.schema'>
+    <key name='test' type='s'>
+      <default>'who'</default>
+      <choices>
+        <choice value='who'/>
+        <choice value='what'/>
+        <choice value='where'/>
+        <choice value='when'/>
+        <choice value='why'/>
+      </choices>
+    </key>
+  </schema>
+</schemalist>
diff --git a/gio/tests/schema-tests/default-in-aliases.gschema.xml b/gio/tests/schema-tests/default-in-aliases.gschema.xml
new file mode 100644 (file)
index 0000000..81d639f
--- /dev/null
@@ -0,0 +1,15 @@
+<schemalist>
+  <schema id='org.gtk.test.schema'>
+    <key name='test' type='s'>
+      <choices>
+        <choice value='before'/>
+        <choice value='after'/>
+      </choices>
+      <aliases>
+        <alias value='pre' target='before'/>
+        <alias value='post' target='after'/>
+      </aliases>
+      <default>'pre'</default>
+    </key>
+  </schema>
+</schemalist>
diff --git a/gio/tests/schema-tests/enum-with-aliases.gschema.xml b/gio/tests/schema-tests/enum-with-aliases.gschema.xml
new file mode 100644 (file)
index 0000000..e8c1e68
--- /dev/null
@@ -0,0 +1,20 @@
+<schemalist>
+  <enum id='org.gtk.test.MyEnum'>
+    <value nick='nospam' value='0'/>
+    <value nick='spam' value='1'/>
+    <value nick='ham' value='2'/>
+    <value nick='eggs' value='3'/>
+    <value nick='bangers' value='4'/>
+    <value nick='mash' value='5'/>
+  </enum>
+
+  <schema id='org.gtk.test.schema'>
+    <key name='test' enum='org.gtk.test.MyEnum'>
+      <default>'spam'</default>
+
+      <aliases>
+        <alias value='sausages' target='bangers'/>
+      </aliases>
+    </key>
+  </schema>
+</schemalist>
diff --git a/gio/tests/schema-tests/enum-with-bad-default.gschema.xml b/gio/tests/schema-tests/enum-with-bad-default.gschema.xml
new file mode 100644 (file)
index 0000000..aee0867
--- /dev/null
@@ -0,0 +1,16 @@
+<schemalist>
+  <enum id='org.gtk.test.MyEnum'>
+    <value nick='nospam' value='0'/>
+    <value nick='spam' value='1'/>
+    <value nick='ham' value='2'/>
+    <value nick='eggs' value='3'/>
+    <value nick='bangers' value='4'/>
+    <value nick='mash' value='5'/>
+  </enum>
+
+  <schema id='org.gtk.test.schema'>
+    <key name='test' enum='org.gtk.test.MyEnum'>
+      <default>'nie'</default>
+    </key>
+  </schema>
+</schemalist>
diff --git a/gio/tests/schema-tests/enum-with-chained-alias.gschema.xml b/gio/tests/schema-tests/enum-with-chained-alias.gschema.xml
new file mode 100644 (file)
index 0000000..65c31e3
--- /dev/null
@@ -0,0 +1,21 @@
+<schemalist>
+  <enum id='org.gtk.test.MyEnum'>
+    <value nick='nospam' value='0'/>
+    <value nick='spam' value='1'/>
+    <value nick='ham' value='2'/>
+    <value nick='eggs' value='3'/>
+    <value nick='bangers' value='4'/>
+    <value nick='mash' value='5'/>
+  </enum>
+
+  <schema id='org.gtk.test.schema'>
+    <key name='test' enum='org.gtk.test.MyEnum'>
+      <default>'spam'</default>
+
+      <aliases>
+        <alias value='sausages' target='bangers'/>
+        <alias value='wurst' target='sausages'/>
+      </aliases>
+    </key>
+  </schema>
+</schemalist>
diff --git a/gio/tests/schema-tests/enum-with-choice.gschema.xml b/gio/tests/schema-tests/enum-with-choice.gschema.xml
new file mode 100644 (file)
index 0000000..50caf21
--- /dev/null
@@ -0,0 +1,17 @@
+<schemalist>
+  <enum id='org.gtk.test.MyEnum'>
+    <value nick='nospam' value='0'/>
+    <value nick='spam' value='1'/>
+    <value nick='ham' value='2'/>
+    <value nick='eggs' value='3'/>
+    <value nick='bangers' value='4'/>
+    <value nick='mash' value='5'/>
+  </enum>
+
+  <schema id='org.gtk.test.schema'>
+    <key name='test' enum='org.gtk.test.MyEnum'>
+      <default>'spam'</default>
+      <choices/>
+    </key>
+  </schema>
+</schemalist>
diff --git a/gio/tests/schema-tests/enum-with-invalid-alias.gschema.xml b/gio/tests/schema-tests/enum-with-invalid-alias.gschema.xml
new file mode 100644 (file)
index 0000000..51a51fd
--- /dev/null
@@ -0,0 +1,20 @@
+<schemalist>
+  <enum id='org.gtk.test.MyEnum'>
+    <value nick='nospam' value='0'/>
+    <value nick='spam' value='1'/>
+    <value nick='ham' value='2'/>
+    <value nick='eggs' value='3'/>
+    <value nick='bangers' value='4'/>
+    <value nick='mash' value='5'/>
+  </enum>
+
+  <schema id='org.gtk.test.schema'>
+    <key name='test' enum='org.gtk.test.MyEnum'>
+      <default>'spam'</default>
+
+      <aliases>
+        <alias value='sausages' target='banger'/>
+      </aliases>
+    </key>
+  </schema>
+</schemalist>
diff --git a/gio/tests/schema-tests/enum-with-repeated-alias.gschema.xml b/gio/tests/schema-tests/enum-with-repeated-alias.gschema.xml
new file mode 100644 (file)
index 0000000..a13ef89
--- /dev/null
@@ -0,0 +1,21 @@
+<schemalist>
+  <enum id='org.gtk.test.MyEnum'>
+    <value nick='nospam' value='0'/>
+    <value nick='spam' value='1'/>
+    <value nick='ham' value='2'/>
+    <value nick='eggs' value='3'/>
+    <value nick='bangers' value='4'/>
+    <value nick='mash' value='5'/>
+  </enum>
+
+  <schema id='org.gtk.test.schema'>
+    <key name='test' enum='org.gtk.test.MyEnum'>
+      <default>'spam'</default>
+
+      <aliases>
+        <alias value='sausages' target='bangers'/>
+        <alias value='sausages' target='mash'/>
+      </aliases>
+    </key>
+  </schema>
+</schemalist>
diff --git a/gio/tests/schema-tests/enum-with-shadow-alias.gschema.xml b/gio/tests/schema-tests/enum-with-shadow-alias.gschema.xml
new file mode 100644 (file)
index 0000000..52e30ee
--- /dev/null
@@ -0,0 +1,20 @@
+<schemalist>
+  <enum id='org.gtk.test.MyEnum'>
+    <value nick='nospam' value='0'/>
+    <value nick='spam' value='1'/>
+    <value nick='ham' value='2'/>
+    <value nick='eggs' value='3'/>
+    <value nick='bangers' value='4'/>
+    <value nick='mash' value='5'/>
+  </enum>
+
+  <schema id='org.gtk.test.schema'>
+    <key name='test' enum='org.gtk.test.MyEnum'>
+      <default>'spam'</default>
+
+      <aliases>
+        <alias value='mash' target='bangers'/>
+      </aliases>
+    </key>
+  </schema>
+</schemalist>
diff --git a/gio/tests/schema-tests/enum.gschema.xml b/gio/tests/schema-tests/enum.gschema.xml
new file mode 100644 (file)
index 0000000..8cf5879
--- /dev/null
@@ -0,0 +1,16 @@
+<schemalist>
+  <enum id='org.gtk.test.MyEnum'>
+    <value nick='nospam' value='0'/>
+    <value nick='spam' value='1'/>
+    <value nick='ham' value='2'/>
+    <value nick='eggs' value='3'/>
+    <value nick='bangers' value='4'/>
+    <value nick='mash' value='5'/>
+  </enum>
+
+  <schema id='org.gtk.test.schema'>
+    <key name='test' enum='org.gtk.test.MyEnum'>
+      <default>'spam'</default>
+    </key>
+  </schema>
+</schemalist>
diff --git a/gio/tests/schema-tests/range-badtype.gschema.xml b/gio/tests/schema-tests/range-badtype.gschema.xml
new file mode 100644 (file)
index 0000000..14a7217
--- /dev/null
@@ -0,0 +1,7 @@
+<schemalist>
+  <schema id='org.gtk.test.schema'>
+    <key name='test' type='s'>
+      <range min='22' max='27'/>
+    </key>
+  </schema>
+</schemalist>
diff --git a/gio/tests/schema-tests/range-default-high.gschema.xml b/gio/tests/schema-tests/range-default-high.gschema.xml
new file mode 100644 (file)
index 0000000..b5feb3e
--- /dev/null
@@ -0,0 +1,8 @@
+<schemalist>
+  <schema id='org.gtk.test.schema'>
+    <key name='test' type='i'>
+      <default>28</default>
+      <range min='22' max='27'/>
+    </key>
+  </schema>
+</schemalist>
diff --git a/gio/tests/schema-tests/range-default-low.gschema.xml b/gio/tests/schema-tests/range-default-low.gschema.xml
new file mode 100644 (file)
index 0000000..f8fb9ef
--- /dev/null
@@ -0,0 +1,8 @@
+<schemalist>
+  <schema id='org.gtk.test.schema'>
+    <key name='test' type='i'>
+      <default>21</default>
+      <range min='22' max='27'/>
+    </key>
+  </schema>
+</schemalist>
diff --git a/gio/tests/schema-tests/range-high-default.gschema.xml b/gio/tests/schema-tests/range-high-default.gschema.xml
new file mode 100644 (file)
index 0000000..0f01fc8
--- /dev/null
@@ -0,0 +1,8 @@
+<schemalist>
+  <schema id='org.gtk.test.schema'>
+    <key name='test' type='i'>
+      <range min='22' max='27'/>
+      <default>28</default>
+    </key>
+  </schema>
+</schemalist>
diff --git a/gio/tests/schema-tests/range-low-default.gschema.xml b/gio/tests/schema-tests/range-low-default.gschema.xml
new file mode 100644 (file)
index 0000000..49db491
--- /dev/null
@@ -0,0 +1,8 @@
+<schemalist>
+  <schema id='org.gtk.test.schema'>
+    <key name='test' type='i'>
+      <range min='22' max='27'/>
+      <default>21</default>
+    </key>
+  </schema>
+</schemalist>
diff --git a/gio/tests/schema-tests/range-parse-error.gschema.xml b/gio/tests/schema-tests/range-parse-error.gschema.xml
new file mode 100644 (file)
index 0000000..58ddb50
--- /dev/null
@@ -0,0 +1,8 @@
+<schemalist>
+  <schema id='org.gtk.test.schema'>
+    <key name='test' type='i'>
+      <range min='22.5' max='27'/>
+      <default>25</default>
+    </key>
+  </schema>
+</schemalist>
diff --git a/gio/tests/schema-tests/range.gschema.xml b/gio/tests/schema-tests/range.gschema.xml
new file mode 100644 (file)
index 0000000..59118bd
--- /dev/null
@@ -0,0 +1,8 @@
+<schemalist>
+  <schema id='org.gtk.test.schema'>
+    <key name='test' type='i'>
+      <range min='22' max='27'/>
+      <default>25</default>
+    </key>
+  </schema>
+</schemalist>