~ubuntu-branches/ubuntu/oneiric/gconf/oneiric-proposed

« back to all changes in this revision

Viewing changes to tests/testpersistence.c

  • Committer: Bazaar Package Importer
  • Author(s): Takuo KITAME
  • Date: 2002-03-17 01:51:39 UTC
  • Revision ID: james.westby@ubuntu.com-20020317015139-z4f8fdg1hoe049g0
Tags: upstream-1.0.9
ImportĀ upstreamĀ versionĀ 1.0.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* GConf
 
2
 * Copyright (C) 1999, 2000 Red Hat Inc.
 
3
 *
 
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.
 
8
 *
 
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.
 
13
 *
 
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.
 
18
 */
 
19
 
 
20
#include <gconf/gconf.h>
 
21
#include <stdio.h>
 
22
#include <unistd.h>
 
23
#include <math.h>
 
24
#include <gconf/gconf-internals.h>
 
25
 
 
26
const char *null_safe(const char *s)
 
27
{
 
28
        return s ? s : "<null>";
 
29
}
 
30
 
 
31
static void
 
32
sync_and_clear(GConfEngine* conf)
 
33
{
 
34
  gconf_synchronous_sync(conf, NULL);
 
35
  gconf_clear_cache(conf, NULL);
 
36
}
 
37
 
 
38
static void
 
39
check(gboolean condition, const gchar* fmt, ...)
 
40
{
 
41
  va_list args;
 
42
  gchar* description;
 
43
  
 
44
  va_start (args, fmt);
 
45
  description = g_strdup_vprintf(fmt, args);
 
46
  va_end (args);
 
47
  
 
48
  if (condition)
 
49
    {
 
50
      printf(".");
 
51
      fflush(stdout);
 
52
    }
 
53
  else
 
54
    {
 
55
      fprintf(stderr, "\n*** FAILED: %s\n", description);
 
56
      exit(1);
 
57
    }
 
58
  
 
59
  g_free(description);
 
60
}
 
61
 
 
62
static const gchar*
 
63
keys[] = {
 
64
  "/testing/foo/tar",
 
65
  "/testing/foo/bar",
 
66
  "/testing/quad",
 
67
  "/testing/blah",
 
68
  "/testing/q/a/b/c/z/w/x/y/z",
 
69
  "/testing/foo/baz",
 
70
  "/testing/oops/bloo",
 
71
  "/testing/oops/snoo",
 
72
  "/testing/oops/kwoo",
 
73
  "/testing/foo/quaz",
 
74
  NULL
 
75
};
 
76
 
 
77
static const gchar*
 
78
some_strings[] = {
 
79
  "",
 
80
  "dkadfhg;ifb;klndfl;kghpaodigjhrekjt45u62%&@#&@#kl6$%76k@$%&L jk245L:Yj45&@$&KL #$^UY $5",
 
81
  "sdkjfkljg",
 
82
  "a",
 
83
  "&",
 
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
  "#$&&^(%^^#$&&*(%^&#!$%$%&^&(%&>>>>>>>>>>>>>!>>>.....<<<<<<<<<<<<<<,,,,,,,&&&&&&",
 
86
  "sjdflkjg;kljklj",
 
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>"
 
93
          "</gmr:Style>"
 
94
          "<gmr:Geometry Width=\"610\" Height=\"418\"/>"
 
95
          "<gmr:Sheets>"
 
96
            "<gmr:Sheet>"
 
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>"
 
101
              "<gmr:Cols>"
 
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\"/>"
 
107
              "</gmr:Cols>"
 
108
              "<gmr:Rows>"
 
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\"/>"
 
124
              "</gmr:Rows>"
 
125
              "<gmr:Objects>"
 
126
                "<gmr:Ellipse Pattern=\"0\" Width=\"1\" Color=\"black\">"
 
127
                  "<gmr:Points>(258.000000 320.000000)(356.000000 356.000000)</gmr:Points>"
 
128
                "</gmr:Ellipse>"
 
129
                "<gmr:Arrow Width=\"1\" Color=\"black\">"
 
130
                  "<gmr:Points>(500.000000 131.000000)(332.000000 320.000000)</gmr:Points>"
 
131
                "</gmr:Arrow>"
 
132
              "</gmr:Objects>"
 
133
              "<gmr:Cells>"
 
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>"
 
137
                  "</gmr:Style>"
 
138
          "<gmr:Content>500</gmr:Content>",
 
139
 
 
140
  NULL
 
141
};
 
142
 
 
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]);
 
145
 
 
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 };
 
148
 
 
149
static const guint n_bools = sizeof(bools)/sizeof(bools[0]);
 
150
 
 
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 */
 
152
 
 
153
static const guint n_floats = sizeof(floats)/sizeof(floats[0]);
 
154
 
 
155
static void
 
156
check_unset(GConfEngine* conf)
 
157
{
 
158
  GError* err = NULL;
 
159
  const gchar** keyp = NULL;
 
160
 
 
161
  keyp = keys;
 
162
 
 
163
  while (*keyp)
 
164
    {
 
165
      gconf_engine_unset(conf, *keyp, &err);
 
166
 
 
167
      if (err != NULL)
 
168
        {
 
169
          fprintf(stderr, "unset of `%s' failed: %s\n", *keyp, err->message);
 
170
          g_error_free(err);
 
171
          err = NULL;
 
172
        }
 
173
      else
 
174
        {
 
175
          GConfValue* val;
 
176
          gchar* valstr;
 
177
 
 
178
          sync_and_clear(conf);
 
179
          
 
180
          val = gconf_engine_get (conf, *keyp, &err);
 
181
 
 
182
 
 
183
          if (val)
 
184
            valstr = gconf_value_to_string(val);
 
185
          else
 
186
            valstr = g_strdup("(none)");
 
187
          
 
188
          check(val == NULL, "unsetting a previously-set value `%s' the value `%s' existed", *keyp, valstr);
 
189
 
 
190
          g_free(valstr);
 
191
        }
 
192
      
 
193
      ++keyp;
 
194
    }
 
195
}
 
196
 
 
197
static void
 
198
check_string_storage(GConfEngine* conf)
 
199
{
 
200
  GError* err = NULL;
 
201
  const gchar** keyp = NULL;
 
202
  const gchar** valp = NULL;
 
203
 
 
204
  /* Loop over keys, storing all strings at each key then immediately
 
205
     retrieving them */
 
206
  
 
207
  keyp = keys;
 
208
 
 
209
  while (*keyp)
 
210
    {
 
211
      valp = some_strings;
 
212
      while (*valp)
 
213
        {
 
214
          gchar* gotten;
 
215
          
 
216
          if (!gconf_engine_set_string(conf, *keyp, *valp, &err))
 
217
            {
 
218
              fprintf(stderr, "Failed to set key `%s' to `%s': %s\n",
 
219
                      *keyp, *valp, err->message);
 
220
              g_error_free(err);
 
221
              err = NULL;
 
222
            }
 
223
          else
 
224
            {
 
225
              sync_and_clear(conf);
 
226
              
 
227
              gotten = gconf_engine_get_string(conf, *keyp, &err);
 
228
              
 
229
              if (err != NULL)
 
230
                {
 
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);
 
234
                  g_error_free(err);
 
235
                  err = NULL;
 
236
                }
 
237
              else
 
238
                {
 
239
                  check (strcmp(gotten, *valp) == 0, "string set/get pair: `%s' set, `%s' got",
 
240
                         *valp, gotten);
 
241
              
 
242
                  g_free(gotten);
 
243
                }
 
244
            }
 
245
          
 
246
          ++valp;
 
247
        }
 
248
 
 
249
      ++keyp;
 
250
    }
 
251
 
 
252
  /* Now invert the loop and see if that causes problems */
 
253
  
 
254
  valp = some_strings;
 
255
  
 
256
  while (*valp)
 
257
    {
 
258
      keyp = keys;
 
259
      while (*keyp)
 
260
        {
 
261
          gchar* gotten;
 
262
          
 
263
          if (!gconf_engine_set_string(conf, *keyp, *valp, &err))
 
264
            {
 
265
              fprintf(stderr, "Failed to set key `%s' to `%s': %s\n",
 
266
                      *keyp, *valp, err->message);
 
267
              g_error_free(err);
 
268
              err = NULL;
 
269
            }
 
270
 
 
271
          sync_and_clear(conf);
 
272
          
 
273
          gotten = gconf_engine_get_string(conf, *keyp, &err);
 
274
 
 
275
          if (err != NULL)
 
276
            {
 
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);
 
280
              g_error_free(err);
 
281
              err = NULL;
 
282
            }
 
283
          else if (gotten)
 
284
            {
 
285
              check (strcmp(gotten, *valp) == 0, "string set/get pair: `%s' set, `%s' got",
 
286
                     *valp, null_safe(gotten));
 
287
              
 
288
              g_free(gotten);
 
289
            }
 
290
              
 
291
          ++keyp;
 
292
        }
 
293
 
 
294
      ++valp;
 
295
    }
 
296
 
 
297
 
 
298
  check_unset(conf);
 
299
}
 
300
 
 
301
void
 
302
check_bool_storage(GConfEngine* conf)
 
303
{
 
304
  GError* err = NULL;
 
305
  const gchar** keyp = NULL;
 
306
  guint i; 
 
307
  
 
308
  /* Loop over keys, storing all bools at each then retrieving them */
 
309
  
 
310
  keyp = keys;
 
311
 
 
312
  while (*keyp)
 
313
    {
 
314
      i = 0;
 
315
      while (i < n_bools)
 
316
        {
 
317
          gboolean gotten;
 
318
          
 
319
          if (!gconf_engine_set_bool(conf, *keyp, bools[i], &err))
 
320
            {
 
321
              fprintf(stderr, "Failed to set key `%s' to `%d': %s\n",
 
322
                      *keyp, bools[i], err->message);
 
323
              g_error_free(err);
 
324
              err = NULL;
 
325
            }
 
326
          else
 
327
            {
 
328
              sync_and_clear(conf);
 
329
              
 
330
              gotten = gconf_engine_get_bool(conf, *keyp, &err);
 
331
 
 
332
              if (err != NULL)
 
333
                {
 
334
                  check(gotten == FALSE, "TRUE was returned though there was an error");
 
335
 
 
336
                  fprintf(stderr, "Failed to get key `%s': %s\n",
 
337
                          *keyp, err->message);
 
338
                  g_error_free(err);
 
339
                  err = NULL;
 
340
                }
 
341
              else
 
342
                {
 
343
                  check (bools[i] == gotten, "bool set/get pair: `%d' set, `%d' got",
 
344
                         bools[i], gotten);
 
345
 
 
346
                }
 
347
            }
 
348
          
 
349
          ++i;
 
350
        }
 
351
      
 
352
      ++keyp;
 
353
    }
 
354
 
 
355
  /* Now invert the loop and see if that causes problems */
 
356
 
 
357
  i = 0;
 
358
      
 
359
  while (i < n_bools)
 
360
    {
 
361
      keyp = keys;
 
362
      
 
363
      while (*keyp)
 
364
        {
 
365
          gboolean gotten;
 
366
          
 
367
          if (!gconf_engine_set_bool(conf, *keyp, bools[i], &err))
 
368
            {
 
369
              fprintf(stderr, "Failed to set key `%s' to `%d': %s\n",
 
370
                      *keyp, bools[i], err->message);
 
371
              g_error_free(err);
 
372
              err = NULL;
 
373
            }
 
374
          else
 
375
            {
 
376
              sync_and_clear(conf);
 
377
              
 
378
              gotten = gconf_engine_get_bool(conf, *keyp, &err);
 
379
              
 
380
              if (err != NULL)
 
381
                {
 
382
                  check(gotten == FALSE, "TRUE was returned though there was an error");
 
383
 
 
384
                  fprintf(stderr, "Failed to get key `%s': %s\n",
 
385
                          *keyp, err->message);
 
386
                  g_error_free(err);
 
387
                  err = NULL;
 
388
                }
 
389
              else
 
390
                {
 
391
                  check (bools[i] == gotten, "bool set/get pair: `%d' set, `%d' got",
 
392
                         bools[i], gotten);
 
393
 
 
394
                }
 
395
            }
 
396
 
 
397
          ++keyp;
 
398
        }
 
399
 
 
400
      ++i;
 
401
    }
 
402
  
 
403
  check_unset(conf);
 
404
}
 
405
 
 
406
void
 
407
check_float_storage(GConfEngine* conf)
 
408
{
 
409
  GError* err = NULL;
 
410
  const gchar** keyp = NULL;
 
411
  guint i; 
 
412
  const gdouble tolerance = 1e-5;
 
413
  
 
414
  /* Loop over keys, storing all values at each then retrieving them */
 
415
  
 
416
  keyp = keys;
 
417
 
 
418
  while (*keyp)
 
419
    {
 
420
      i = 0;
 
421
      while (i < n_floats)
 
422
        {
 
423
          gdouble gotten;
 
424
          
 
425
          if (!gconf_engine_set_float(conf, *keyp, floats[i], &err))
 
426
            {
 
427
              fprintf(stderr, "Failed to set key `%s' to `%g': %s\n",
 
428
                      *keyp, floats[i], err->message);
 
429
              g_error_free(err);
 
430
              err = NULL;
 
431
            }
 
432
          else
 
433
            {
 
434
              sync_and_clear(conf);
 
435
              
 
436
              gotten = gconf_engine_get_float(conf, *keyp, &err);
 
437
 
 
438
              if (err != NULL)
 
439
                {
 
440
                  check(gotten == 0.0, "0.0 not returned though there was an error");
 
441
 
 
442
                  fprintf(stderr, "Failed to get key `%s': %s\n",
 
443
                          *keyp, err->message);
 
444
                  g_error_free(err);
 
445
                  err = NULL;
 
446
                }
 
447
              else
 
448
                {
 
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);
 
452
 
 
453
                }
 
454
            }
 
455
          
 
456
          ++i;
 
457
        }
 
458
      
 
459
      ++keyp;
 
460
    }
 
461
 
 
462
  /* Now invert the loop and see if that causes problems */
 
463
 
 
464
  i = 0;
 
465
  while (i < n_floats)
 
466
    {
 
467
 
 
468
      keyp = keys;
 
469
 
 
470
      while (*keyp)
 
471
        {
 
472
          gdouble gotten;
 
473
          
 
474
          if (!gconf_engine_set_float(conf, *keyp, floats[i], &err))
 
475
            {
 
476
              fprintf(stderr, "Failed to set key `%s' to `%g': %s\n",
 
477
                      *keyp, floats[i], err->message);
 
478
              g_error_free(err);
 
479
              err = NULL;
 
480
            }
 
481
          else
 
482
            {
 
483
              sync_and_clear(conf);
 
484
              
 
485
              gotten = gconf_engine_get_float(conf, *keyp, &err);
 
486
 
 
487
              if (err != NULL)
 
488
                {
 
489
                  check(gotten == 0.0, "0.0 not returned though there was an error");
 
490
 
 
491
                  fprintf(stderr, "Failed to get key `%s': %s\n",
 
492
                          *keyp, err->message);
 
493
                  g_error_free(err);
 
494
                  err = NULL;
 
495
                }
 
496
              else
 
497
                {
 
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);
 
501
 
 
502
                }
 
503
            }
 
504
          
 
505
      
 
506
          ++keyp;
 
507
        }
 
508
 
 
509
      ++i;
 
510
    }
 
511
          
 
512
  check_unset(conf);
 
513
}
 
514
 
 
515
void
 
516
check_int_storage(GConfEngine* conf)
 
517
{
 
518
  GError* err = NULL;
 
519
  const gchar** keyp = NULL;
 
520
  guint i; 
 
521
  
 
522
  /* Loop over keys, storing all values at each then retrieving them */
 
523
  
 
524
  keyp = keys;
 
525
 
 
526
  while (*keyp)
 
527
    {
 
528
      i = 0;
 
529
      while (i < n_ints)
 
530
        {
 
531
          gint gotten;
 
532
          
 
533
          if (!gconf_engine_set_int(conf, *keyp, ints[i], &err))
 
534
            {
 
535
              fprintf(stderr, "Failed to set key `%s' to `%d': %s\n",
 
536
                      *keyp, ints[i], err->message);
 
537
              g_error_free(err);
 
538
              err = NULL;
 
539
            }
 
540
          else
 
541
            {
 
542
              sync_and_clear(conf);
 
543
              
 
544
              gotten = gconf_engine_get_int(conf, *keyp, &err);
 
545
 
 
546
              if (err != NULL)
 
547
                {
 
548
                  check(gotten == 0.0, "0.0 not returned though there was an error");
 
549
 
 
550
                  fprintf(stderr, "Failed to get key `%s': %s\n",
 
551
                          *keyp, err->message);
 
552
                  g_error_free(err);
 
553
                  err = NULL;
 
554
                }
 
555
              else
 
556
                {
 
557
                  check (ints[i] == gotten,
 
558
                         "int set/get pair: `%d' set, `%d' got",
 
559
                         ints[i], gotten);
 
560
 
 
561
                }
 
562
            }
 
563
          
 
564
          ++i;
 
565
        }
 
566
      
 
567
      ++keyp;
 
568
    }
 
569
 
 
570
  /* Now invert the loop and see if that causes problems */
 
571
 
 
572
  i = 0;
 
573
  while (i < n_ints)
 
574
    {
 
575
 
 
576
      keyp = keys;
 
577
 
 
578
      while (*keyp)
 
579
        {
 
580
          gint gotten;
 
581
          
 
582
          if (!gconf_engine_set_int(conf, *keyp, ints[i], &err))
 
583
            {
 
584
              fprintf(stderr, "Failed to set key `%s' to `%d': %s\n",
 
585
                      *keyp, ints[i], err->message);
 
586
              g_error_free(err);
 
587
              err = NULL;
 
588
            }
 
589
          else
 
590
            {
 
591
              sync_and_clear(conf);
 
592
              
 
593
              gotten = gconf_engine_get_int(conf, *keyp, &err);
 
594
 
 
595
              if (err != NULL)
 
596
                {
 
597
                  check(gotten == 0, "0 not returned though there was an error");
 
598
 
 
599
                  fprintf(stderr, "Failed to get key `%s': %s\n",
 
600
                          *keyp, err->message);
 
601
                  g_error_free(err);
 
602
                  err = NULL;
 
603
                }
 
604
              else
 
605
                {
 
606
                  check (ints[i] == gotten,
 
607
                         "int set/get pair: `%d' set, `%d' got",
 
608
                         ints[i], gotten);
 
609
 
 
610
                }
 
611
            }
 
612
          
 
613
      
 
614
          ++keyp;
 
615
        }
 
616
 
 
617
      ++i;
 
618
    }
 
619
          
 
620
  check_unset(conf);
 
621
}
 
622
 
 
623
static void
 
624
compare_lists(GConfValueType type, GSList* first, GSList* second)
 
625
{
 
626
  GSList* l1;
 
627
  GSList* l2;
 
628
 
 
629
  l1 = first;
 
630
  l2 = second;
 
631
  
 
632
  while (l1 != NULL)
 
633
    {      
 
634
      check(l2 != NULL, "second list too short");
 
635
      
 
636
      switch (type)
 
637
        {
 
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));
 
642
          break;
 
643
          
 
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));
 
648
          break;
 
649
          
 
650
        case GCONF_VALUE_FLOAT:
 
651
          {
 
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)",
 
656
                  d1, d2, d2 - d1);
 
657
          }
 
658
          break;
 
659
          
 
660
        case GCONF_VALUE_STRING:
 
661
          check(strcmp(l1->data, l2->data) == 0, 
 
662
                "string values `%s' and `%s' are not equal",
 
663
                l1->data, l2->data);
 
664
          break;
 
665
          
 
666
        default:
 
667
          g_assert_not_reached();
 
668
          break;
 
669
        }
 
670
      
 
671
      l1 = g_slist_next(l1);
 
672
      l2 = g_slist_next(l2);
 
673
    }
 
674
 
 
675
  check(l2 == NULL, "second list too long with list type %s",
 
676
        gconf_value_type_to_string(type));
 
677
}
 
678
 
 
679
static void
 
680
free_list(GConfValueType type, GSList* list)
 
681
{
 
682
  GSList* tmp = list;
 
683
 
 
684
  while (tmp != NULL)
 
685
    {
 
686
      switch (type)
 
687
        {
 
688
        case GCONF_VALUE_INT:
 
689
        case GCONF_VALUE_BOOL:
 
690
          break;
 
691
 
 
692
        case GCONF_VALUE_FLOAT:
 
693
        case GCONF_VALUE_STRING:
 
694
          g_free(tmp->data);
 
695
          break;
 
696
          
 
697
        default:
 
698
          g_assert_not_reached();
 
699
          break;
 
700
        }
 
701
 
 
702
      tmp = g_slist_next(tmp);
 
703
    }
 
704
 
 
705
  g_slist_free(list);
 
706
}
 
707
 
 
708
static GSList*
 
709
list_of_ints(void)
 
710
{
 
711
  GSList* retval = NULL;
 
712
  guint i = 0;
 
713
  while (i < n_ints)
 
714
    {      
 
715
      retval = g_slist_prepend(retval, GINT_TO_POINTER(ints[i]));
 
716
      
 
717
      ++i;
 
718
    }
 
719
  return retval;
 
720
}
 
721
 
 
722
static GSList*
 
723
list_of_strings(void)
 
724
{
 
725
  GSList* retval = NULL;
 
726
  const gchar** stringp = some_strings;
 
727
  while (*stringp)
 
728
    {     
 
729
      retval = g_slist_prepend(retval, g_strdup(*stringp));
 
730
      
 
731
      ++stringp;
 
732
    }
 
733
  return retval;
 
734
}
 
735
 
 
736
static GSList*
 
737
list_of_bools(void)
 
738
{
 
739
  GSList* retval = NULL;
 
740
  guint i = 0;
 
741
  while (i < n_bools)
 
742
    {      
 
743
      retval = g_slist_prepend(retval, GINT_TO_POINTER(bools[i]));
 
744
      
 
745
      ++i;
 
746
    }
 
747
  return retval;
 
748
}
 
749
 
 
750
static GSList*
 
751
list_of_floats(void)
 
752
{
 
753
  GSList* retval = NULL;
 
754
  guint i = 0;
 
755
  while (i < n_floats)
 
756
    {      
 
757
      retval = g_slist_prepend(retval,
 
758
                               g_memdup(&floats[i], sizeof(floats[i])));
 
759
      
 
760
      ++i;
 
761
    }
 
762
  return retval;
 
763
}
 
764
 
 
765
 
 
766
static void
 
767
check_list_storage(GConfEngine* conf)
 
768
{
 
769
  GError* err = NULL;
 
770
  const gchar** keyp = NULL;
 
771
  guint i;
 
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]);
 
778
 
 
779
  /* List of integers */
 
780
  lists[0] = list_of_ints();
 
781
 
 
782
  /* empty list of integers */
 
783
  lists[1] = NULL;
 
784
 
 
785
  /* lists of string */
 
786
  lists[2] = list_of_strings();
 
787
  lists[3] = NULL;
 
788
 
 
789
  /* of float */
 
790
  lists[4] = list_of_floats();
 
791
  lists[5] = NULL;
 
792
 
 
793
  /* of bool */
 
794
  lists[6] = list_of_bools();
 
795
  lists[7] = NULL;
 
796
  
 
797
  /* Loop over keys, storing all values at each then retrieving them */
 
798
  
 
799
  keyp = keys;
 
800
 
 
801
  while (*keyp)
 
802
    {
 
803
      i = 0;
 
804
      
 
805
      while (i < n_lists)
 
806
        {
 
807
          GSList* gotten = NULL;
 
808
          
 
809
          if (!gconf_engine_set_list(conf, *keyp, list_types[i], lists[i], &err))
 
810
            {
 
811
              fprintf(stderr, "Failed to set key `%s' to list: %s\n",
 
812
                      *keyp, err->message);
 
813
              g_error_free(err);
 
814
              err = NULL;
 
815
            }
 
816
          else
 
817
            {
 
818
              sync_and_clear(conf);
 
819
              
 
820
              gotten = gconf_engine_get_list(conf, *keyp, list_types[i], &err);
 
821
 
 
822
              if (err != NULL)
 
823
                {
 
824
                  check(gotten == NULL, "NULL not returned though there was an error");
 
825
 
 
826
                  fprintf(stderr, "Failed to get key `%s': %s\n",
 
827
                          *keyp, err->message);
 
828
                  g_error_free(err);
 
829
                  err = NULL;
 
830
                }
 
831
              else
 
832
                {
 
833
                  compare_lists(list_types[i], lists[i], gotten);
 
834
                }
 
835
            }
 
836
 
 
837
          ++i;
 
838
        }
 
839
      
 
840
      ++keyp;
 
841
    }
 
842
 
 
843
  i = 0;
 
844
  while (i < n_lists)
 
845
    {
 
846
      free_list(list_types[i], lists[i]);
 
847
      ++i;
 
848
    }
 
849
 
 
850
  check_unset(conf);
 
851
}
 
852
 
 
853
int 
 
854
main (int argc, char** argv)
 
855
{
 
856
  GConfEngine* conf;
 
857
  GError* err = NULL;
 
858
  
 
859
  if (!gconf_init(argc, argv, &err))
 
860
    {
 
861
      g_assert(err != NULL);
 
862
      fprintf(stderr, "Failed to init GConf: %s\n", err->message);
 
863
      fflush(stderr);
 
864
      g_error_free(err);
 
865
      err = NULL;
 
866
      return 1;
 
867
    }
 
868
  
 
869
  conf = gconf_engine_get_default();
 
870
 
 
871
  check(conf != NULL, "create the default conf engine");
 
872
 
 
873
  printf("\nChecking list storage:");
 
874
  
 
875
  check_list_storage(conf);
 
876
  
 
877
  printf("\nChecking integer storage:");
 
878
  
 
879
  check_int_storage(conf);
 
880
 
 
881
  printf("\nChecking float storage:");
 
882
  
 
883
  check_float_storage(conf);
 
884
 
 
885
  printf("\nChecking string storage:");
 
886
  
 
887
  check_string_storage(conf);
 
888
 
 
889
  printf("\nChecking bool storage:");
 
890
  
 
891
  check_bool_storage(conf);
 
892
  
 
893
  gconf_engine_unref(conf);
 
894
 
 
895
  printf("\n\n");
 
896
  
 
897
  return 0;
 
898
}