X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Futil%2Ftest_configuration.c;h=bbee2de92d16028f2d142a83db6cccf6dc272784;hb=65f518e8036699fa3c574266d39e3cd1263af9e8;hp=2737cb4f7eda1d5f0ed9040b6f7b1a60333a5d05;hpb=5746309cb4be2073d550ad7a6885e918631dbc38;p=oweals%2Fgnunet.git diff --git a/src/util/test_configuration.c b/src/util/test_configuration.c index 2737cb4f7..bbee2de92 100644 --- a/src/util/test_configuration.c +++ b/src/util/test_configuration.c @@ -1,6 +1,6 @@ /* 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 Christian Grothoff (and other contributing authors) GNUnet is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published @@ -24,11 +24,8 @@ */ #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_NO /* Test Configuration Diffs Options */ enum @@ -40,14 +37,12 @@ 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 { @@ -133,7 +128,7 @@ diffsCallBack (void *cls, const char *section, const char *option, GNUNET_free_non_null (diffValue); break; } -#if DEBUG +#if 0 case PRINT: if (NULL == cbData->section) { @@ -204,7 +199,7 @@ editConfiguration (struct GNUNET_CONFIGURATION_Handle *cfg, int option) * 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; @@ -228,30 +223,31 @@ checkDiffs (struct GNUNET_CONFIGURATION_Handle *cfgDefault, int option) 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"); @@ -277,7 +273,7 @@ testConfig () return 1; if (0 != strcmp ("b", c)) { - fprintf (stderr, "Got `%s'\n", c); + FPRINTF (stderr, "Got `%s'\n", c); GNUNET_free (c); return 2; } @@ -333,6 +329,17 @@ testConfig () } 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; } @@ -459,7 +466,7 @@ main (int argc, char *argv[]) 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; } @@ -473,7 +480,7 @@ main (int argc, char *argv[]) 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; } @@ -507,35 +514,35 @@ main (int argc, char *argv[]) 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) { - fprintf (stderr, "Test failed: %u\n", failureCount); + FPRINTF (stderr, "Test failed: %u\n", failureCount); return 1; } return 0;