2 This file is part of GNUnet.
3 (C) 2003, 2004, 2005, 2006, 2007 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
21 * @file util/test_configuration.c
22 * @brief Test that the configuration module works.
23 * @author Christian Grothoff
27 #include "gnunet_common.h"
28 #include "gnunet_configuration_lib.h"
30 static struct GNUNET_CONFIGURATION_Handle *cfg;
39 GNUNET_CONFIGURATION_get_value_string (cfg, "test", "b", &c))
41 if (0 != strcmp ("b", c))
43 fprintf (stderr, "Got `%s'\n", c);
48 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg,
53 GNUNET_CONFIGURATION_set_value_string (cfg, "more", "c", "YES");
54 if (GNUNET_NO == GNUNET_CONFIGURATION_get_value_yesno (cfg, "more", "c"))
56 GNUNET_CONFIGURATION_set_value_number (cfg, "NUMBERS", "TEN", 10);
58 GNUNET_CONFIGURATION_get_value_string (cfg, "NUMBERS", "TEN", &c))
60 if (0 != strcmp (c, "10"))
68 GNUNET_CONFIGURATION_get_value_filename (cfg, "last", "test", &c))
71 if (0 != strcmp (c, "/hello/world"))
73 #define HI "\\hello\\world"
74 if (strstr (c, HI) != c + strlen (c) - strlen (HI))
85 static const char *want[] = {
94 check (void *data, const char *fn)
98 if (0 == strcmp (want[*idx], fn))
103 return GNUNET_SYSERR;
107 testConfigFilenames ()
112 if (3 != GNUNET_CONFIGURATION_iterate_value_filenames (cfg,
120 GNUNET_CONFIGURATION_remove_value_filename (cfg,
122 "test", "/File Name"))
126 GNUNET_CONFIGURATION_remove_value_filename (cfg,
128 "test", "/File Name"))
131 GNUNET_CONFIGURATION_remove_value_filename (cfg,
137 GNUNET_CONFIGURATION_append_value_filename (cfg,
142 GNUNET_CONFIGURATION_append_value_filename (cfg,
148 GNUNET_CONFIGURATION_append_value_filename (cfg,
154 GNUNET_CONFIGURATION_append_value_filename (cfg,
163 if (4 != GNUNET_CONFIGURATION_iterate_value_filenames (cfg,
174 main (int argc, char *argv[])
176 int failureCount = 0;
179 GNUNET_log_setup ("test_configuration", "WARNING", NULL);
180 cfg = GNUNET_CONFIGURATION_create ();
181 GNUNET_assert (cfg != NULL);
183 GNUNET_CONFIGURATION_parse (cfg, "test_configuration_data.conf"))
185 fprintf (stderr, "Failed to parse configuration file\n");
186 GNUNET_CONFIGURATION_destroy (cfg);
189 failureCount += testConfig ();
190 failureCount += 2 * testConfigFilenames ();
192 if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, "/tmp/gnunet-test.conf"))
194 fprintf (stderr, "Failed to write configuration file\n");
195 GNUNET_CONFIGURATION_destroy (cfg);
198 GNUNET_CONFIGURATION_destroy (cfg);
199 GNUNET_assert (0 == UNLINK ("/tmp/gnunet-test.conf"));
201 cfg = GNUNET_CONFIGURATION_create ();
203 GNUNET_CONFIGURATION_load (cfg, "test_configuration_data.conf"))
206 GNUNET_CONFIGURATION_destroy (cfg);
210 GNUNET_CONFIGURATION_get_value_string (cfg, "TESTING", "WEAKRANDOM",
212 || (0 != strcmp (c, "YES")))
214 GNUNET_CONFIGURATION_destroy (cfg);
219 GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", "SERVICEHOME",
221 || (0 != strcmp (c, "/var/lib/gnunet/")))
223 GNUNET_CONFIGURATION_destroy (cfg);
227 GNUNET_CONFIGURATION_destroy (cfg);
228 if (failureCount != 0)
230 fprintf (stderr, "Test failed: %u\n", failureCount);