-remove async ecc key generation, not needed
[oweals/gnunet.git] / src / util / test_program.c
1 /*
2      This file is part of GNUnet.
3      (C) 2009 Christian Grothoff (and other contributing authors)
4
5      GNUnet is free software; you can redistribute it and/or modify
6      it under the terms of the GNU General Public License as published
7      by the Free Software Foundation; either version 3, or (at your
8      option) any later version.
9
10      GNUnet is distributed in the hope that it will be useful, but
11      WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13      General Public License for more details.
14
15      You should have received a copy of the GNU General Public License
16      along with GNUnet; see the file COPYING.  If not, write to the
17      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18      Boston, MA 02111-1307, USA.
19 */
20 /**
21  * @file util/test_program.c
22  * @brief tests for program.c
23  */
24 #include "platform.h"
25 #include "gnunet_common.h"
26 #include "gnunet_program_lib.h"
27 #include "gnunet_scheduler_lib.h"
28 #include "gnunet_time_lib.h"
29
30 static int setme1, setme2;
31
32 static struct GNUNET_GETOPT_CommandLineOption options1[] = {
33   {'n', "name", NULL, "description", 0, &GNUNET_GETOPT_set_one, &setme1},
34   GNUNET_GETOPT_OPTION_END
35 };
36
37 static struct GNUNET_GETOPT_CommandLineOption options2[] = {
38   {'n', "name", NULL, "description", 0, &GNUNET_GETOPT_set_one, &setme1},
39   {'N', "number", NULL, "description", 0, &GNUNET_GETOPT_set_one, &setme2},
40   GNUNET_GETOPT_OPTION_END
41 };
42
43 static struct GNUNET_GETOPT_CommandLineOption options3[] = {
44   {'N', "number", NULL, "description", 0, &GNUNET_GETOPT_set_one, &setme1},
45   {'n', "name", NULL, "description", 0, &GNUNET_GETOPT_set_one, &setme2},
46   GNUNET_GETOPT_OPTION_END
47 };
48
49 static struct GNUNET_GETOPT_CommandLineOption options4[] = {
50   {'n', "name", NULL, "description", 0, &GNUNET_GETOPT_set_one, &setme1},
51   {'n', "number", NULL, "description", 0, &GNUNET_GETOPT_set_one, &setme2},
52   GNUNET_GETOPT_OPTION_END
53 };
54
55 /**
56  * Main function that will be run.
57  */
58
59 static void
60 runner (void *cls, char *const *args, const char *cfgfile,
61         const struct GNUNET_CONFIGURATION_Handle *cfg)
62 {
63   int *ok = cls;
64
65   GNUNET_assert (setme1 == 1);
66   GNUNET_assert (0 == strcmp (args[0], "extra"));
67   GNUNET_assert (args[1] == NULL);
68   GNUNET_assert (0 == strcmp (cfgfile, "test_program_data.conf"));
69
70   *ok = 0;
71 }
72
73 /**
74  * Main method, starts scheduler with task1,
75  * checks that "ok" is correct at the end.
76  */
77 static int
78 check ()
79 {
80   int ok = 1;
81
82   char *const argv[] = {
83     "test_program",
84     "-c",
85     "test_program_data.conf",
86     "-L",
87     "WARNING",
88     "-n",
89     "extra",
90     NULL
91   };
92
93   GNUNET_assert (GNUNET_OK ==
94                  GNUNET_PROGRAM_run (7, argv, "test_program", "A test",
95                                      options1, &runner, &ok));
96
97   GNUNET_assert (GNUNET_OK ==
98                  GNUNET_PROGRAM_run (7, argv, "test_program", "A test",
99                                      options2, &runner, &ok));
100   GNUNET_assert (GNUNET_OK ==
101                  GNUNET_PROGRAM_run (7, argv, "test_program", "A test",
102                                      options3, &runner, &ok));
103   GNUNET_assert (GNUNET_OK ==
104                  GNUNET_PROGRAM_run (7, argv, "test_program", "A test",
105                                      options4, &runner, &ok));
106
107   return ok;
108 }
109
110 int
111 main (int argc, char *argv[])
112 {
113   int ret = 0;
114
115   GNUNET_log_setup ("test_program", "WARNING", NULL);
116   ret += check ();
117
118   return ret;
119 }
120
121 /* end of test_program.c */