2
* Copyright (C) 1999, 2000 Red Hat Inc.
4
* This library is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Library General Public
6
* License as published by the Free Software Foundation; either
7
* version 2 of the License, or (at your option) any later version.
9
* This library is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* Library General Public License for more details.
14
* You should have received a copy of the GNU Library General Public
15
* License along with this library; if not, write to the
16
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17
* Boston, MA 02111-1307, USA.
20
#include <gconf/gconf.h>
24
#include <gconf/gconf-internals.h>
26
/* glibc printf() functions accept NULL for a %s format, but to be
27
safe, check for null strings and return a printable value */
29
NULL_SAFE(const char *x)
31
return x ? x : "<NULL>";
35
check(gboolean condition, const gchar* fmt, ...)
41
description = g_strdup_vprintf(fmt, args);
51
fprintf(stderr, "\n*** FAILED: %s\n", description);
64
"/testing/q/a/b/c/z/w/x/y/z",
82
static gint ints[] = { -1, -2, -3, 0, 1, 2, 3, 4000, 0xfffff, -0xfffff, G_MININT, G_MAXINT, 0, 0, 57, 83, 95 };
83
static const guint n_ints = sizeof(ints)/sizeof(ints[0]);
86
check_unset(GConfEngine* conf)
89
const gchar** keyp = NULL;
95
gconf_engine_unset(conf, *keyp, &err);
99
fprintf(stderr, "unset of `%s' failed: %s\n", *keyp, err->message);
108
val = gconf_engine_get (conf, *keyp, &err);
112
valstr = gconf_value_to_string(val);
114
valstr = g_strdup("(none)");
116
check(val == NULL, "unsetting a previously-set value `%s' the value `%s' existed", *keyp, valstr);
126
check_int_storage(GConfEngine* conf)
129
const gchar** keyp = NULL;
132
/* Loop over keys, storing all values at each then retrieving them */
143
if (!gconf_engine_set_int(conf, *keyp, ints[i], &err))
145
fprintf(stderr, "Failed to set key `%s' to `%d': %s\n",
146
*keyp, ints[i], err->message);
152
gotten = gconf_engine_get_int(conf, *keyp, &err);
156
check(gotten == 0.0, "0.0 not returned though there was an error");
158
fprintf(stderr, "Failed to get key `%s': %s\n",
159
*keyp, err->message);
165
check (ints[i] == gotten,
166
"int set/get pair: `%d' set, `%d' got",
178
/* Now invert the loop and see if that causes problems */
190
if (!gconf_engine_set_int(conf, *keyp, ints[i], &err))
192
fprintf(stderr, "Failed to set key `%s' to `%d': %s\n",
193
*keyp, ints[i], err->message);
199
gotten = gconf_engine_get_int(conf, *keyp, &err);
203
check(gotten == 0, "0 not returned though there was an error");
205
fprintf(stderr, "Failed to get key `%s': %s\n",
206
*keyp, err->message);
212
check (ints[i] == gotten,
213
"int set/get pair: `%d' set, `%d' got",
230
null_safe_strcmp(const char* lhs, const char* rhs)
232
if (lhs == NULL && rhs == NULL)
234
else if (lhs == NULL)
236
else if (rhs == NULL)
239
return strcmp(lhs, rhs);
243
check_one_schema(GConfEngine* conf, const gchar** keyp, GConfSchema* schema)
247
if (!gconf_engine_set_schema(conf, *keyp, schema, &err))
249
fprintf(stderr, "Failed to set key `%s' to schema: %s\n",
250
*keyp, err->message);
258
gotten = gconf_engine_get_schema(conf, *keyp, &err);
262
check(gotten == NULL, "NULL not returned though there was an error");
264
fprintf(stderr, "Failed to get key `%s': %s\n",
265
*keyp, err->message);
271
check (gconf_schema_get_type(schema) == gconf_schema_get_type(gotten),
272
"schema set/get pair: type `%s' set, `%s' got",
273
gconf_value_type_to_string(gconf_schema_get_type(schema)),
274
gconf_value_type_to_string(gconf_schema_get_type(gotten)));
277
/* If we set the schema for the current locale be sure we get it back */
278
if (null_safe_strcmp(gconf_current_locale(), gconf_schema_get_locale(schema)) == 0)
280
check (null_safe_strcmp(gconf_current_locale(), gconf_schema_get_locale(gotten)) == 0,
281
"schema set/get pair: locale `%s' set, `%s' got",
282
gconf_current_locale(),
283
NULL_SAFE(gconf_schema_get_locale(gotten)));
286
check (null_safe_strcmp(gconf_schema_get_short_desc(schema), gconf_schema_get_short_desc(gotten)) == 0,
287
"schema set/get pair: short_desc `%s' set, `%s' got",
288
NULL_SAFE(gconf_schema_get_short_desc(schema)),
289
NULL_SAFE(gconf_schema_get_short_desc(gotten)));
291
check (null_safe_strcmp(gconf_schema_get_long_desc(schema), gconf_schema_get_long_desc(gotten)) == 0,
292
"schema set/get pair: long_desc `%s' set, `%s' got",
293
NULL_SAFE(gconf_schema_get_long_desc(schema)),
294
NULL_SAFE(gconf_schema_get_long_desc(gotten)));
296
check (null_safe_strcmp(gconf_schema_get_owner(schema), gconf_schema_get_owner(gotten)) == 0,
297
"schema set/get pair: owner `%s' set, `%s' got",
298
NULL_SAFE(gconf_schema_get_owner(schema)),
299
NULL_SAFE(gconf_schema_get_owner(gotten)));
302
GConfValue* set_default;
303
GConfValue* got_default;
305
set_default = gconf_schema_get_default_value(schema);
306
got_default = gconf_schema_get_default_value(gotten);
308
if (set_default && got_default)
310
check(set_default->type == GCONF_VALUE_INT,
311
"set default type is INT");
313
check(set_default->type == got_default->type,
314
"schema set/get pair: default value type `%s' set, `%s' got",
315
gconf_value_type_to_string(set_default->type),
316
gconf_value_type_to_string(got_default->type));
318
check(set_default->type == got_default->type,
319
"schema set/get pair: default value type `%s' set, `%s' got",
320
gconf_value_type_to_string(set_default->type),
321
gconf_value_type_to_string(got_default->type));
323
check(gconf_value_get_int(set_default) == gconf_value_get_int(got_default),
324
"schema set/get pair: default value (int) `%d' set, `%d' got",
325
gconf_value_get_int(set_default), gconf_value_get_int(got_default));
330
check (set_default == NULL && got_default == NULL,
331
"set and got default value aren't both NULL (`%s' and `%s')",
332
set_default ? gconf_value_to_string(set_default) : "NULL",
333
got_default ? gconf_value_to_string(got_default) : "NULL");
337
gconf_schema_free(gotten);
343
check_schema_storage(GConfEngine* conf)
345
const gchar** keyp = NULL;
347
const gchar** localep = NULL;
349
/* Loop over keys, storing all values at each then retrieving them */
362
GConfValue* default_value;
363
const int default_value_int = 97992;
365
if (*localep == NULL)
368
schema = gconf_schema_new();
370
gconf_schema_set_type(schema, GCONF_VALUE_INT);
371
gconf_schema_set_locale(schema, *localep);
372
short_desc = g_strdup_printf("Schema for key `%s' storing value %d",
374
gconf_schema_set_short_desc(schema, short_desc);
376
long_desc = g_strdup_printf("Long description for schema with short description `%s' is really really long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long "
377
"UTF-8: German (Deutsch Süd) Grüß Gott Greek (Ελληνικά) Γειά σας Hebrew(שלום) Hebrew punctuation(\xd6\xbfש\xd6\xbb\xd6\xbc\xd6\xbb\xd6\xbfל\xd6\xbcו\xd6\xbc\xd6\xbb\xd6\xbb\xd6\xbfם\xd6\xbc\xd6\xbb\xd6\xbf) Japanese (日本語) Thai (สวัสดีครับ) Thai wrong spelling (คำต่อไปนื่สะกดผิด พัั้ัั่งโกะ)\n", short_desc);
379
gconf_schema_set_long_desc(schema, long_desc);
381
gconf_schema_set_owner(schema, "testschemas");
383
default_value = gconf_value_new(GCONF_VALUE_INT);
384
gconf_value_set_int(default_value, default_value_int);
386
gconf_schema_set_default_value_nocopy(schema, default_value);
388
check(gconf_value_get_int(gconf_schema_get_default_value(schema)) == default_value_int,
389
"Properly stored default int value in the schema");
391
check_one_schema(conf, keyp, schema);
393
gconf_schema_free(schema);
404
/* Check setting/getting "empty" schemas */
415
schema = gconf_schema_new();
417
/* this isn't guaranteed to be the same on get/set */
418
gconf_schema_set_locale(schema, "C");
420
gconf_schema_set_type(schema, GCONF_VALUE_INT);
422
check_one_schema(conf, keyp, schema);
424
gconf_schema_free(schema);
436
check_schema_use(GConfEngine * conf)
439
const gchar **keyp = NULL;
440
GConfSchema *schema = gconf_schema_new();
441
GConfValue *value = gconf_value_new(GCONF_VALUE_STRING);
442
char *schema_key = "/schemas/desktop/test-schema";
444
char *schema_value = "string value from schema";
445
char *non_schema_value = "a string value *not* from schema";
447
gconf_schema_set_type(schema, GCONF_VALUE_STRING);
448
gconf_schema_set_locale(schema, "C");
449
gconf_schema_set_short_desc(schema, "short desc");
450
gconf_schema_set_long_desc(schema, "long desc");
451
gconf_schema_set_owner(schema, "testschemas");
452
gconf_value_set_string(value, schema_value);
453
gconf_schema_set_default_value(schema, value);
455
if (gconf_engine_set_schema(conf, schema_key, schema, &err))
459
fprintf(stderr, "gconf_engine_set_schema -> %s\n", err->message);
468
if (gconf_engine_associate_schema(conf, *keyp, schema_key, &err))
472
fprintf(stderr, "gconf_engine_associate_schema -> %s\n", err->message);
482
/* FIXME we need to actually exit with error if these checks fail */
487
gconf_engine_unset(conf, *keyp, &err);
488
s = gconf_engine_get_string(conf, *keyp, &err);
491
if (strcmp(s, schema_value) != 0)
493
fprintf(stderr, "ERROR: Failed to get schema value (got '%s', not '%s')\n", s, schema_value);
502
fprintf(stderr, "ERROR: Failed to get a value when expecting schema value\n");
505
/* associate_schema should accept NULL to unset schemas */
506
gconf_engine_associate_schema(conf, *keyp, "/bogus-nonschema", &err);
507
s = gconf_engine_get_string(conf, *keyp, &err);
510
fprintf(stderr, "Failed to disassociate schema, found '%s'\n", s);
513
gconf_engine_set_string(conf, *keyp, non_schema_value, &err);
514
s = gconf_engine_get_string(conf, *keyp, &err);
517
if (strcmp(s, non_schema_value) != 0)
519
fprintf(stderr, "ERROR: Failed to get non-schema value (got '%s', not '%s')\n", s, non_schema_value);
528
fprintf(stderr, "ERROR: Failed to get a value when expecting non-schema value\n");
537
main (int argc, char** argv)
542
if (!gconf_init(argc, argv, &err))
544
fprintf(stderr, "Failed to init GConf: %s\n", err->message);
550
conf = gconf_engine_get_default();
552
check(conf != NULL, "create the default conf engine");
554
printf("\nChecking integer storage:");
556
check_int_storage(conf);
558
printf("\nChecking schema storage:");
560
check_schema_storage(conf);
562
printf("\nChecking schema use:");
564
check_schema_use(conf);
566
gconf_engine_unref(conf);