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))
70 if (0 != strcmp (c, "/hello/world"))
80 static const char *want[] = {
89 check (void *data, const char *fn)
93 if (0 == strcmp (want[*idx], fn))
102 testConfigFilenames ()
107 if (3 != GNUNET_CONFIGURATION_iterate_value_filenames (cfg,
115 GNUNET_CONFIGURATION_remove_value_filename (cfg,
117 "test", "/File Name"))
121 GNUNET_CONFIGURATION_remove_value_filename (cfg,
123 "test", "/File Name"))
126 GNUNET_CONFIGURATION_remove_value_filename (cfg,
132 GNUNET_CONFIGURATION_append_value_filename (cfg,
137 GNUNET_CONFIGURATION_append_value_filename (cfg,
143 GNUNET_CONFIGURATION_append_value_filename (cfg,
149 GNUNET_CONFIGURATION_append_value_filename (cfg,
158 if (4 != GNUNET_CONFIGURATION_iterate_value_filenames (cfg,
169 main (int argc, char *argv[])
171 int failureCount = 0;
174 GNUNET_log_setup ("test_configuration", "WARNING", NULL);
175 cfg = GNUNET_CONFIGURATION_create ();
176 GNUNET_assert (cfg != NULL);
178 GNUNET_CONFIGURATION_parse (cfg, "test_configuration_data.conf"))
180 fprintf (stderr, "Failed to parse configuration file\n");
181 GNUNET_CONFIGURATION_destroy (cfg);
184 failureCount += testConfig ();
185 failureCount += 2 * testConfigFilenames ();
187 if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, "/tmp/gnunet-test.conf"))
189 fprintf (stderr, "Failed to write configuration file\n");
190 GNUNET_CONFIGURATION_destroy (cfg);
193 GNUNET_CONFIGURATION_destroy (cfg);
194 GNUNET_assert (0 == UNLINK ("/tmp/gnunet-test.conf"));
196 cfg = GNUNET_CONFIGURATION_create ();
198 GNUNET_CONFIGURATION_load (cfg, "test_configuration_data.conf"))
201 GNUNET_CONFIGURATION_destroy (cfg);
205 GNUNET_CONFIGURATION_get_value_string (cfg, "TESTING", "WEAKRANDOM",
207 || (0 != strcmp (c, "YES")))
209 GNUNET_CONFIGURATION_destroy (cfg);
214 GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", "SERVICEHOME",
216 || (0 != strcmp (c, "/var/lib/gnunet/")))
218 GNUNET_CONFIGURATION_destroy (cfg);
222 GNUNET_CONFIGURATION_destroy (cfg);
223 if (failureCount != 0)
225 fprintf (stderr, "Test failed: %u\n", failureCount);