~ubuntu-branches/ubuntu/quantal/gconf/quantal

« back to all changes in this revision

Viewing changes to tests/testchangeset.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 <gconf/gconf-changeset.h>
 
22
#include <stdio.h>
 
23
#include <unistd.h>
 
24
#include <math.h>
 
25
 
 
26
static void
 
27
check(gboolean condition, const gchar* fmt, ...)
 
28
{
 
29
  va_list args;
 
30
  gchar* description;
 
31
  
 
32
  va_start (args, fmt);
 
33
  description = g_strdup_vprintf(fmt, args);
 
34
  va_end (args);
 
35
  
 
36
  if (condition)
 
37
    {
 
38
      printf(".");
 
39
      fflush(stdout);
 
40
    }
 
41
  else
 
42
    {
 
43
      fprintf(stderr, "\n*** FAILED: %s\n", description);
 
44
      exit(1);
 
45
    }
 
46
  
 
47
  g_free(description);
 
48
}
 
49
 
 
50
static const gchar*
 
51
keys[] = {
 
52
  "/testing/foo/tar",
 
53
  "/testing/foo/bar",
 
54
  "/testing/quad",
 
55
  "/testing/blah",
 
56
  "/testing/q/a/b/c/z/w/x/y/z",
 
57
  "/testing/foo/baz",
 
58
  "/testing/oops/bloo",
 
59
  "/testing/oops/snoo",
 
60
  "/testing/oops/kwoo",
 
61
  "/testing/foo/quaz",
 
62
  NULL
 
63
};
 
64
 
 
65
static const gchar*
 
66
some_strings[] = {
 
67
  "",
 
68
  "dkadfhg;ifb;klndfl;kghpaodigjhrekjt45u62%&@#&@#kl6$%76k@$%&L jk245L:Yj45&@$&KL #$^UY $5",
 
69
  "sdkjfkljg",
 
70
  "a",
 
71
  "&",
 
72
  "#$&&^(%^^#$&&*(%^&#!$%$%&^&(%&>>>>>>>>>>>>>!>>>.....<<<<<<<<<<<<<<,,,,,,,&&&&&&",
 
73
  "sjdflkjg;kljklj",
 
74
  "hello this is a string with spaces and \t\t\t\ttabs",
 
75
  "hello this\nstring\nhas\nnewlines\n   \t\t\t\t\t\ttabs and spaces  \n",
 
76
  "<?xml version=\"1.0\"?>"
 
77
        "<gmr:Workbook xmlns:gmr=\"http://www.gnome.org/gnumeric/\">"
 
78
          "<gmr:Style HAlign=\"1\" VAlign=\"1\" Fit=\"0\" Orient=\"1\" Shade=\"0\" Format=\"#,##0_);[red](#,##0)\">"
 
79
            "<gmr:Font Unit=\"14\" NAME=\"FontDef1\">-adobe-helvetica-medium-r-normal--*-120-*-*-*-*-*-*</gmr:Font>"
 
80
          "</gmr:Style>"
 
81
          "<gmr:Geometry Width=\"610\" Height=\"418\"/>"
 
82
          "<gmr:Sheets>"
 
83
            "<gmr:Sheet>"
 
84
              "<gmr:Name>Sheet 0</gmr:Name>"
 
85
              "<gmr:MaxCol>6</gmr:MaxCol>"
 
86
              "<gmr:MaxRow>14</gmr:MaxRow>"
 
87
              "<gmr:Zoom>1.000000</gmr:Zoom>"
 
88
              "<gmr:Cols>"
 
89
                "<gmr:ColInfo No=\"0\" Unit=\"97\" MarginA=\"1\" MarginB=\"1\" HardSize=\"0\"/>"
 
90
                "<gmr:ColInfo No=\"1\" Unit=\"80\" MarginA=\"1\" MarginB=\"1\" HardSize=\"0\"/>"
 
91
                "<gmr:ColInfo No=\"2\" Unit=\"80\" MarginA=\"1\" MarginB=\"1\" HardSize=\"0\"/>"
 
92
                "<gmr:ColInfo No=\"3\" Unit=\"80\" MarginA=\"1\" MarginB=\"1\" HardSize=\"0\"/>"
 
93
                "<gmr:ColInfo No=\"6\" Unit=\"80\" MarginA=\"1\" MarginB=\"1\" HardSize=\"0\"/>"
 
94
              "</gmr:Cols>"
 
95
              "<gmr:Rows>"
 
96
                "<gmr:RowInfo No=\"0\" Unit=\"20\" MarginA=\"1\" MarginB=\"1\" HardSize=\"0\"/>"
 
97
                "<gmr:RowInfo No=\"1\" Unit=\"20\" MarginA=\"1\" MarginB=\"1\" HardSize=\"0\"/>"
 
98
                "<gmr:RowInfo No=\"2\" Unit=\"20\" MarginA=\"1\" MarginB=\"1\" HardSize=\"0\"/>"
 
99
                "<gmr:RowInfo No=\"3\" Unit=\"20\" MarginA=\"1\" MarginB=\"1\" HardSize=\"0\"/>"
 
100
                "<gmr:RowInfo No=\"4\" Unit=\"20\" MarginA=\"1\" MarginB=\"1\" HardSize=\"0\"/>"
 
101
                "<gmr:RowInfo No=\"5\" Unit=\"20\" MarginA=\"1\" MarginB=\"1\" HardSize=\"0\"/>"
 
102
                "<gmr:RowInfo No=\"6\" Unit=\"20\" MarginA=\"1\" MarginB=\"1\" HardSize=\"0\"/>"
 
103
                "<gmr:RowInfo No=\"7\" Unit=\"20\" MarginA=\"1\" MarginB=\"1\" HardSize=\"0\"/>"
 
104
                "<gmr:RowInfo No=\"8\" Unit=\"20\" MarginA=\"1\" MarginB=\"1\" HardSize=\"0\"/>"
 
105
                "<gmr:RowInfo No=\"9\" Unit=\"20\" MarginA=\"1\" MarginB=\"1\" HardSize=\"0\"/>"
 
106
                "<gmr:RowInfo No=\"10\" Unit=\"20\" MarginA=\"1\" MarginB=\"1\" HardSize=\"0\"/>"
 
107
                "<gmr:RowInfo No=\"11\" Unit=\"20\" MarginA=\"1\" MarginB=\"1\" HardSize=\"0\"/>"
 
108
                "<gmr:RowInfo No=\"12\" Unit=\"20\" MarginA=\"1\" MarginB=\"1\" HardSize=\"0\"/>"
 
109
                "<gmr:RowInfo No=\"13\" Unit=\"20\" MarginA=\"1\" MarginB=\"1\" HardSize=\"0\"/>"
 
110
                "<gmr:RowInfo No=\"14\" Unit=\"20\" MarginA=\"1\" MarginB=\"1\" HardSize=\"0\"/>"
 
111
              "</gmr:Rows>"
 
112
              "<gmr:Objects>"
 
113
                "<gmr:Ellipse Pattern=\"0\" Width=\"1\" Color=\"black\">"
 
114
                  "<gmr:Points>(258.000000 320.000000)(356.000000 356.000000)</gmr:Points>"
 
115
                "</gmr:Ellipse>"
 
116
                "<gmr:Arrow Width=\"1\" Color=\"black\">"
 
117
                  "<gmr:Points>(500.000000 131.000000)(332.000000 320.000000)</gmr:Points>"
 
118
                "</gmr:Arrow>"
 
119
              "</gmr:Objects>"
 
120
              "<gmr:Cells>"
 
121
                "<gmr:Cell Col=\"3\" Row=\"1\">"
 
122
                  "<gmr:Style HAlign=\"1\" VAlign=\"1\" Fit=\"0\" Orient=\"1\" Shade=\"0\" Format=\"#,##0_);[red](#,##0)\">"
 
123
                    "<gmr:Font Unit=\"14\" NAME=\"FontDef2\">-adobe-helvetica-medium-r-normal--*-120-*-*-*-*-*-*</gmr:Font>"
 
124
                  "</gmr:Style>"
 
125
          "<gmr:Content>500</gmr:Content>",
 
126
 
 
127
  NULL
 
128
};
 
129
 
 
130
static gint ints[] = { -1, -2, -3, 0, 1, 2, 3, 4000, 0xfffff, -0xfffff, G_MININT, G_MAXINT, 0, 0, 57, 83, 95 };
 
131
static const guint n_ints = sizeof(ints)/sizeof(ints[0]);
 
132
 
 
133
static gboolean bools[] = { TRUE, TRUE, FALSE, FALSE, TRUE, FALSE, TRUE, FALSE, FALSE, FALSE,
 
134
                       FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, TRUE };
 
135
 
 
136
static const guint n_bools = sizeof(bools)/sizeof(bools[0]);
 
137
 
 
138
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 */
 
139
 
 
140
static const guint n_floats = sizeof(floats)/sizeof(floats[0]);
 
141
 
 
142
 
 
143
static void
 
144
check_unset(GConfEngine* conf)
 
145
{
 
146
  GError* err = NULL;
 
147
  const gchar** keyp = NULL;
 
148
  GConfChangeSet* cs;
 
149
 
 
150
  cs = gconf_change_set_new();
 
151
  
 
152
  keyp = keys;
 
153
 
 
154
  while (*keyp)
 
155
    {
 
156
      gconf_change_set_unset(cs, *keyp);
 
157
 
 
158
      ++keyp;
 
159
    }
 
160
 
 
161
  
 
162
  gconf_engine_commit_change_set(conf, cs, TRUE, &err);
 
163
  
 
164
  if (err != NULL)
 
165
    {
 
166
      fprintf(stderr, "unset commit failed: %s\n", err->message);
 
167
      g_error_free(err);
 
168
      err = NULL;
 
169
      exit(1);
 
170
    }
 
171
 
 
172
  gconf_change_set_unref(cs);
 
173
  
 
174
  keyp = keys;
 
175
  while (*keyp)
 
176
    {
 
177
      GConfValue* val;
 
178
      gchar* valstr;
 
179
      
 
180
      val = gconf_engine_get (conf, *keyp, &err);
 
181
      
 
182
      if (val)
 
183
        valstr = gconf_value_to_string(val);
 
184
      else
 
185
        valstr = g_strdup("(none)");
 
186
      
 
187
      check(val == NULL, "unsetting a previously-set value `%s' the value `%s' existed", *keyp, valstr);
 
188
      
 
189
      g_free(valstr);
 
190
      
 
191
      ++keyp;
 
192
    }
 
193
}
 
194
 
 
195
static void
 
196
check_string_storage(GConfEngine* conf)
 
197
{
 
198
  GError* err = NULL;
 
199
  const gchar** keyp = NULL;
 
200
  const gchar** valp = NULL;
 
201
  GConfChangeSet* cs;
 
202
 
 
203
  cs = gconf_change_set_new();
 
204
  
 
205
  keyp = keys;
 
206
  valp = some_strings;
 
207
  
 
208
  while (*keyp && *valp)
 
209
    {
 
210
      gconf_change_set_set_string(cs, *keyp, *valp);
 
211
 
 
212
      ++valp;
 
213
      ++keyp;
 
214
    }
 
215
 
 
216
  gconf_engine_commit_change_set(conf, cs, TRUE, &err);
 
217
  
 
218
  if (err != NULL)
 
219
    {
 
220
      fprintf(stderr, "set commit failed: %s\n", err->message);
 
221
      g_error_free(err);
 
222
      err = NULL;
 
223
      exit(1);
 
224
    }
 
225
 
 
226
  gconf_change_set_unref(cs);
 
227
  
 
228
  keyp = keys;
 
229
  valp = some_strings;
 
230
  
 
231
  while (*keyp && *valp)
 
232
    {
 
233
      gchar* gotten;
 
234
      
 
235
      gotten = gconf_engine_get_string(conf, *keyp, &err);
 
236
      
 
237
      if (err != NULL)
 
238
        {
 
239
          check(gotten == NULL, "string was returned though there was an error");
 
240
          fprintf(stderr, "Failed to get key `%s': %s\n",
 
241
                  *keyp, err->message);
 
242
          g_error_free(err);
 
243
          err = NULL;
 
244
          exit(1);
 
245
        }
 
246
      else
 
247
        {
 
248
          check (strcmp(gotten, *valp) == 0, "string set/get pair: `%s' set, `%s' got",
 
249
                 *valp, gotten);
 
250
          
 
251
          g_free(gotten);
 
252
        }
 
253
      
 
254
      ++valp;
 
255
      ++keyp;
 
256
    }
 
257
 
 
258
  check_unset(conf);
 
259
}
 
260
 
 
261
int 
 
262
main (int argc, char** argv)
 
263
{
 
264
  GConfEngine* conf;
 
265
  GError* err = NULL;
 
266
  
 
267
  if (!gconf_init(argc, argv, &err))
 
268
    {
 
269
      fprintf(stderr, "Failed to init GConf: %s\n", err->message);
 
270
      g_error_free(err);
 
271
      err = NULL;
 
272
      return 1;
 
273
    }
 
274
  
 
275
  conf = gconf_engine_get_default();
 
276
 
 
277
  check(conf != NULL, "create the default conf engine");
 
278
 
 
279
  printf("\nChecking string storage via GConfChangeSet:");
 
280
  
 
281
  check_string_storage(conf);
 
282
  
 
283
  gconf_engine_unref(conf);
 
284
 
 
285
  printf("\n\n");
 
286
  
 
287
  return 0;
 
288
}