2 This file is part of GNUnet.
3 Copyright (C) 2003, 2004, 2005, 2006, 2009 GNUnet e.V.
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.
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.
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/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
21 * @file util/test_getopt.c
22 * @brief testcase for util/getopt.c
25 #include "gnunet_util_lib.h"
31 char *const emptyargv[] = {
35 const struct GNUNET_GETOPT_CommandLineOption emptyoptionlist[] = {
36 GNUNET_GETOPT_OPTION_END
39 if (1 != GNUNET_GETOPT_run ("test", emptyoptionlist, 1, emptyargv))
49 char *const myargv[] = {
56 unsigned int vflags = 0;
58 const struct GNUNET_GETOPT_CommandLineOption verboseoptionlist[] = {
59 GNUNET_GETOPT_option_verbose (&vflags),
60 GNUNET_GETOPT_OPTION_END
63 if (3 != GNUNET_GETOPT_run ("test", verboseoptionlist, 4, myargv))
80 char *const myargv[] = {
85 const struct GNUNET_GETOPT_CommandLineOption versionoptionlist[] = {
86 GNUNET_GETOPT_option_version (PACKAGE_VERSION " " VCS_VERSION),
87 GNUNET_GETOPT_OPTION_END
90 if (0 != GNUNET_GETOPT_run ("test_getopt", versionoptionlist, 2, myargv))
102 char *const myargv[] = {
107 const struct GNUNET_GETOPT_CommandLineOption aboutoptionlist[] = {
108 GNUNET_GETOPT_option_help ("Testing"),
109 GNUNET_GETOPT_OPTION_END
112 if (0 != GNUNET_GETOPT_run ("test_getopt", aboutoptionlist, 2, myargv))
124 char *const myargv[] = {
130 char *level = GNUNET_strdup ("stuff");
133 const struct GNUNET_GETOPT_CommandLineOption logoptionlist[] = {
134 GNUNET_GETOPT_option_logfile (&fn),
135 GNUNET_GETOPT_option_loglevel (&level),
136 GNUNET_GETOPT_OPTION_END
139 if (5 != GNUNET_GETOPT_run ("test_getopt",
146 GNUNET_assert (NULL != fn);
147 if ( (0 != strcmp (level, "WARNING")) ||
148 (NULL == strstr (fn, "/filename")) )
164 char *const myargv[] = {
172 unsigned int num = 0;
173 unsigned long long lnum = 0;
175 const struct GNUNET_GETOPT_CommandLineOption logoptionlist[] = {
176 GNUNET_GETOPT_option_flag ('f',
180 GNUNET_GETOPT_option_uint ('n',
185 GNUNET_GETOPT_option_ulong ('N',
190 GNUNET_GETOPT_OPTION_END
194 GNUNET_GETOPT_run ("test_getopt",
214 main (int argc, char *argv[])
218 GNUNET_log_setup ("test_getopt",
221 /* suppress output from -h, -v options */
223 GNUNET_break (0 == CLOSE (1));
225 if (0 != testMinimal ())
227 if (0 != testVerbose ())
229 if (0 != testVersion ())
231 if (0 != testAbout ())
233 if (0 != testLogOpts ())
235 if (0 != testFlagNum ())