/*
This file is part of GNUnet.
- (C) 2003, 2004, 2005, 2006, 2007 Christian Grothoff (and other contributing authors)
+ Copyright (C) 2003, 2004, 2005, 2006, 2007 GNUnet e.V.
- GNUnet is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published
- by the Free Software Foundation; either version 3, or (at your
- option) any later version.
+ GNUnet is free software: you can redistribute it and/or modify it
+ under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License,
+ or (at your option) any later version.
GNUnet is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
+ Affero General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with GNUnet; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
-*/
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+ SPDX-License-Identifier: AGPL3.0-or-later
+ */
/**
* @file util/test_configuration.c
* @brief Test that the configuration module works.
*/
#include "platform.h"
-#include "gnunet_common.h"
-#include "gnunet_configuration_lib.h"
-#include "gnunet_disk_lib.h"
+#include "gnunet_util_lib.h"
-#define DEBUG GNUNET_EXTRA_LOGGING
/* Test Configuration Diffs Options */
enum
ADD_NEW_ENTRY,
REMOVE_SECTION,
REMOVE_ENTRY,
- COMPARE
-#if DEBUG
- , PRINT
-#endif
+ COMPARE,
+ PRINT
};
static struct GNUNET_CONFIGURATION_Handle *cfg;
-static struct GNUNET_CONFIGURATION_Handle *cfgDefault;
+static struct GNUNET_CONFIGURATION_Handle *cfg_default;
struct DiffsCBData
{
/**
* callback function for modifying
* and comparing configuration
-*/
+ */
static void
diffsCallBack (void *cls, const char *section, const char *option,
const char *value)
"new-value");
}
break;
+
case EDIT_ALL:
GNUNET_CONFIGURATION_set_value_string (cbData->cfg, section, option,
"new-value");
GNUNET_CONFIGURATION_set_value_string (cbData->cfgDiffs, section, option,
"new-value");
break;
- case ADD_NEW_ENTRY:
- {
- static int hit = 0;
- if (hit == 0)
+ case ADD_NEW_ENTRY:
{
- hit = 1;
- GNUNET_CONFIGURATION_set_value_string (cbData->cfg, section, "new-key",
- "new-value");
- GNUNET_CONFIGURATION_set_value_string (cbData->cfgDiffs, section,
- "new-key", "new-value");
+ static int hit = 0;
+
+ if (hit == 0)
+ {
+ hit = 1;
+ GNUNET_CONFIGURATION_set_value_string (cbData->cfg, section, "new-key",
+ "new-value");
+ GNUNET_CONFIGURATION_set_value_string (cbData->cfgDiffs, section,
+ "new-key", "new-value");
+ }
+ break;
}
- break;
- }
+
case COMPARE:
- {
- int ret;
- char *diffValue;
+ {
+ int ret;
+ char *diffValue;
- diffValue = NULL;
- ret =
+ diffValue = NULL;
+ ret =
GNUNET_CONFIGURATION_get_value_string (cbData->cfgDiffs, section,
option, &diffValue);
- if (NULL != diffValue)
- {
- if (ret == GNUNET_SYSERR || strcmp (diffValue, value) != 0)
+ if (NULL != diffValue)
+ {
+ if ((ret == GNUNET_SYSERR) || (strcmp (diffValue, value) != 0) )
+ cbData->status = 1;
+ }
+ else
cbData->status = 1;
+ GNUNET_free_non_null (diffValue);
+ break;
}
- else
- cbData->status = 1;
- GNUNET_free_non_null (diffValue);
- break;
- }
-#if DEBUG
+
+#if 0
case PRINT:
if (NULL == cbData->section)
{
diffsCB.cfg = cfg;
GNUNET_CONFIGURATION_iterate (cfg, diffsCallBack, &diffsCB);
break;
+
case EDIT_NOTHING:
/* Do nothing */
break;
- case ADD_NEW_SECTION:
- {
- int i;
- char *key;
- for (i = 0; i < 5; i++)
+ case ADD_NEW_SECTION:
{
- GNUNET_asprintf (&key, "key%d", i);
- GNUNET_CONFIGURATION_set_value_string (cfg, "new-section", key,
- "new-value");
- GNUNET_CONFIGURATION_set_value_string (diffsCB.cfgDiffs, "new-section",
- key, "new-value");
- GNUNET_free (key);
+ int i;
+ char *key;
+
+ for (i = 0; i < 5; i++)
+ {
+ GNUNET_asprintf (&key, "key%d", i);
+ GNUNET_CONFIGURATION_set_value_string (cfg, "new-section", key,
+ "new-value");
+ GNUNET_CONFIGURATION_set_value_string (diffsCB.cfgDiffs, "new-section",
+ key, "new-value");
+ GNUNET_free (key);
+ }
+ break;
}
- break;
- }
+
case REMOVE_SECTION:
break;
+
case REMOVE_ENTRY:
break;
+
default:
break;
}
return diffsCB.cfgDiffs;
}
+
/**
* Checking configuration diffs
*/
static int
-checkDiffs (struct GNUNET_CONFIGURATION_Handle *cfgDefault, int option)
+checkDiffs (struct GNUNET_CONFIGURATION_Handle *cfg_default, int option)
{
struct GNUNET_CONFIGURATION_Handle *cfg;
struct GNUNET_CONFIGURATION_Handle *cfgDiffs;
GNUNET_CONFIGURATION_destroy (cfgDiffs);
return 1;
}
- GNUNET_CONFIGURATION_write_diffs (cfgDefault, cfg, diffsFileName);
+ GNUNET_CONFIGURATION_write_diffs (cfg_default, cfg, diffsFileName);
GNUNET_CONFIGURATION_destroy (cfg);
/* Compare the dumped configuration with modifications done */
cfg = GNUNET_CONFIGURATION_create ();
GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_parse (cfg, diffsFileName));
- remove (diffsFileName);
+ if (0 != remove (diffsFileName))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "remove",
+ diffsFileName);
cbData.callBackOption = COMPARE;
cbData.cfgDiffs = cfgDiffs;
GNUNET_CONFIGURATION_iterate (cfg, diffsCallBack, &cbData);
if (1 == (ret = cbData.status))
{
- fprintf (stderr,
+ fprintf (stderr, "%s",
"Incorrect Configuration Diffs: Diffs may contain data not actually edited\n");
goto housekeeping;
}
cbData.cfgDiffs = cfg;
GNUNET_CONFIGURATION_iterate (cfgDiffs, diffsCallBack, &cbData);
if ((ret = cbData.status) == 1)
- fprintf (stderr,
+ fprintf (stderr, "%s",
"Incorrect Configuration Diffs: Data may be missing in diffs\n");
housekeeping:
-#if DEBUG
+#if 0
cbData.section = NULL;
cbData.callBackOption = PRINT;
printf ("\nExpected Diffs:\n");
GNUNET_break (0);
return 8;
}
-#ifndef MINGW
+
if (0 != strcmp (c, "/hello/world"))
-#else
-#define HI "\\hello\\world"
- if (strstr (c, HI) != c + strlen (c) - strlen (HI))
-#endif
{
GNUNET_break (0);
GNUNET_free (c);
}
GNUNET_free (c);
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_size (cfg, "last", "size", &l))
+ {
+ GNUNET_break (0);
+ return 10;
+ }
+ if (l != 512 * 1024)
+ {
+ GNUNET_break (0);
+ return 11;
+ }
return 0;
}
+
static const char *want[] = {
"/Hello",
"/File Name",
return GNUNET_SYSERR;
}
+
static int
testConfigFilenames ()
{
if (GNUNET_OK !=
GNUNET_CONFIGURATION_parse (cfg, "test_configuration_data.conf"))
{
- fprintf (stderr, "Failed to parse configuration file\n");
+ fprintf (stderr, "%s", "Failed to parse configuration file\n");
GNUNET_CONFIGURATION_destroy (cfg);
return 1;
}
if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, "/tmp/gnunet-test.conf"))
{
- fprintf (stderr, "Failed to write configuration file\n");
+ fprintf (stderr, "%s", "Failed to write configuration file\n");
GNUNET_CONFIGURATION_destroy (cfg);
return 1;
}
GNUNET_CONFIGURATION_destroy (cfg);
- GNUNET_assert (0 == UNLINK ("/tmp/gnunet-test.conf"));
+ GNUNET_assert (0 == unlink ("/tmp/gnunet-test.conf"));
cfg = GNUNET_CONFIGURATION_create ();
if (GNUNET_OK !=
GNUNET_CONFIGURATION_destroy (cfg);
/* Testing configuration diffs */
- cfgDefault = GNUNET_CONFIGURATION_create ();
- if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfgDefault, NULL))
+ cfg_default = GNUNET_CONFIGURATION_create ();
+ if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg_default, NULL))
{
GNUNET_break (0);
- GNUNET_CONFIGURATION_destroy (cfgDefault);
+ GNUNET_CONFIGURATION_destroy (cfg_default);
return 1;
}
/* Nothing changed in the new configuration */
- failureCount += checkDiffs (cfgDefault, EDIT_NOTHING);
+ failureCount += checkDiffs (cfg_default, EDIT_NOTHING);
/* Modify all entries of the last section */
- failureCount += checkDiffs (cfgDefault, EDIT_SECTION);
+ failureCount += checkDiffs (cfg_default, EDIT_SECTION);
/* Add a new section */
- failureCount += checkDiffs (cfgDefault, ADD_NEW_SECTION);
+ failureCount += checkDiffs (cfg_default, ADD_NEW_SECTION);
/* Add a new entry to the last section */
- failureCount += checkDiffs (cfgDefault, ADD_NEW_ENTRY);
+ failureCount += checkDiffs (cfg_default, ADD_NEW_ENTRY);
/* Modify all entries in the configuration */
- failureCount += checkDiffs (cfgDefault, EDIT_ALL);
+ failureCount += checkDiffs (cfg_default, EDIT_ALL);
- GNUNET_CONFIGURATION_destroy (cfgDefault);
+ GNUNET_CONFIGURATION_destroy (cfg_default);
error:
if (failureCount != 0)