#include "platform.h"
#include "gnunet_common.h"
#include "gnunet_configuration_lib.h"
+#include "gnunet_disk_lib.h"
-/* Directives used for testing Configuration Diffs */
#define DEBUG GNUNET_NO
-#define CONFIGURATION_DIFFS_PATH "/tmp/gnunet-diff.conf"
-#define EDIT_NOTHING 0
-#define EDIT_SECTION 1
-#define EDIT_ALL 2
-#define ADD_NEW_SECTION 3
-#define ADD_NEW_ENTRY 4
-#define REMOVE_SECTION 5
-#define REMOVE_ENTRY 6
-#define COMPARE 7
+/* Test Configuration Diffs Options */
+enum
+{
+ EDIT_NOTHING,
+ EDIT_SECTION,
+ EDIT_ALL,
+ ADD_NEW_SECTION,
+ ADD_NEW_ENTRY,
+ REMOVE_SECTION,
+ REMOVE_ENTRY,
+ COMPARE
#if DEBUG
-#define PRINT 8
+ , PRINT
#endif
+};
static struct GNUNET_CONFIGURATION_Handle *cfg;
static struct GNUNET_CONFIGURATION_Handle *cfgDefault;
switch (cbOption)
{
case EDIT_SECTION:
- if (cbData->section == NULL)
+ if (NULL == cbData->section)
cbData->section = section;
if (strcmp (cbData->section, section) == 0)
{
{
int ret;
char *diffValue;
+
+ diffValue = NULL;
ret =
GNUNET_CONFIGURATION_get_value_string (cbData->cfgDiffs, section,
option, &diffValue);
- if (ret == GNUNET_SYSERR || diffValue == NULL
- || 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;
}
#if DEBUG
case PRINT:
- if (cbData->section == NULL || strcmp (cbData->section, section) != 0)
+ if (NULL == cbData->section)
+ {
+ cbData->section = section;
+ printf ("\nSection: %s\n", section);
+ }
+ else if (strcmp (cbData->section, section) != 0)
{
cbData->section = section;
printf ("\nSection: %s\n", section);
break;
case ADD_NEW_SECTION:
{
- int i = 0;
+ int i;
char *key;
- for (; i < 5; i++)
+ for (i = 0; i < 5; i++)
{
GNUNET_asprintf (&key, "key%d", i);
GNUNET_CONFIGURATION_set_value_string (cfg, "new-section", key,
GNUNET_CONFIGURATION_set_value_string (diffsCB.cfgDiffs,
"new-section", key,
"new-value");
+ GNUNET_free (key);
}
break;
}
static int
checkDiffs (struct GNUNET_CONFIGURATION_Handle *cfgDefault, int option)
{
- struct GNUNET_CONFIGURATION_Handle *cfg, *cfgDiffs;
+ struct GNUNET_CONFIGURATION_Handle *cfg;
+ struct GNUNET_CONFIGURATION_Handle *cfgDiffs;
struct DiffsCBData cbData;
+ int ret;
+ char *diffsFileName;
+
initDiffsCBData (&cbData);
- int ret = 0;
cfg = GNUNET_CONFIGURATION_create ();
- GNUNET_CONFIGURATION_load (cfg, NULL);
+ /* load defaults */
+ GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (cfg, NULL));
/* Modify configuration and save it */
cfgDiffs = editConfiguration (cfg, option);
- GNUNET_CONFIGURATION_write_diffs (cfgDefault, cfg,
- CONFIGURATION_DIFFS_PATH);
+ diffsFileName =
+ GNUNET_DISK_mktemp ("gnunet-test-configurations-diffs.conf");
+ if (diffsFileName == NULL)
+ {
+ GNUNET_break (0);
+ GNUNET_CONFIGURATION_destroy (cfg);
+ GNUNET_CONFIGURATION_destroy (cfgDiffs);
+ return 1;
+ }
+ GNUNET_CONFIGURATION_write_diffs (cfgDefault, cfg, diffsFileName);
GNUNET_CONFIGURATION_destroy (cfg);
/* Compare the dumped configuration with modifications done */
cfg = GNUNET_CONFIGURATION_create ();
- GNUNET_CONFIGURATION_parse (cfg, CONFIGURATION_DIFFS_PATH);
+ GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_parse (cfg, diffsFileName));
+ remove (diffsFileName);
cbData.callBackOption = COMPARE;
cbData.cfgDiffs = cfgDiffs;
GNUNET_CONFIGURATION_iterate (cfg, diffsCallBack, &cbData);
- if ((ret = cbData.status) == 1)
+ if (1 == (ret = cbData.status))
{
fprintf (stderr,
"Incorrect Configuration Diffs: Diffs may contain data not actually edited\n");
#endif
GNUNET_CONFIGURATION_destroy (cfg);
GNUNET_CONFIGURATION_destroy (cfgDiffs);
+ GNUNET_free (diffsFileName);
return ret;
}
GNUNET_free (c);
if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg,
"test", "five", &l))
- return 3;
+ {
+ GNUNET_break (0);
+ return 3;
+ }
if (5 != l)
- return 4;
+ {
+ GNUNET_break (0);
+ return 4;
+ }
GNUNET_CONFIGURATION_set_value_string (cfg, "more", "c", "YES");
if (GNUNET_NO == GNUNET_CONFIGURATION_get_value_yesno (cfg, "more", "c"))
- return 5;
+ {
+ GNUNET_break (0);
+ return 5;
+ }
GNUNET_CONFIGURATION_set_value_number (cfg, "NUMBERS", "TEN", 10);
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg, "NUMBERS", "TEN", &c))
- return 6;
+ {
+ GNUNET_break (0);
+ return 6;
+ }
if (0 != strcmp (c, "10"))
{
GNUNET_free (c);
+ GNUNET_break (0);
return 7;
}
GNUNET_free (c);
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_filename (cfg, "last", "test", &c))
- return 8;
+ {
+ GNUNET_break (0);
+ return 8;
+ }
#ifndef MINGW
if (0 != strcmp (c, "/hello/world"))
#else
if (strstr (c, HI) != c + strlen (c) - strlen (HI))
#endif
{
+ GNUNET_break (0);
GNUNET_free (c);
return 9;
}
(*idx)++;
return GNUNET_OK;
}
+ GNUNET_break (0);
return GNUNET_SYSERR;
}
"FILENAMES",
"test",
&check, &idx))
- return 8;
+ {
+ GNUNET_break (0);
+ return 8;
+ }
if (idx != 3)
return 16;
if (GNUNET_OK !=
GNUNET_CONFIGURATION_remove_value_filename (cfg,
"FILENAMES",
"test", "/File Name"))
- return 24;
+ {
+ GNUNET_break (0);
+ return 24;
+ }
if (GNUNET_NO !=
GNUNET_CONFIGURATION_remove_value_filename (cfg,
"FILENAMES",
"test", "/File Name"))
- return 32;
+ {
+ GNUNET_break (0);
+ return 32;
+ }
if (GNUNET_NO !=
GNUNET_CONFIGURATION_remove_value_filename (cfg,
"FILENAMES",
"test", "Stuff"))
- return 40;
+ {
+ GNUNET_break (0);
+ return 40;
+ }
if (GNUNET_NO !=
GNUNET_CONFIGURATION_append_value_filename (cfg,
"FILENAMES",
"test", "/Hello"))
- return 48;
+ {
+ GNUNET_break (0);
+ return 48;
+ }
if (GNUNET_NO !=
GNUNET_CONFIGURATION_append_value_filename (cfg,
"FILENAMES",
"test", "/World"))
- return 56;
+ {
+ GNUNET_break (0);
+ return 56;
+ }
if (GNUNET_YES !=
GNUNET_CONFIGURATION_append_value_filename (cfg,
"FILENAMES",
"test", "/File 1"))
- return 64;
+ {
+ GNUNET_break (0);
+ return 64;
+ }
if (GNUNET_YES !=
GNUNET_CONFIGURATION_append_value_filename (cfg,
"FILENAMES",
"test", "/File 2"))
- return 72;
+ {
+ GNUNET_break (0);
+ return 72;
+ }
idx = 0;
want[1] = "/World";
"FILENAMES",
"test",
&check, &idx))
- return 80;
+ {
+ GNUNET_break (0);
+ return 80;
+ }
if (idx != 4)
- return 88;
+ {
+ GNUNET_break (0);
+ return 88;
+ }
return 0;
}
&c))
|| (0 != strcmp (c, "YES")))
{
- GNUNET_CONFIGURATION_destroy (cfg);
- return 1;
- }
- GNUNET_free (c);
- if ((GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", "SERVICEHOME",
- &c))
- || (0 != strcmp (c, "/var/lib/gnunet/")))
- {
+ GNUNET_break (0);
GNUNET_CONFIGURATION_destroy (cfg);
return 1;
}
/* Testing configuration diffs */
cfgDefault = GNUNET_CONFIGURATION_create ();
- if (GNUNET_CONFIGURATION_load (cfgDefault, NULL) == GNUNET_SYSERR)
+ if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfgDefault, NULL))
{
- printf ("\n Error! \n");
+ GNUNET_break (0);
+ GNUNET_CONFIGURATION_destroy (cfgDefault);
+ return 1;
}
/* Nothing changed in the new configuration */