Merge branch 'master' of ssh://gnunet.org/gnunet
[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
28 static int setme1;
29
30 static int setme2;
31
32
33 /**
34  * Main function that will be run.
35  */
36 static void
37 runner (void *cls,
38         char *const *args,
39         const char *cfgfile,
40         const struct GNUNET_CONFIGURATION_Handle *cfg)
41 {
42   int *ok = cls;
43
44   GNUNET_assert (setme1 == 1);
45   GNUNET_assert (0 == strcmp (args[0], "extra"));
46   GNUNET_assert (args[1] == NULL);
47   GNUNET_assert (NULL != strstr (cfgfile, "/test_program_data.conf"));
48   *ok = 0;
49 }
50
51
52 int
53 main (int argc, char *argv[])
54 {
55   int ok = 1;
56   char *const argvx[] = {
57     "test_program",
58     "-c",
59     "test_program_data.conf",
60     "-L",
61     "WARNING",
62     "-n",
63     "extra",
64     NULL
65   };
66   struct GNUNET_GETOPT_CommandLineOption options1[] = {
67     GNUNET_GETOPT_OPTION_SET_ONE ('n',
68                                   "name",
69                                   "description",
70                                   &setme1),
71     GNUNET_GETOPT_OPTION_END
72   };
73   struct GNUNET_GETOPT_CommandLineOption options2[] = {
74     GNUNET_GETOPT_OPTION_SET_ONE ('n',
75                                   "name",
76                                   "description",
77                                   &setme1),
78     GNUNET_GETOPT_OPTION_SET_ONE ('N',
79                                   "number",
80                                   "description",
81                                   &setme2),
82     GNUNET_GETOPT_OPTION_END
83   };
84   struct GNUNET_GETOPT_CommandLineOption options3[] = {
85     GNUNET_GETOPT_OPTION_SET_ONE ('N',
86                                   "number",
87                                   "description",
88                                   &setme1),
89     GNUNET_GETOPT_OPTION_SET_ONE ('n',
90                                   "name",
91                                   "description",
92                                   &setme2),
93     GNUNET_GETOPT_OPTION_END
94   };
95   struct GNUNET_GETOPT_CommandLineOption options4[] = {
96     GNUNET_GETOPT_OPTION_SET_ONE ('n',
97                                   "name",
98                                   "description",
99                                   &setme1),
100     GNUNET_GETOPT_OPTION_SET_ONE ('n',
101                                   "name",
102                                   "description",
103                                   &setme2),
104     GNUNET_GETOPT_OPTION_END
105   };
106
107
108   GNUNET_log_setup ("test_program",
109                     "WARNING",
110                     NULL);
111   GNUNET_assert (GNUNET_OK ==
112                  GNUNET_PROGRAM_run (7, argvx,
113                                      "test_program",
114                                      "A test",
115                                      options1,
116                                      &runner, &ok));
117
118   GNUNET_assert (GNUNET_OK ==
119                  GNUNET_PROGRAM_run (7, argvx,
120                                      "test_program", "A test",
121                                      options2,
122                                      &runner, &ok));
123   GNUNET_assert (GNUNET_OK ==
124                  GNUNET_PROGRAM_run (7, argvx,
125                                      "test_program", "A test",
126                                      options3,
127                                      &runner, &ok));
128   GNUNET_assert (GNUNET_OK ==
129                  GNUNET_PROGRAM_run (7, argvx,
130                                      "test_program", "A test",
131                                      options4,
132                                      &runner, &ok));
133
134   return ok;
135 }
136
137 /* end of test_program.c */