-dead
[oweals/gnunet.git] / src / util / test_configuration.c
index 8bad5b5d4b8e43b2d704c8444471d62b9d31594b..62ad5fa92fc3a4a267b834b719d9307675fad1bc 100644 (file)
@@ -28,7 +28,6 @@
 #include "gnunet_configuration_lib.h"
 #include "gnunet_disk_lib.h"
 
-#define DEBUG GNUNET_NO
 
 /* Test Configuration Diffs Options */
 enum
@@ -40,10 +39,8 @@ enum
   ADD_NEW_ENTRY,
   REMOVE_SECTION,
   REMOVE_ENTRY,
-  COMPARE
-#if DEBUG
-      , PRINT
-#endif
+  COMPARE, 
+  PRINT
 };
 
 static struct GNUNET_CONFIGURATION_Handle *cfg;
@@ -75,8 +72,8 @@ initDiffsCBData (struct DiffsCBData *cbData)
  * and comparing configuration
 */
 static void
-diffsCallBack (void *cls,
-               const char *section, const char *option, const char *value)
+diffsCallBack (void *cls, const char *section, const char *option,
+               const char *value)
 {
   struct DiffsCBData *cbData = cls;
   int cbOption = cbData->callBackOption;
@@ -90,15 +87,15 @@ diffsCallBack (void *cls,
     {
       GNUNET_CONFIGURATION_set_value_string (cbData->cfg, section, option,
                                              "new-value");
-      GNUNET_CONFIGURATION_set_value_string (cbData->cfgDiffs, section,
-                                             option, "new-value");
+      GNUNET_CONFIGURATION_set_value_string (cbData->cfgDiffs, section, option,
+                                             "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");
+    GNUNET_CONFIGURATION_set_value_string (cbData->cfgDiffs, section, option,
+                                           "new-value");
     break;
   case ADD_NEW_ENTRY:
   {
@@ -107,8 +104,8 @@ diffsCallBack (void *cls,
     if (hit == 0)
     {
       hit = 1;
-      GNUNET_CONFIGURATION_set_value_string (cbData->cfg, section,
-                                             "new-key", "new-value");
+      GNUNET_CONFIGURATION_set_value_string (cbData->cfg, section, "new-key",
+                                             "new-value");
       GNUNET_CONFIGURATION_set_value_string (cbData->cfgDiffs, section,
                                              "new-key", "new-value");
     }
@@ -133,7 +130,7 @@ diffsCallBack (void *cls,
     GNUNET_free_non_null (diffValue);
     break;
   }
-#if DEBUG
+#if 0
   case PRINT:
     if (NULL == cbData->section)
     {
@@ -183,8 +180,8 @@ editConfiguration (struct GNUNET_CONFIGURATION_Handle *cfg, int option)
       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_CONFIGURATION_set_value_string (diffsCB.cfgDiffs, "new-section",
+                                             key, "new-value");
       GNUNET_free (key);
     }
     break;
@@ -234,24 +231,25 @@ checkDiffs (struct GNUNET_CONFIGURATION_Handle *cfgDefault, int option)
   /* 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,13 +275,13 @@ 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;
   }
   GNUNET_free (c);
-  if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg,
-                                                          "test", "five", &l))
+  if (GNUNET_OK !=
+      GNUNET_CONFIGURATION_get_value_number (cfg, "test", "five", &l))
   {
     GNUNET_break (0);
     return 3;
@@ -333,6 +331,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;
 }
 
@@ -364,9 +373,9 @@ testConfigFilenames ()
   int idx;
 
   idx = 0;
-  if (3 != GNUNET_CONFIGURATION_iterate_value_filenames (cfg,
-                                                         "FILENAMES",
-                                                         "test", &check, &idx))
+  if (3 !=
+      GNUNET_CONFIGURATION_iterate_value_filenames (cfg, "FILENAMES", "test",
+                                                    &check, &idx))
   {
     GNUNET_break (0);
     return 8;
@@ -374,60 +383,54 @@ testConfigFilenames ()
   if (idx != 3)
     return 16;
   if (GNUNET_OK !=
-      GNUNET_CONFIGURATION_remove_value_filename (cfg,
-                                                  "FILENAMES",
-                                                  "test", "/File Name"))
+      GNUNET_CONFIGURATION_remove_value_filename (cfg, "FILENAMES", "test",
+                                                  "/File Name"))
   {
     GNUNET_break (0);
     return 24;
   }
 
   if (GNUNET_NO !=
-      GNUNET_CONFIGURATION_remove_value_filename (cfg,
-                                                  "FILENAMES",
-                                                  "test", "/File Name"))
+      GNUNET_CONFIGURATION_remove_value_filename (cfg, "FILENAMES", "test",
+                                                  "/File Name"))
   {
     GNUNET_break (0);
     return 32;
   }
   if (GNUNET_NO !=
-      GNUNET_CONFIGURATION_remove_value_filename (cfg,
-                                                  "FILENAMES", "test", "Stuff"))
+      GNUNET_CONFIGURATION_remove_value_filename (cfg, "FILENAMES", "test",
+                                                  "Stuff"))
   {
     GNUNET_break (0);
     return 40;
   }
 
   if (GNUNET_NO !=
-      GNUNET_CONFIGURATION_append_value_filename (cfg,
-                                                  "FILENAMES",
-                                                  "test", "/Hello"))
+      GNUNET_CONFIGURATION_append_value_filename (cfg, "FILENAMES", "test",
+                                                  "/Hello"))
   {
     GNUNET_break (0);
     return 48;
   }
   if (GNUNET_NO !=
-      GNUNET_CONFIGURATION_append_value_filename (cfg,
-                                                  "FILENAMES",
-                                                  "test", "/World"))
+      GNUNET_CONFIGURATION_append_value_filename (cfg, "FILENAMES", "test",
+                                                  "/World"))
   {
     GNUNET_break (0);
     return 56;
   }
 
   if (GNUNET_YES !=
-      GNUNET_CONFIGURATION_append_value_filename (cfg,
-                                                  "FILENAMES",
-                                                  "test", "/File 1"))
+      GNUNET_CONFIGURATION_append_value_filename (cfg, "FILENAMES", "test",
+                                                  "/File 1"))
   {
     GNUNET_break (0);
     return 64;
   }
 
   if (GNUNET_YES !=
-      GNUNET_CONFIGURATION_append_value_filename (cfg,
-                                                  "FILENAMES",
-                                                  "test", "/File 2"))
+      GNUNET_CONFIGURATION_append_value_filename (cfg, "FILENAMES", "test",
+                                                  "/File 2"))
   {
     GNUNET_break (0);
     return 72;
@@ -437,9 +440,9 @@ testConfigFilenames ()
   want[1] = "/World";
   want[2] = "/File 1";
   want[3] = "/File 2";
-  if (4 != GNUNET_CONFIGURATION_iterate_value_filenames (cfg,
-                                                         "FILENAMES",
-                                                         "test", &check, &idx))
+  if (4 !=
+      GNUNET_CONFIGURATION_iterate_value_filenames (cfg, "FILENAMES", "test",
+                                                    &check, &idx))
   {
     GNUNET_break (0);
     return 80;
@@ -465,7 +468,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;
   }
@@ -479,7 +482,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;
   }
@@ -541,7 +544,7 @@ main (int argc, char *argv[])
 error:
   if (failureCount != 0)
   {
-    fprintf (stderr, "Test failed: %u\n", failureCount);
+    FPRINTF (stderr, "Test failed: %u\n", failureCount);
     return 1;
   }
   return 0;