aboutsummaryrefslogtreecommitdiff
path: root/src/util/test_configuration.c
diff options
context:
space:
mode:
authorSafey A.Halim <safey.allah@gmail.com>2009-11-20 18:04:25 +0000
committerSafey A.Halim <safey.allah@gmail.com>2009-11-20 18:04:25 +0000
commit512e1b2444a35a36740111655063a1d99dbc8c8d (patch)
tree43f1dd4b6210ede038f6f9d4914ad607622ae656 /src/util/test_configuration.c
parent94abb1c2cacd91010f99be82f5e33bf9a99a4221 (diff)
downloadgnunet-512e1b2444a35a36740111655063a1d99dbc8c8d.tar.gz
gnunet-512e1b2444a35a36740111655063a1d99dbc8c8d.zip
-> Using GNUNET_DISK_mktemp for the creation of temporary configuration file
-> Test Configuration Diffs code refactoring.
Diffstat (limited to 'src/util/test_configuration.c')
-rw-r--r--src/util/test_configuration.c67
1 files changed, 43 insertions, 24 deletions
diff --git a/src/util/test_configuration.c b/src/util/test_configuration.c
index 637c8ed00..609f797bd 100644
--- a/src/util/test_configuration.c
+++ b/src/util/test_configuration.c
@@ -26,22 +26,25 @@
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_common.h" 27#include "gnunet_common.h"
28#include "gnunet_configuration_lib.h" 28#include "gnunet_configuration_lib.h"
29#include "gnunet_disk_lib.h"
29 30
30/* Directives used for testing Configuration Diffs */
31#define DEBUG GNUNET_NO 31#define DEBUG GNUNET_NO
32#define CONFIGURATION_DIFFS_PATH "/tmp/gnunet-diff.conf"
33#define EDIT_NOTHING 0
34#define EDIT_SECTION 1
35#define EDIT_ALL 2
36#define ADD_NEW_SECTION 3
37#define ADD_NEW_ENTRY 4
38#define REMOVE_SECTION 5
39#define REMOVE_ENTRY 6
40#define COMPARE 7
41 32
33/* Test Configuration Diffs Options */
34enum
35{
36 EDIT_NOTHING,
37 EDIT_SECTION,
38 EDIT_ALL,
39 ADD_NEW_SECTION,
40 ADD_NEW_ENTRY,
41 REMOVE_SECTION,
42 REMOVE_ENTRY,
43 COMPARE
42#if DEBUG 44#if DEBUG
43#define PRINT 8 45 , PRINT
44#endif 46#endif
47};
45 48
46static struct GNUNET_CONFIGURATION_Handle *cfg; 49static struct GNUNET_CONFIGURATION_Handle *cfg;
47static struct GNUNET_CONFIGURATION_Handle *cfgDefault; 50static struct GNUNET_CONFIGURATION_Handle *cfgDefault;
@@ -81,7 +84,7 @@ diffsCallBack (void *cls,
81 switch (cbOption) 84 switch (cbOption)
82 { 85 {
83 case EDIT_SECTION: 86 case EDIT_SECTION:
84 if (cbData->section == NULL) 87 if (NULL == cbData->section)
85 cbData->section = section; 88 cbData->section = section;
86 if (strcmp (cbData->section, section) == 0) 89 if (strcmp (cbData->section, section) == 0)
87 { 90 {
@@ -117,14 +120,23 @@ diffsCallBack (void *cls,
117 ret = 120 ret =
118 GNUNET_CONFIGURATION_get_value_string (cbData->cfgDiffs, section, 121 GNUNET_CONFIGURATION_get_value_string (cbData->cfgDiffs, section,
119 option, &diffValue); 122 option, &diffValue);
120 if (ret == GNUNET_SYSERR || diffValue == NULL 123 if (NULL != diffValue)
121 || strcmp (diffValue, value) != 0) 124 {
125 if (ret == GNUNET_SYSERR || strcmp (diffValue, value) != 0)
126 cbData->status = 1;
127 }
128 else
122 cbData->status = 1; 129 cbData->status = 1;
123 break; 130 break;
124 } 131 }
125#if DEBUG 132#if DEBUG
126 case PRINT: 133 case PRINT:
127 if (cbData->section == NULL || strcmp (cbData->section, section) != 0) 134 if (NULL == cbData->section)
135 {
136 cbData->section = section;
137 printf ("\nSection: %s\n", section);
138 }
139 else if (strcmp (cbData->section, section) != 0)
128 { 140 {
129 cbData->section = section; 141 cbData->section = section;
130 printf ("\nSection: %s\n", section); 142 printf ("\nSection: %s\n", section);
@@ -158,9 +170,9 @@ editConfiguration (struct GNUNET_CONFIGURATION_Handle *cfg, int option)
158 break; 170 break;
159 case ADD_NEW_SECTION: 171 case ADD_NEW_SECTION:
160 { 172 {
161 int i = 0; 173 int i;
162 char *key; 174 char *key;
163 for (; i < 5; i++) 175 for (i = 0; i < 5; i++)
164 { 176 {
165 GNUNET_asprintf (&key, "key%d", i); 177 GNUNET_asprintf (&key, "key%d", i);
166 GNUNET_CONFIGURATION_set_value_string (cfg, "new-section", key, 178 GNUNET_CONFIGURATION_set_value_string (cfg, "new-section", key,
@@ -188,23 +200,28 @@ editConfiguration (struct GNUNET_CONFIGURATION_Handle *cfg, int option)
188static int 200static int
189checkDiffs (struct GNUNET_CONFIGURATION_Handle *cfgDefault, int option) 201checkDiffs (struct GNUNET_CONFIGURATION_Handle *cfgDefault, int option)
190{ 202{
191 struct GNUNET_CONFIGURATION_Handle *cfg, *cfgDiffs; 203 struct GNUNET_CONFIGURATION_Handle *cfg;
204 struct GNUNET_CONFIGURATION_Handle *cfgDiffs;
192 struct DiffsCBData cbData; 205 struct DiffsCBData cbData;
206 int ret;
207 char *diffsFileName;
208
193 initDiffsCBData (&cbData); 209 initDiffsCBData (&cbData);
194 int ret = 0;
195 210
196 cfg = GNUNET_CONFIGURATION_create (); 211 cfg = GNUNET_CONFIGURATION_create ();
197 GNUNET_CONFIGURATION_load (cfg, NULL); 212 GNUNET_CONFIGURATION_load (cfg, NULL);
198 213
199 /* Modify configuration and save it */ 214 /* Modify configuration and save it */
200 cfgDiffs = editConfiguration (cfg, option); 215 cfgDiffs = editConfiguration (cfg, option);
201 GNUNET_CONFIGURATION_write_diffs (cfgDefault, cfg, 216 diffsFileName =
202 CONFIGURATION_DIFFS_PATH); 217 GNUNET_DISK_mktemp ("gnunet-test-configurations-diffs.conf");
218 GNUNET_CONFIGURATION_write_diffs (cfgDefault, cfg, diffsFileName);
203 GNUNET_CONFIGURATION_destroy (cfg); 219 GNUNET_CONFIGURATION_destroy (cfg);
204 220
205 /* Compare the dumped configuration with modifications done */ 221 /* Compare the dumped configuration with modifications done */
206 cfg = GNUNET_CONFIGURATION_create (); 222 cfg = GNUNET_CONFIGURATION_create ();
207 GNUNET_CONFIGURATION_parse (cfg, CONFIGURATION_DIFFS_PATH); 223 GNUNET_CONFIGURATION_parse (cfg, diffsFileName);
224 remove (diffsFileName);
208 cbData.callBackOption = COMPARE; 225 cbData.callBackOption = COMPARE;
209 cbData.cfgDiffs = cfgDiffs; 226 cbData.cfgDiffs = cfgDiffs;
210 GNUNET_CONFIGURATION_iterate (cfg, diffsCallBack, &cbData); 227 GNUNET_CONFIGURATION_iterate (cfg, diffsCallBack, &cbData);
@@ -436,9 +453,11 @@ main (int argc, char *argv[])
436 453
437 /* Testing configuration diffs */ 454 /* Testing configuration diffs */
438 cfgDefault = GNUNET_CONFIGURATION_create (); 455 cfgDefault = GNUNET_CONFIGURATION_create ();
439 if (GNUNET_CONFIGURATION_load (cfgDefault, NULL) == GNUNET_SYSERR) 456 if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfgDefault, NULL))
440 { 457 {
441 printf ("\n Error! \n"); 458 GNUNET_break (0);
459 GNUNET_CONFIGURATION_destroy (cfgDefault);
460 return 1;
442 } 461 }
443 462
444 /* Nothing changed in the new configuration */ 463 /* Nothing changed in the new configuration */