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
const char *null_safe(const char *s)
28
return s ? s : "<null>";
32
sync_and_clear(GConfEngine* conf)
34
gconf_synchronous_sync(conf, NULL);
35
gconf_clear_cache(conf, NULL);
39
check(gboolean condition, const gchar* fmt, ...)
45
description = g_strdup_vprintf(fmt, args);
55
fprintf(stderr, "\n*** FAILED: %s\n", description);
68
"/testing/q/a/b/c/z/w/x/y/z",
80
"dkadfhg;ifb;klndfl;kghpaodigjhrekjt45u62%&@#&@#kl6$%76k@$%&L jk245L:Yj45&@$&KL #$^UY $5",
84
"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",
85
"#$&&^(%^^#$&&*(%^&#!$%$%&^&(%&>>>>>>>>>>>>>!>>>.....<<<<<<<<<<<<<<,,,,,,,&&&&&&",
87
"hello this is a string with spaces and \t\t\t\ttabs",
88
"hello this\nstring\nhas\nnewlines\n \t\t\t\t\t\ttabs and spaces \n",
89
"<?xml version=\"1.0\"?>"
90
"<gmr:Workbook xmlns:gmr=\"http://www.gnome.org/gnumeric/\">"
91
"<gmr:Style HAlign=\"1\" VAlign=\"1\" Fit=\"0\" Orient=\"1\" Shade=\"0\" Format=\"#,##0_);[red](#,##0)\">"
92
"<gmr:Font Unit=\"14\" NAME=\"FontDef1\">-adobe-helvetica-medium-r-normal--*-120-*-*-*-*-*-*</gmr:Font>"
94
"<gmr:Geometry Width=\"610\" Height=\"418\"/>"
97
"<gmr:Name>Sheet 0</gmr:Name>"
98
"<gmr:MaxCol>6</gmr:MaxCol>"
99
"<gmr:MaxRow>14</gmr:MaxRow>"
100
"<gmr:Zoom>1.000000</gmr:Zoom>"
102
"<gmr:ColInfo No=\"0\" Unit=\"97\" MarginA=\"1\" MarginB=\"1\" HardSize=\"0\"/>"
103
"<gmr:ColInfo No=\"1\" Unit=\"80\" MarginA=\"1\" MarginB=\"1\" HardSize=\"0\"/>"
104
"<gmr:ColInfo No=\"2\" Unit=\"80\" MarginA=\"1\" MarginB=\"1\" HardSize=\"0\"/>"
105
"<gmr:ColInfo No=\"3\" Unit=\"80\" MarginA=\"1\" MarginB=\"1\" HardSize=\"0\"/>"
106
"<gmr:ColInfo No=\"6\" Unit=\"80\" MarginA=\"1\" MarginB=\"1\" HardSize=\"0\"/>"
109
"<gmr:RowInfo No=\"0\" Unit=\"20\" MarginA=\"1\" MarginB=\"1\" HardSize=\"0\"/>"
110
"<gmr:RowInfo No=\"1\" Unit=\"20\" MarginA=\"1\" MarginB=\"1\" HardSize=\"0\"/>"
111
"<gmr:RowInfo No=\"2\" Unit=\"20\" MarginA=\"1\" MarginB=\"1\" HardSize=\"0\"/>"
112
"<gmr:RowInfo No=\"3\" Unit=\"20\" MarginA=\"1\" MarginB=\"1\" HardSize=\"0\"/>"
113
"<gmr:RowInfo No=\"4\" Unit=\"20\" MarginA=\"1\" MarginB=\"1\" HardSize=\"0\"/>"
114
"<gmr:RowInfo No=\"5\" Unit=\"20\" MarginA=\"1\" MarginB=\"1\" HardSize=\"0\"/>"
115
"<gmr:RowInfo No=\"6\" Unit=\"20\" MarginA=\"1\" MarginB=\"1\" HardSize=\"0\"/>"
116
"<gmr:RowInfo No=\"7\" Unit=\"20\" MarginA=\"1\" MarginB=\"1\" HardSize=\"0\"/>"
117
"<gmr:RowInfo No=\"8\" Unit=\"20\" MarginA=\"1\" MarginB=\"1\" HardSize=\"0\"/>"
118
"<gmr:RowInfo No=\"9\" Unit=\"20\" MarginA=\"1\" MarginB=\"1\" HardSize=\"0\"/>"
119
"<gmr:RowInfo No=\"10\" Unit=\"20\" MarginA=\"1\" MarginB=\"1\" HardSize=\"0\"/>"
120
"<gmr:RowInfo No=\"11\" Unit=\"20\" MarginA=\"1\" MarginB=\"1\" HardSize=\"0\"/>"
121
"<gmr:RowInfo No=\"12\" Unit=\"20\" MarginA=\"1\" MarginB=\"1\" HardSize=\"0\"/>"
122
"<gmr:RowInfo No=\"13\" Unit=\"20\" MarginA=\"1\" MarginB=\"1\" HardSize=\"0\"/>"
123
"<gmr:RowInfo No=\"14\" Unit=\"20\" MarginA=\"1\" MarginB=\"1\" HardSize=\"0\"/>"
126
"<gmr:Ellipse Pattern=\"0\" Width=\"1\" Color=\"black\">"
127
"<gmr:Points>(258.000000 320.000000)(356.000000 356.000000)</gmr:Points>"
129
"<gmr:Arrow Width=\"1\" Color=\"black\">"
130
"<gmr:Points>(500.000000 131.000000)(332.000000 320.000000)</gmr:Points>"
134
"<gmr:Cell Col=\"3\" Row=\"1\">"
135
"<gmr:Style HAlign=\"1\" VAlign=\"1\" Fit=\"0\" Orient=\"1\" Shade=\"0\" Format=\"#,##0_);[red](#,##0)\">"
136
"<gmr:Font Unit=\"14\" NAME=\"FontDef2\">-adobe-helvetica-medium-r-normal--*-120-*-*-*-*-*-*</gmr:Font>"
138
"<gmr:Content>500</gmr:Content>",
143
static gint ints[] = { -1, -2, -3, 0, 1, 2, 3, 4000, 0xfffff, -0xfffff, G_MININT, G_MAXINT, 0, 0, 57, 83, 95 };
144
static const guint n_ints = sizeof(ints)/sizeof(ints[0]);
146
static gboolean bools[] = { TRUE, TRUE, FALSE, FALSE, TRUE, FALSE, TRUE, FALSE, FALSE, FALSE,
147
FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, TRUE };
149
static const guint n_bools = sizeof(bools)/sizeof(bools[0]);
151
static gdouble floats[] = { 0.0, 1.0, 2.0, 3.0, 4.0, -10.0, -10.34645764573475637657367346743734878734109870187200000000000009, -100.39458694856908, 3.14159, 4.4532464e7, 9.35e-10, 4.5, 6.7, 8.3, -5.1, G_MINFLOAT, -G_MAXFLOAT, G_MAXFLOAT }; /* don't use max/min double, we don't guarantee that we can store huge numbers */
153
static const guint n_floats = sizeof(floats)/sizeof(floats[0]);
156
check_unset(GConfEngine* conf)
159
const gchar** keyp = NULL;
165
gconf_engine_unset(conf, *keyp, &err);
169
fprintf(stderr, "unset of `%s' failed: %s\n", *keyp, err->message);
178
sync_and_clear(conf);
180
val = gconf_engine_get (conf, *keyp, &err);
184
valstr = gconf_value_to_string(val);
186
valstr = g_strdup("(none)");
188
check(val == NULL, "unsetting a previously-set value `%s' the value `%s' existed", *keyp, valstr);
198
check_string_storage(GConfEngine* conf)
201
const gchar** keyp = NULL;
202
const gchar** valp = NULL;
204
/* Loop over keys, storing all strings at each key then immediately
216
if (!gconf_engine_set_string(conf, *keyp, *valp, &err))
218
fprintf(stderr, "Failed to set key `%s' to `%s': %s\n",
219
*keyp, *valp, err->message);
225
sync_and_clear(conf);
227
gotten = gconf_engine_get_string(conf, *keyp, &err);
231
check(gotten == NULL, "string was returned though there was an error");
232
fprintf(stderr, "Failed to get key `%s': %s\n",
233
*keyp, err->message);
239
check (strcmp(gotten, *valp) == 0, "string set/get pair: `%s' set, `%s' got",
252
/* Now invert the loop and see if that causes problems */
263
if (!gconf_engine_set_string(conf, *keyp, *valp, &err))
265
fprintf(stderr, "Failed to set key `%s' to `%s': %s\n",
266
*keyp, *valp, err->message);
271
sync_and_clear(conf);
273
gotten = gconf_engine_get_string(conf, *keyp, &err);
277
check(gotten == NULL, "string was returned though there was an error");
278
fprintf(stderr, "Failed to get key `%s': %s\n",
279
*keyp, err->message);
285
check (strcmp(gotten, *valp) == 0, "string set/get pair: `%s' set, `%s' got",
286
*valp, null_safe(gotten));
302
check_bool_storage(GConfEngine* conf)
305
const gchar** keyp = NULL;
308
/* Loop over keys, storing all bools at each then retrieving them */
319
if (!gconf_engine_set_bool(conf, *keyp, bools[i], &err))
321
fprintf(stderr, "Failed to set key `%s' to `%d': %s\n",
322
*keyp, bools[i], err->message);
328
sync_and_clear(conf);
330
gotten = gconf_engine_get_bool(conf, *keyp, &err);
334
check(gotten == FALSE, "TRUE was returned though there was an error");
336
fprintf(stderr, "Failed to get key `%s': %s\n",
337
*keyp, err->message);
343
check (bools[i] == gotten, "bool set/get pair: `%d' set, `%d' got",
355
/* Now invert the loop and see if that causes problems */
367
if (!gconf_engine_set_bool(conf, *keyp, bools[i], &err))
369
fprintf(stderr, "Failed to set key `%s' to `%d': %s\n",
370
*keyp, bools[i], err->message);
376
sync_and_clear(conf);
378
gotten = gconf_engine_get_bool(conf, *keyp, &err);
382
check(gotten == FALSE, "TRUE was returned though there was an error");
384
fprintf(stderr, "Failed to get key `%s': %s\n",
385
*keyp, err->message);
391
check (bools[i] == gotten, "bool set/get pair: `%d' set, `%d' got",
407
check_float_storage(GConfEngine* conf)
410
const gchar** keyp = NULL;
412
const gdouble tolerance = 1e-5;
414
/* Loop over keys, storing all values at each then retrieving them */
425
if (!gconf_engine_set_float(conf, *keyp, floats[i], &err))
427
fprintf(stderr, "Failed to set key `%s' to `%g': %s\n",
428
*keyp, floats[i], err->message);
434
sync_and_clear(conf);
436
gotten = gconf_engine_get_float(conf, *keyp, &err);
440
check(gotten == 0.0, "0.0 not returned though there was an error");
442
fprintf(stderr, "Failed to get key `%s': %s\n",
443
*keyp, err->message);
449
check (fabs(floats[i] - gotten) < tolerance,
450
"float set/get pair: `%g' set, `%g' got, `%g' epsilon",
451
floats[i], gotten, floats[i] - gotten);
462
/* Now invert the loop and see if that causes problems */
474
if (!gconf_engine_set_float(conf, *keyp, floats[i], &err))
476
fprintf(stderr, "Failed to set key `%s' to `%g': %s\n",
477
*keyp, floats[i], err->message);
483
sync_and_clear(conf);
485
gotten = gconf_engine_get_float(conf, *keyp, &err);
489
check(gotten == 0.0, "0.0 not returned though there was an error");
491
fprintf(stderr, "Failed to get key `%s': %s\n",
492
*keyp, err->message);
498
check (fabs(floats[i] - gotten) < tolerance,
499
"float set/get pair: `%g' set, `%g' got, `%g' epsilon",
500
floats[i], gotten, floats[i] - gotten);
516
check_int_storage(GConfEngine* conf)
519
const gchar** keyp = NULL;
522
/* Loop over keys, storing all values at each then retrieving them */
533
if (!gconf_engine_set_int(conf, *keyp, ints[i], &err))
535
fprintf(stderr, "Failed to set key `%s' to `%d': %s\n",
536
*keyp, ints[i], err->message);
542
sync_and_clear(conf);
544
gotten = gconf_engine_get_int(conf, *keyp, &err);
548
check(gotten == 0.0, "0.0 not returned though there was an error");
550
fprintf(stderr, "Failed to get key `%s': %s\n",
551
*keyp, err->message);
557
check (ints[i] == gotten,
558
"int set/get pair: `%d' set, `%d' got",
570
/* Now invert the loop and see if that causes problems */
582
if (!gconf_engine_set_int(conf, *keyp, ints[i], &err))
584
fprintf(stderr, "Failed to set key `%s' to `%d': %s\n",
585
*keyp, ints[i], err->message);
591
sync_and_clear(conf);
593
gotten = gconf_engine_get_int(conf, *keyp, &err);
597
check(gotten == 0, "0 not returned though there was an error");
599
fprintf(stderr, "Failed to get key `%s': %s\n",
600
*keyp, err->message);
606
check (ints[i] == gotten,
607
"int set/get pair: `%d' set, `%d' got",
624
compare_lists(GConfValueType type, GSList* first, GSList* second)
634
check(l2 != NULL, "second list too short");
638
case GCONF_VALUE_INT:
639
check(GPOINTER_TO_INT(l1->data) == GPOINTER_TO_INT(l2->data),
640
"integer values %d and %d are not equal",
641
GPOINTER_TO_INT(l1->data), GPOINTER_TO_INT(l2->data));
644
case GCONF_VALUE_BOOL:
645
check(GPOINTER_TO_INT(l1->data) == GPOINTER_TO_INT(l2->data),
646
"boolean values %d and %d are not equal",
647
GPOINTER_TO_INT(l1->data), GPOINTER_TO_INT(l2->data));
650
case GCONF_VALUE_FLOAT:
652
gdouble d1 = *((gdouble*)l1->data);
653
gdouble d2 = *((gdouble*)l2->data);
654
check(fabs(d2 - d1) < 1e-5,
655
"float values %g and %g are not equal (epsilon %g)",
660
case GCONF_VALUE_STRING:
661
check(strcmp(l1->data, l2->data) == 0,
662
"string values `%s' and `%s' are not equal",
667
g_assert_not_reached();
671
l1 = g_slist_next(l1);
672
l2 = g_slist_next(l2);
675
check(l2 == NULL, "second list too long with list type %s",
676
gconf_value_type_to_string(type));
680
free_list(GConfValueType type, GSList* list)
688
case GCONF_VALUE_INT:
689
case GCONF_VALUE_BOOL:
692
case GCONF_VALUE_FLOAT:
693
case GCONF_VALUE_STRING:
698
g_assert_not_reached();
702
tmp = g_slist_next(tmp);
711
GSList* retval = NULL;
715
retval = g_slist_prepend(retval, GINT_TO_POINTER(ints[i]));
723
list_of_strings(void)
725
GSList* retval = NULL;
726
const gchar** stringp = some_strings;
729
retval = g_slist_prepend(retval, g_strdup(*stringp));
739
GSList* retval = NULL;
743
retval = g_slist_prepend(retval, GINT_TO_POINTER(bools[i]));
753
GSList* retval = NULL;
757
retval = g_slist_prepend(retval,
758
g_memdup(&floats[i], sizeof(floats[i])));
767
check_list_storage(GConfEngine* conf)
770
const gchar** keyp = NULL;
772
GConfValueType list_types[] = { GCONF_VALUE_INT, GCONF_VALUE_INT,
773
GCONF_VALUE_STRING, GCONF_VALUE_STRING,
774
GCONF_VALUE_FLOAT, GCONF_VALUE_FLOAT,
775
GCONF_VALUE_BOOL, GCONF_VALUE_BOOL };
776
GSList* lists[] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL };
777
const guint n_lists = sizeof(lists)/sizeof(lists[0]);
779
/* List of integers */
780
lists[0] = list_of_ints();
782
/* empty list of integers */
785
/* lists of string */
786
lists[2] = list_of_strings();
790
lists[4] = list_of_floats();
794
lists[6] = list_of_bools();
797
/* Loop over keys, storing all values at each then retrieving them */
807
GSList* gotten = NULL;
809
if (!gconf_engine_set_list(conf, *keyp, list_types[i], lists[i], &err))
811
fprintf(stderr, "Failed to set key `%s' to list: %s\n",
812
*keyp, err->message);
818
sync_and_clear(conf);
820
gotten = gconf_engine_get_list(conf, *keyp, list_types[i], &err);
824
check(gotten == NULL, "NULL not returned though there was an error");
826
fprintf(stderr, "Failed to get key `%s': %s\n",
827
*keyp, err->message);
833
compare_lists(list_types[i], lists[i], gotten);
846
free_list(list_types[i], lists[i]);
854
main (int argc, char** argv)
859
if (!gconf_init(argc, argv, &err))
861
g_assert(err != NULL);
862
fprintf(stderr, "Failed to init GConf: %s\n", err->message);
869
conf = gconf_engine_get_default();
871
check(conf != NULL, "create the default conf engine");
873
printf("\nChecking list storage:");
875
check_list_storage(conf);
877
printf("\nChecking integer storage:");
879
check_int_storage(conf);
881
printf("\nChecking float storage:");
883
check_float_storage(conf);
885
printf("\nChecking string storage:");
887
check_string_storage(conf);
889
printf("\nChecking bool storage:");
891
check_bool_storage(conf);
893
gconf_engine_unref(conf);