Bug 631263 - GSettings needs range/choice APIs

Add g_settings_get_range() to describe the possible values that may be
provided to g_settings_set_value() without causing an error.

Add a test case.
This commit is contained in:
Ryan Lortie
2010-10-04 02:58:46 -04:00
parent 833e389516
commit d6d76783ae
4 changed files with 159 additions and 1 deletions

View File

@@ -14,6 +14,20 @@ static gboolean backend_set;
* to be compiled and installed in the same directory.
*/
static void
check_and_free (GVariant *value,
const gchar *expected)
{
gchar *printed;
printed = g_variant_print (value, TRUE);
g_assert_cmpstr (printed, ==, expected);
g_free (printed);
g_variant_unref (value);
}
/* Just to get warmed up: Read and set a string, and
* verify that can read the changed string back
*/
@@ -1843,6 +1857,34 @@ test_get_mapped (void)
g_object_unref (settings);
}
static void
test_get_range (void)
{
GSettings *settings;
GVariant *range;
settings = g_settings_new ("org.gtk.test.range");
range = g_settings_get_range (settings, "val");
check_and_free (range, "('range', <(2, 44)>)");
g_object_unref (settings);
settings = g_settings_new ("org.gtk.test.enums");
range = g_settings_get_range (settings, "test");
check_and_free (range, "('enum', <['foo', 'bar', 'baz', 'quux']>)");
g_object_unref (settings);
settings = g_settings_new ("org.gtk.test.enums");
range = g_settings_get_range (settings, "f-test");
check_and_free (range, "('flags', "
"<['mourning', 'laughing', 'talking', 'walking']>)");
g_object_unref (settings);
settings = g_settings_new ("org.gtk.test");
range = g_settings_get_range (settings, "greeting");
check_and_free (range, "('type', <@as []>)");
g_object_unref (settings);
}
int
main (int argc, char *argv[])
{
@@ -1926,6 +1968,7 @@ main (int argc, char *argv[])
g_test_add_func ("/gsettings/list-items", test_list_items);
g_test_add_func ("/gsettings/list-schemas", test_list_schemas);
g_test_add_func ("/gsettings/mapped", test_get_mapped);
g_test_add_func ("/gsettings/get-range", test_get_range);
result = g_test_run ();