Debian Codegraph @

vendored-meson/meson/test cases/frameworks/7 gnome/schemas/schemaprog.c

raw
1 #include<gio/gio.h>
2 #include<stdio.h>
3 #include<string.h>
4
5 int main(int argc, char **argv) {
6 GSettingsSchemaSource *src;
7 GSettingsSchema *schema;
8 GSettings *settings;
9 GVariant *value;
10
11 GError *error = NULL;
12 src = g_settings_schema_source_new_from_directory("schemas",
13 g_settings_schema_source_get_default(), TRUE, &error);
14 if(error) {
15 fprintf(stderr, "Fail: %s\n", error->message);
16 g_error_free(error);
17 return 1;
18 }
19
20 schema = g_settings_schema_source_lookup(src, "com.github.meson", FALSE);
21 if(!schema) {
22 fprintf(stderr, "Could not get schema from source.\n");
23 return 2;
24 }
25
26 settings = g_settings_new_full(schema, NULL, NULL);
27 if(!settings) {
28 fprintf(stderr, "Could not get settings object.\n");
29 return 3;
30 }
31
32 value = g_settings_get_value(settings, "greeting");
33 if(!value) {
34 fprintf(stderr, "Could not get value from settings.\n");
35 return 4;
36 }
37
38 if(strcmp("Hello", g_variant_get_string(value, NULL)) != 0) {
39 fprintf(stderr, "Value of setting is incorrect.\n");
40 return 5;
41 }
42 g_variant_unref(value);
43 g_object_unref(settings);
44 g_settings_schema_unref(schema);
45 g_settings_schema_source_unref(src);
46 return 0;
47 }