diff options
author | Safey A.Halim <safey.allah@gmail.com> | 2009-11-10 08:06:11 +0000 |
---|---|---|
committer | Safey A.Halim <safey.allah@gmail.com> | 2009-11-10 08:06:11 +0000 |
commit | 63aea8612441c32317fbe7ffd238f14a03c614fe (patch) | |
tree | cfaa6d673aa09ef4dd0f705c5a244b51c7b95e5b /src | |
parent | 37edd6776d34c68b4e84bdc705ea451aac2c71b2 (diff) | |
download | gnunet-63aea8612441c32317fbe7ffd238f14a03c614fe.tar.gz gnunet-63aea8612441c32317fbe7ffd238f14a03c614fe.zip |
Diffstat (limited to 'src')
-rw-r--r-- | src/util/configuration.c | 30 | ||||
-rw-r--r-- | src/util/test_configuration.c | 129 |
2 files changed, 96 insertions, 63 deletions
diff --git a/src/util/configuration.c b/src/util/configuration.c index e35dfacfe..d64ca8e83 100644 --- a/src/util/configuration.c +++ b/src/util/configuration.c | |||
@@ -98,6 +98,16 @@ struct GNUNET_CONFIGURATION_Handle | |||
98 | 98 | ||
99 | }; | 99 | }; |
100 | 100 | ||
101 | /** | ||
102 | * Used for diffing a configuration object against | ||
103 | * the default one | ||
104 | */ | ||
105 | struct GNUNNET_CONFIGURATION_Diff_Handle{ | ||
106 | struct GNUNET_CONFIGURATION_Handle* cfgNew; | ||
107 | struct GNUNET_CONFIGURATION_Handle* cfgDiff; | ||
108 | }; | ||
109 | |||
110 | |||
101 | 111 | ||
102 | /** | 112 | /** |
103 | * Create a GNUNET_CONFIGURATION_Handle. | 113 | * Create a GNUNET_CONFIGURATION_Handle. |
@@ -478,7 +488,7 @@ compareEntries( | |||
478 | { | 488 | { |
479 | struct ConfigSection *secNew; | 489 | struct ConfigSection *secNew; |
480 | struct ConfigEntry *entNew; | 490 | struct ConfigEntry *entNew; |
481 | GNUNNET_CONFIGURATION_Diff_Handle* cfgDiff = (GNUNNET_CONFIGURATION_Diff_Handle*)cls; | 491 | struct GNUNNET_CONFIGURATION_Diff_Handle* cfgDiff = (struct GNUNNET_CONFIGURATION_Diff_Handle*)cls; |
482 | 492 | ||
483 | secNew = findSection(cfgDiff->cfgNew, section); | 493 | secNew = findSection(cfgDiff->cfgNew, section); |
484 | entNew = findEntry(cfgDiff->cfgNew, section, option); | 494 | entNew = findEntry(cfgDiff->cfgNew, section, option); |
@@ -551,14 +561,18 @@ GNUNET_CONFIGURATION_write_diffs( | |||
551 | const char* filename | 561 | const char* filename |
552 | ) | 562 | ) |
553 | { | 563 | { |
554 | GNUNNET_CONFIGURATION_Diff_Handle *diffHandle = | 564 | int ret; |
555 | GNUNET_malloc(sizeof(GNUNNET_CONFIGURATION_Diff_Handle)); | 565 | struct GNUNNET_CONFIGURATION_Diff_Handle diffHandle; |
556 | diffHandle->cfgDiff = GNUNET_CONFIGURATION_create(); | 566 | diffHandle.cfgDiff = GNUNET_CONFIGURATION_create(); |
557 | diffHandle->cfgDiff->sections = NULL; | 567 | diffHandle.cfgDiff->sections = NULL; |
558 | diffHandle->cfgNew = cfgNew; | 568 | diffHandle.cfgNew = cfgNew; |
559 | GNUNET_CONFIGURATION_iterate(cfgDefault, compareEntries, diffHandle); | 569 | GNUNET_CONFIGURATION_iterate(cfgDefault, compareEntries, &diffHandle); |
570 | |||
571 | ret = GNUNET_CONFIGURATION_write(diffHandle.cfgDiff, filename); | ||
560 | 572 | ||
561 | return GNUNET_CONFIGURATION_write(diffHandle->cfgDiff, filename); | 573 | /* Housekeeping */ |
574 | GNUNET_CONFIGURATION_destroy(diffHandle.cfgDiff); | ||
575 | return ret; | ||
562 | } | 576 | } |
563 | 577 | ||
564 | 578 | ||
diff --git a/src/util/test_configuration.c b/src/util/test_configuration.c index 4c7f69a14..150b8d6b4 100644 --- a/src/util/test_configuration.c +++ b/src/util/test_configuration.c | |||
@@ -173,62 +173,81 @@ testConfigFilenames () | |||
173 | int | 173 | int |
174 | main (int argc, char *argv[]) | 174 | main (int argc, char *argv[]) |
175 | { | 175 | { |
176 | int failureCount = 0; | 176 | // int failureCount = 0; |
177 | char *c; | 177 | // char *c; |
178 | 178 | ||
179 | GNUNET_log_setup ("test_configuration", "WARNING", NULL); | 179 | // GNUNET_log_setup ("test_configuration", "WARNING", NULL); |
180 | cfg = GNUNET_CONFIGURATION_create (); | 180 | // cfg = GNUNET_CONFIGURATION_create (); |
181 | GNUNET_assert (cfg != NULL); | 181 | // GNUNET_assert (cfg != NULL); |
182 | // if (GNUNET_OK != | ||
183 | // GNUNET_CONFIGURATION_parse (cfg, "test_configuration_data.conf")) | ||
184 | // { | ||
185 | // fprintf (stderr, "Failed to parse configuration file\n"); | ||
186 | // GNUNET_CONFIGURATION_destroy (cfg); | ||
187 | // return 1; | ||
188 | // } | ||
189 | // failureCount += testConfig (); | ||
190 | // failureCount += 2 * testConfigFilenames (); | ||
191 | // | ||
192 | // if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, "/tmp/gnunet-test.conf")) | ||
193 | // { | ||
194 | // fprintf (stderr, "Failed to write configuration file\n"); | ||
195 | // GNUNET_CONFIGURATION_destroy (cfg); | ||
196 | // return 1; | ||
197 | // } | ||
198 | // GNUNET_CONFIGURATION_destroy (cfg); | ||
199 | // GNUNET_assert (0 == UNLINK ("/tmp/gnunet-test.conf")); | ||
200 | // | ||
201 | // cfg = GNUNET_CONFIGURATION_create (); | ||
202 | // if (GNUNET_OK != | ||
203 | // GNUNET_CONFIGURATION_load (cfg, "test_configuration_data.conf")) | ||
204 | // { | ||
205 | // GNUNET_break (0); | ||
206 | // GNUNET_CONFIGURATION_destroy (cfg); | ||
207 | // return 1; | ||
208 | // } | ||
209 | // if ((GNUNET_OK != | ||
210 | // GNUNET_CONFIGURATION_get_value_string (cfg, "TESTING", "WEAKRANDOM", | ||
211 | // &c)) | ||
212 | // || (0 != strcmp (c, "YES"))) | ||
213 | // { | ||
214 | // GNUNET_CONFIGURATION_destroy (cfg); | ||
215 | // return 1; | ||
216 | // } | ||
217 | // GNUNET_free (c); | ||
218 | // if ((GNUNET_OK != | ||
219 | // GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", "SERVICEHOME", | ||
220 | // &c)) | ||
221 | // || (0 != strcmp (c, "/var/lib/gnunet/"))) | ||
222 | // { | ||
223 | // GNUNET_CONFIGURATION_destroy (cfg); | ||
224 | // return 1; | ||
225 | // } | ||
226 | // GNUNET_free (c); | ||
227 | // GNUNET_CONFIGURATION_destroy (cfg); | ||
228 | // if (failureCount != 0) | ||
229 | // { | ||
230 | // fprintf (stderr, "Test failed: %u\n", failureCount); | ||
231 | // return 1; | ||
232 | // } | ||
233 | // | ||
234 | struct GNUNET_CONFIGURATION_Handle* cfgDefault = GNUNET_CONFIGURATION_create (); | ||
235 | struct GNUNET_CONFIGURATION_Handle* cfgNew = GNUNET_CONFIGURATION_create(); | ||
182 | if (GNUNET_OK != | 236 | if (GNUNET_OK != |
183 | GNUNET_CONFIGURATION_parse (cfg, "test_configuration_data.conf")) | 237 | GNUNET_CONFIGURATION_parse (cfgDefault, "src/util/test_configuration_data.conf")) |
184 | { | 238 | { |
185 | fprintf (stderr, "Failed to parse configuration file\n"); | 239 | fprintf (stderr, "Failed to parse configuration file\n"); |
186 | GNUNET_CONFIGURATION_destroy (cfg); | 240 | GNUNET_CONFIGURATION_destroy (cfgDefault); |
187 | return 1; | 241 | return 1; |
188 | } | 242 | } |
189 | failureCount += testConfig (); | ||
190 | failureCount += 2 * testConfigFilenames (); | ||
191 | |||
192 | if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, "/tmp/gnunet-test.conf")) | ||
193 | { | ||
194 | fprintf (stderr, "Failed to write configuration file\n"); | ||
195 | GNUNET_CONFIGURATION_destroy (cfg); | ||
196 | return 1; | ||
197 | } | ||
198 | GNUNET_CONFIGURATION_destroy (cfg); | ||
199 | GNUNET_assert (0 == UNLINK ("/tmp/gnunet-test.conf")); | ||
200 | |||
201 | cfg = GNUNET_CONFIGURATION_create (); | ||
202 | if (GNUNET_OK != | 243 | if (GNUNET_OK != |
203 | GNUNET_CONFIGURATION_load (cfg, "test_configuration_data.conf")) | 244 | GNUNET_CONFIGURATION_parse (cfgNew, "/Users/soufi/Desktop/test_configuration_data.conf")) |
204 | { | 245 | { |
205 | GNUNET_break (0); | 246 | fprintf (stderr, "Failed to parse configuration file\n"); |
206 | GNUNET_CONFIGURATION_destroy (cfg); | 247 | GNUNET_CONFIGURATION_destroy (cfgNew); |
207 | return 1; | 248 | return 1; |
208 | } | 249 | } |
209 | if ((GNUNET_OK != | 250 | |
210 | GNUNET_CONFIGURATION_get_value_string (cfg, "TESTING", "WEAKRANDOM", | 251 | GNUNET_CONFIGURATION_write_diffs(cfgDefault, cfgNew, "/tmp/safey.conf"); |
211 | &c)) | ||
212 | || (0 != strcmp (c, "YES"))) | ||
213 | { | ||
214 | GNUNET_CONFIGURATION_destroy (cfg); | ||
215 | return 1; | ||
216 | } | ||
217 | GNUNET_free (c); | ||
218 | if ((GNUNET_OK != | ||
219 | GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", "SERVICEHOME", | ||
220 | &c)) | ||
221 | || (0 != strcmp (c, "/var/lib/gnunet/"))) | ||
222 | { | ||
223 | GNUNET_CONFIGURATION_destroy (cfg); | ||
224 | return 1; | ||
225 | } | ||
226 | GNUNET_free (c); | ||
227 | GNUNET_CONFIGURATION_destroy (cfg); | ||
228 | if (failureCount != 0) | ||
229 | { | ||
230 | fprintf (stderr, "Test failed: %u\n", failureCount); | ||
231 | return 1; | ||
232 | } | ||
233 | return 0; | 252 | return 0; |
234 | } | 253 | } |