fix build issues
[oweals/gnunet.git] / src / util / test_program.c
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2009 GNUnet e.V.
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., 51 Franklin Street, Fifth Floor,
18      Boston, MA 02110-1301, USA.
19 */
20 /**
21  * @file util/test_program.c
22  * @brief tests for program.c
23  */
24 #include "platform.h"
25 #include "gnunet_util_lib.h"
26
27 static int setme1, setme2;
28
29 static struct GNUNET_GETOPT_CommandLineOption options1[] = {
30   {'n', "name", NULL, "description", 0, &GNUNET_GETOPT_set_one, &setme1},
31   GNUNET_GETOPT_OPTION_END
32 };
33
34 static struct GNUNET_GETOPT_CommandLineOption options2[] = {
35   {'n', "name", NULL, "description", 0, &GNUNET_GETOPT_set_one, &setme1},
36   {'N', "number", NULL, "description", 0, &GNUNET_GETOPT_set_one, &setme2},
37   GNUNET_GETOPT_OPTION_END
38 };
39
40 static struct GNUNET_GETOPT_CommandLineOption options3[] = {
41   {'N', "number", NULL, "description", 0, &GNUNET_GETOPT_set_one, &setme1},
42   {'n', "name", NULL, "description", 0, &GNUNET_GETOPT_set_one, &setme2},
43   GNUNET_GETOPT_OPTION_END
44 };
45
46 static struct GNUNET_GETOPT_CommandLineOption options4[] = {
47   {'n', "name", NULL, "description", 0, &GNUNET_GETOPT_set_one, &setme1},
48   {'n', "number", NULL, "description", 0, &GNUNET_GETOPT_set_one, &setme2},
49   GNUNET_GETOPT_OPTION_END
50 };
51
52 /**
53  * Main function that will be run.
54  */
55
56 static void
57 runner (void *cls, char *const *args, const char *cfgfile,
58         const struct GNUNET_CONFIGURATION_Handle *cfg)
59 {
60   int *ok = cls;
61
62   GNUNET_assert (setme1 == 1);
63   GNUNET_assert (0 == strcmp (args[0], "extra"));
64   GNUNET_assert (args[1] == NULL);
65   GNUNET_assert (0 == strcmp (cfgfile, "test_program_data.conf"));
66
67   *ok = 0;
68 }
69
70 /**
71  * Main method, starts scheduler with task1,
72  * checks that "ok" is correct at the end.
73  */
74 static int
75 check ()
76 {
77   int ok = 1;
78
79   char *const argv[] = {
80     "test_program",
81     "-c",
82     "test_program_data.conf",
83     "-L",
84     "WARNING",
85     "-n",
86     "extra",
87     NULL
88   };
89
90   GNUNET_assert (GNUNET_OK ==
91                  GNUNET_PROGRAM_run (7, argv, "test_program", "A test",
92                                      options1, &runner, &ok));
93
94   GNUNET_assert (GNUNET_OK ==
95                  GNUNET_PROGRAM_run (7, argv, "test_program", "A test",
96                                      options2, &runner, &ok));
97   GNUNET_assert (GNUNET_OK ==
98                  GNUNET_PROGRAM_run (7, argv, "test_program", "A test",
99                                      options3, &runner, &ok));
100   GNUNET_assert (GNUNET_OK ==
101                  GNUNET_PROGRAM_run (7, argv, "test_program", "A test",
102                                      options4, &runner, &ok));
103
104   return ok;
105 }
106
107 int
108 main (int argc, char *argv[])
109 {
110   int ret = 0;
111
112   GNUNET_log_setup ("test_program", "WARNING", NULL);
113   ret += check ();
114
115   return ret;
116 }
117
118 /* end of test_program.c */