rps.conf is generated from rps.conf.in
[oweals/gnunet.git] / src / util / test_getopt.c
index 89e7be863fe97f0985a15ece2fb9448e1418e4a3..8e578640dd9b3b226b917f266a0e82ba17416999 100644 (file)
@@ -1,10 +1,10 @@
 /*
      This file is part of GNUnet.
 /*
      This file is part of GNUnet.
-     (C) 2003, 2004, 2005, 2006, 2009 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2003, 2004, 2005, 2006, 2009 GNUnet e.V.
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
-     by the Free Software Foundation; either version 2, or (at your
+     by the Free Software Foundation; either version 3, or (at your
      option) any later version.
 
      GNUnet is distributed in the hope that it will be useful, but
      option) any later version.
 
      GNUnet is distributed in the hope that it will be useful, but
 
      You should have received a copy of the GNU General Public License
      along with GNUnet; see the file COPYING.  If not, write to the
 
      You should have received a copy of the GNU General Public License
      along with GNUnet; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-     Boston, MA 02111-1307, USA.
+     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+     Boston, MA 02110-1301, USA.
 */
 /**
  * @file util/test_getopt.c
  * @brief testcase for util/getopt.c
  */
 #include "platform.h"
 */
 /**
  * @file util/test_getopt.c
  * @brief testcase for util/getopt.c
  */
 #include "platform.h"
-#include "gnunet_common.h"
-#include "gnunet_configuration_lib.h"
-#include "gnunet_getopt_lib.h"
+#include "gnunet_util_lib.h"
 
 
-#define VERBOSE 0
 
 static int
 testMinimal ()
 {
 
 static int
 testMinimal ()
 {
-  struct GNUNET_CONFIGURATION_Handle *cfg;
   char *const emptyargv[] = {
     "test",
     NULL
   char *const emptyargv[] = {
     "test",
     NULL
@@ -40,21 +36,16 @@ testMinimal ()
     GNUNET_GETOPT_OPTION_END
   };
 
     GNUNET_GETOPT_OPTION_END
   };
 
-  cfg = GNUNET_CONFIGURATION_create ();
-  if (1 != GNUNET_GETOPT_run ("test", cfg, emptyoptionlist, 1, emptyargv))
-    {
-      GNUNET_CONFIGURATION_destroy (cfg);
-      return 1;
-    }
-  GNUNET_CONFIGURATION_destroy (cfg);
+  if (1 != GNUNET_GETOPT_run ("test", emptyoptionlist, 1, emptyargv))
+    return 1;
 
   return 0;
 }
 
 
   return 0;
 }
 
+
 static int
 testVerbose ()
 {
 static int
 testVerbose ()
 {
-  struct GNUNET_CONFIGURATION_Handle *cfg;
   char *const myargv[] = {
     "test",
     "-V",
   char *const myargv[] = {
     "test",
     "-V",
@@ -63,57 +54,51 @@ testVerbose ()
     NULL
   };
   unsigned int vflags = 0;
     NULL
   };
   unsigned int vflags = 0;
+
   const struct GNUNET_GETOPT_CommandLineOption verboseoptionlist[] = {
     GNUNET_GETOPT_OPTION_VERBOSE (&vflags),
     GNUNET_GETOPT_OPTION_END
   };
 
   const struct GNUNET_GETOPT_CommandLineOption verboseoptionlist[] = {
     GNUNET_GETOPT_OPTION_VERBOSE (&vflags),
     GNUNET_GETOPT_OPTION_END
   };
 
-  cfg = GNUNET_CONFIGURATION_create ();
-  if (3 != GNUNET_GETOPT_run ("test", cfg, verboseoptionlist, 4, myargv))
-    {
-      GNUNET_break (0);
-      GNUNET_CONFIGURATION_destroy (cfg);
-      return 1;
-    }
-  GNUNET_CONFIGURATION_destroy (cfg);
+  if (3 != GNUNET_GETOPT_run ("test", verboseoptionlist, 4, myargv))
+  {
+    GNUNET_break (0);
+    return 1;
+  }
   if (vflags != 2)
   if (vflags != 2)
-    {
-      GNUNET_break (0);
-      return 1;
-    }
+  {
+    GNUNET_break (0);
+    return 1;
+  }
   return 0;
 }
 
   return 0;
 }
 
+
 static int
 testVersion ()
 {
 static int
 testVersion ()
 {
-  struct GNUNET_CONFIGURATION_Handle *cfg;
   char *const myargv[] = {
     "test_getopt",
     "-v",
     NULL
   };
   const struct GNUNET_GETOPT_CommandLineOption versionoptionlist[] = {
   char *const myargv[] = {
     "test_getopt",
     "-v",
     NULL
   };
   const struct GNUNET_GETOPT_CommandLineOption versionoptionlist[] = {
-    GNUNET_GETOPT_OPTION_VERSION (PACKAGE_VERSION),
+    GNUNET_GETOPT_OPTION_VERSION (PACKAGE_VERSION " " VCS_VERSION),
     GNUNET_GETOPT_OPTION_END
   };
 
     GNUNET_GETOPT_OPTION_END
   };
 
-  cfg = GNUNET_CONFIGURATION_create ();
-  if (-1 != GNUNET_GETOPT_run ("test_getopt",
-                               cfg, versionoptionlist, 2, myargv))
-    {
-      GNUNET_break (0);
-      GNUNET_CONFIGURATION_destroy (cfg);
-      return 1;
-    }
-  GNUNET_CONFIGURATION_destroy (cfg);
+  if (0 != GNUNET_GETOPT_run ("test_getopt", versionoptionlist, 2, myargv))
+  {
+    GNUNET_break (0);
+    return 1;
+  }
   return 0;
 }
 
   return 0;
 }
 
+
 static int
 testAbout ()
 {
 static int
 testAbout ()
 {
-  struct GNUNET_CONFIGURATION_Handle *cfg;
   char *const myargv[] = {
     "test_getopt",
     "-h",
   char *const myargv[] = {
     "test_getopt",
     "-h",
@@ -124,22 +109,18 @@ testAbout ()
     GNUNET_GETOPT_OPTION_END
   };
 
     GNUNET_GETOPT_OPTION_END
   };
 
-  cfg = GNUNET_CONFIGURATION_create ();
-  if (-1 != GNUNET_GETOPT_run ("test_getopt",
-                               cfg, aboutoptionlist, 2, myargv))
-    {
-      GNUNET_break (0);
-      GNUNET_CONFIGURATION_destroy (cfg);
-      return 1;
-    }
-  GNUNET_CONFIGURATION_destroy (cfg);
+  if (0 != GNUNET_GETOPT_run ("test_getopt", aboutoptionlist, 2, myargv))
+  {
+    GNUNET_break (0);
+    return 1;
+  }
   return 0;
 }
 
   return 0;
 }
 
+
 static int
 testLogOpts ()
 {
 static int
 testLogOpts ()
 {
-  struct GNUNET_CONFIGURATION_Handle *cfg;
   char *const myargv[] = {
     "test_getopt",
     "-l", "filename",
   char *const myargv[] = {
     "test_getopt",
     "-l", "filename",
@@ -148,37 +129,35 @@ testLogOpts ()
   };
   char *level = GNUNET_strdup ("stuff");
   char *fn = NULL;
   };
   char *level = GNUNET_strdup ("stuff");
   char *fn = NULL;
+
   const struct GNUNET_GETOPT_CommandLineOption logoptionlist[] = {
     GNUNET_GETOPT_OPTION_LOGFILE (&fn),
     GNUNET_GETOPT_OPTION_LOGLEVEL (&level),
     GNUNET_GETOPT_OPTION_END
   };
 
   const struct GNUNET_GETOPT_CommandLineOption logoptionlist[] = {
     GNUNET_GETOPT_OPTION_LOGFILE (&fn),
     GNUNET_GETOPT_OPTION_LOGLEVEL (&level),
     GNUNET_GETOPT_OPTION_END
   };
 
-  cfg = GNUNET_CONFIGURATION_create ();
-  if (5 != GNUNET_GETOPT_run ("test_getopt", cfg, logoptionlist, 5, myargv))
-    {
-      GNUNET_break (0);
-      GNUNET_CONFIGURATION_destroy (cfg);
-      return 1;
-    }
+  if (5 != GNUNET_GETOPT_run ("test_getopt", logoptionlist, 5, myargv))
+  {
+    GNUNET_break (0);
+    return 1;
+  }
   GNUNET_assert (fn != NULL);
   GNUNET_assert (fn != NULL);
-  GNUNET_CONFIGURATION_destroy (cfg);
   if ((0 != strcmp (level, "WARNING")) || (0 != strcmp (fn, "filename")))
   if ((0 != strcmp (level, "WARNING")) || (0 != strcmp (fn, "filename")))
-    {
-      GNUNET_break (0);
-      GNUNET_free (level);
-      GNUNET_free (fn);
-      return 1;
-    }
+  {
+    GNUNET_break (0);
+    GNUNET_free (level);
+    GNUNET_free (fn);
+    return 1;
+  }
   GNUNET_free (level);
   GNUNET_free (fn);
   return 0;
 }
 
   GNUNET_free (level);
   GNUNET_free (fn);
   return 0;
 }
 
+
 static int
 testFlagNum ()
 {
 static int
 testFlagNum ()
 {
-  struct GNUNET_CONFIGURATION_Handle *cfg;
   char *const myargv[] = {
     "test_getopt",
     "-f",
   char *const myargv[] = {
     "test_getopt",
     "-f",
@@ -189,6 +168,7 @@ testFlagNum ()
   int flag = 0;
   unsigned int num = 0;
   unsigned long long lnum = 0;
   int flag = 0;
   unsigned int num = 0;
   unsigned long long lnum = 0;
+
   const struct GNUNET_GETOPT_CommandLineOption logoptionlist[] = {
     {'f', "--flag", NULL, "helptext", 0, &GNUNET_GETOPT_set_one,
      (void *) &flag},
   const struct GNUNET_GETOPT_CommandLineOption logoptionlist[] = {
     {'f', "--flag", NULL, "helptext", 0, &GNUNET_GETOPT_set_one,
      (void *) &flag},
@@ -199,22 +179,20 @@ testFlagNum ()
     GNUNET_GETOPT_OPTION_END
   };
 
     GNUNET_GETOPT_OPTION_END
   };
 
-  cfg = GNUNET_CONFIGURATION_create ();
-  if (6 != GNUNET_GETOPT_run ("test_getopt", cfg, logoptionlist, 6, myargv))
-    {
-      GNUNET_break (0);
-      GNUNET_CONFIGURATION_destroy (cfg);
-      return 1;
-    }
-  GNUNET_CONFIGURATION_destroy (cfg);
+  if (6 != GNUNET_GETOPT_run ("test_getopt", logoptionlist, 6, myargv))
+  {
+    GNUNET_break (0);
+    return 1;
+  }
   if ((1 != flag) || (42 != num) || (42 != lnum))
   if ((1 != flag) || (42 != num) || (42 != lnum))
-    {
-      GNUNET_break (0);
-      return 1;
-    }
+  {
+    GNUNET_break (0);
+    return 1;
+  }
   return 0;
 }
 
   return 0;
 }
 
+
 int
 main (int argc, char *argv[])
 {
 int
 main (int argc, char *argv[])
 {
@@ -222,7 +200,9 @@ main (int argc, char *argv[])
 
   GNUNET_log_setup ("test_getopt", "WARNING", NULL);
   /* suppress output from -h, -v options */
 
   GNUNET_log_setup ("test_getopt", "WARNING", NULL);
   /* suppress output from -h, -v options */
+#ifndef MINGW
   GNUNET_break (0 == CLOSE (1));
   GNUNET_break (0 == CLOSE (1));
+#endif
   if (0 != testMinimal ())
     errCnt++;
   if (0 != testVerbose ())
   if (0 != testMinimal ())
     errCnt++;
   if (0 != testVerbose ())