b3db43d1092c605c4727b000c639450630acc47b
[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 it
6      under the terms of the GNU General Public License as published
7      by the Free Software Foundation, either version 3 of the License,
8      or (at your 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      Affero General Public License for more details.
14 */
15 /**
16  * @file util/test_program.c
17  * @brief tests for program.c
18  */
19 #include "platform.h"
20 #include "gnunet_util_lib.h"
21
22
23 static int setme1;
24
25 static int setme2;
26
27
28 /**
29  * Main function that will be run.
30  */
31 static void
32 runner (void *cls,
33         char *const *args,
34         const char *cfgfile,
35         const struct GNUNET_CONFIGURATION_Handle *cfg)
36 {
37   int *ok = cls;
38
39   GNUNET_assert (setme1 == 1);
40   GNUNET_assert (0 == strcmp (args[0], "extra"));
41   GNUNET_assert (args[1] == NULL);
42   GNUNET_assert (NULL != strstr (cfgfile, "/test_program_data.conf"));
43   *ok = 0;
44 }
45
46
47 int
48 main (int argc, char *argv[])
49 {
50   int ok = 1;
51   char *const argvx[] = {
52     "test_program",
53     "-c",
54     "test_program_data.conf",
55     "-L",
56     "WARNING",
57     "-n",
58     "extra",
59     NULL
60   };
61   struct GNUNET_GETOPT_CommandLineOption options1[] = {
62     GNUNET_GETOPT_option_flag ('n',
63                                   "name",
64                                   "description",
65                                   &setme1),
66     GNUNET_GETOPT_OPTION_END
67   };
68   struct GNUNET_GETOPT_CommandLineOption options2[] = {
69     GNUNET_GETOPT_option_flag ('n',
70                                   "name",
71                                   "description",
72                                   &setme1),
73     GNUNET_GETOPT_option_flag ('N',
74                                   "number",
75                                   "description",
76                                   &setme2),
77     GNUNET_GETOPT_OPTION_END
78   };
79   struct GNUNET_GETOPT_CommandLineOption options3[] = {
80     GNUNET_GETOPT_option_flag ('N',
81                                   "number",
82                                   "description",
83                                   &setme1),
84     GNUNET_GETOPT_option_flag ('n',
85                                   "name",
86                                   "description",
87                                   &setme2),
88     GNUNET_GETOPT_OPTION_END
89   };
90   struct GNUNET_GETOPT_CommandLineOption options4[] = {
91     GNUNET_GETOPT_option_flag ('n',
92                                   "name",
93                                   "description",
94                                   &setme1),
95     GNUNET_GETOPT_option_flag ('n',
96                                   "name",
97                                   "description",
98                                   &setme2),
99     GNUNET_GETOPT_OPTION_END
100   };
101
102
103   GNUNET_log_setup ("test_program",
104                     "WARNING",
105                     NULL);
106   GNUNET_assert (GNUNET_OK ==
107                  GNUNET_PROGRAM_run (7, argvx,
108                                      "test_program",
109                                      "A test",
110                                      options1,
111                                      &runner, &ok));
112
113   GNUNET_assert (GNUNET_OK ==
114                  GNUNET_PROGRAM_run (7, argvx,
115                                      "test_program", "A test",
116                                      options2,
117                                      &runner, &ok));
118   GNUNET_assert (GNUNET_OK ==
119                  GNUNET_PROGRAM_run (7, argvx,
120                                      "test_program", "A test",
121                                      options3,
122                                      &runner, &ok));
123   GNUNET_assert (GNUNET_OK ==
124                  GNUNET_PROGRAM_run (7, argvx,
125                                      "test_program", "A test",
126                                      options4,
127                                      &runner, &ok));
128
129   return ok;
130 }
131
132 /* end of test_program.c */