diff options
Diffstat (limited to 'src/lib/util/test_program.c')
-rw-r--r-- | src/lib/util/test_program.c | 139 |
1 files changed, 139 insertions, 0 deletions
diff --git a/src/lib/util/test_program.c b/src/lib/util/test_program.c new file mode 100644 index 000000000..3d63b0336 --- /dev/null +++ b/src/lib/util/test_program.c | |||
@@ -0,0 +1,139 @@ | |||
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 Affero 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 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | /** | ||
21 | * @file util/test_program.c | ||
22 | * @brief tests for program.c | ||
23 | */ | ||
24 | |||
25 | #include "platform.h" | ||
26 | #include "gnunet_util_lib.h" | ||
27 | |||
28 | |||
29 | static int setme1; | ||
30 | |||
31 | static int setme2; | ||
32 | |||
33 | |||
34 | /** | ||
35 | * Main function that will be run. | ||
36 | */ | ||
37 | static void | ||
38 | runner (void *cls, | ||
39 | char *const *args, | ||
40 | const char *cfgfile, | ||
41 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
42 | { | ||
43 | int *ok = cls; | ||
44 | |||
45 | GNUNET_assert (setme1 == 1); | ||
46 | GNUNET_assert (0 == strcmp (args[0], "extra")); | ||
47 | GNUNET_assert (args[1] == NULL); | ||
48 | GNUNET_assert (NULL != strstr (cfgfile, "/test_program_data.conf")); | ||
49 | *ok = 0; | ||
50 | } | ||
51 | |||
52 | |||
53 | int | ||
54 | main (int argc, char *argv[]) | ||
55 | { | ||
56 | int ok = 1; | ||
57 | char *const argvx[] = { | ||
58 | "test_program", | ||
59 | "-c", | ||
60 | "test_program_data.conf", | ||
61 | "-L", | ||
62 | "WARNING", | ||
63 | "-n", | ||
64 | "extra", | ||
65 | NULL | ||
66 | }; | ||
67 | struct GNUNET_GETOPT_CommandLineOption options1[] = { | ||
68 | GNUNET_GETOPT_option_flag ('n', | ||
69 | "name", | ||
70 | "description", | ||
71 | &setme1), | ||
72 | GNUNET_GETOPT_OPTION_END | ||
73 | }; | ||
74 | struct GNUNET_GETOPT_CommandLineOption options2[] = { | ||
75 | GNUNET_GETOPT_option_flag ('n', | ||
76 | "name", | ||
77 | "description", | ||
78 | &setme1), | ||
79 | GNUNET_GETOPT_option_flag ('N', | ||
80 | "number", | ||
81 | "description", | ||
82 | &setme2), | ||
83 | GNUNET_GETOPT_OPTION_END | ||
84 | }; | ||
85 | struct GNUNET_GETOPT_CommandLineOption options3[] = { | ||
86 | GNUNET_GETOPT_option_flag ('N', | ||
87 | "number", | ||
88 | "description", | ||
89 | &setme1), | ||
90 | GNUNET_GETOPT_option_flag ('n', | ||
91 | "name", | ||
92 | "description", | ||
93 | &setme2), | ||
94 | GNUNET_GETOPT_OPTION_END | ||
95 | }; | ||
96 | struct GNUNET_GETOPT_CommandLineOption options4[] = { | ||
97 | GNUNET_GETOPT_option_flag ('n', | ||
98 | "name", | ||
99 | "description", | ||
100 | &setme1), | ||
101 | GNUNET_GETOPT_option_flag ('n', | ||
102 | "name", | ||
103 | "description", | ||
104 | &setme2), | ||
105 | GNUNET_GETOPT_OPTION_END | ||
106 | }; | ||
107 | |||
108 | |||
109 | GNUNET_log_setup ("test_program", | ||
110 | "WARNING", | ||
111 | NULL); | ||
112 | GNUNET_assert (GNUNET_OK == | ||
113 | GNUNET_PROGRAM_run (7, argvx, | ||
114 | "test_program", | ||
115 | "A test", | ||
116 | options1, | ||
117 | &runner, &ok)); | ||
118 | |||
119 | GNUNET_assert (GNUNET_OK == | ||
120 | GNUNET_PROGRAM_run (7, argvx, | ||
121 | "test_program", "A test", | ||
122 | options2, | ||
123 | &runner, &ok)); | ||
124 | GNUNET_assert (GNUNET_OK == | ||
125 | GNUNET_PROGRAM_run (7, argvx, | ||
126 | "test_program", "A test", | ||
127 | options3, | ||
128 | &runner, &ok)); | ||
129 | GNUNET_assert (GNUNET_OK == | ||
130 | GNUNET_PROGRAM_run (7, argvx, | ||
131 | "test_program", "A test", | ||
132 | options4, | ||
133 | &runner, &ok)); | ||
134 | |||
135 | return ok; | ||
136 | } | ||
137 | |||
138 | |||
139 | /* end of test_program.c */ | ||