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[] = { "test", NULL };
32 const struct GNUNET_GETOPT_CommandLineOption emptyoptionlist[] = {
33 GNUNET_GETOPT_OPTION_END
36 if (1 != GNUNET_GETOPT_run ("test", emptyoptionlist, 1, emptyargv))
46 char *const myargv[] = { "test", "-V", "-V", "more", NULL };
47 unsigned int vflags = 0;
49 const struct GNUNET_GETOPT_CommandLineOption verboseoptionlist[] =
50 { GNUNET_GETOPT_option_verbose (&vflags), GNUNET_GETOPT_OPTION_END };
52 if (3 != GNUNET_GETOPT_run ("test", verboseoptionlist, 4, myargv))
69 char *const myargv[] = { "test_getopt", "-v", NULL };
70 const struct GNUNET_GETOPT_CommandLineOption versionoptionlist[] =
71 { GNUNET_GETOPT_option_version (PACKAGE_VERSION " " VCS_VERSION),
72 GNUNET_GETOPT_OPTION_END };
74 if (0 != GNUNET_GETOPT_run ("test_getopt", versionoptionlist, 2, myargv))
86 char *const myargv[] = { "test_getopt", "-h", NULL };
87 const struct GNUNET_GETOPT_CommandLineOption aboutoptionlist[] =
88 { GNUNET_GETOPT_option_help ("Testing"), GNUNET_GETOPT_OPTION_END };
90 if (0 != GNUNET_GETOPT_run ("test_getopt", aboutoptionlist, 2, myargv))
102 char *const myargv[] =
103 { "test_getopt", "-l", "filename", "-L", "WARNING", NULL };
104 char *level = GNUNET_strdup ("stuff");
107 const struct GNUNET_GETOPT_CommandLineOption logoptionlist[] =
108 { GNUNET_GETOPT_option_logfile (&fn),
109 GNUNET_GETOPT_option_loglevel (&level),
110 GNUNET_GETOPT_OPTION_END };
112 if (5 != GNUNET_GETOPT_run ("test_getopt", logoptionlist, 5, myargv))
117 GNUNET_assert (NULL != fn);
118 if ((0 != strcmp (level, "WARNING")) || (NULL == strstr (fn, "/filename")))
134 char *const myargv[] = { "test_getopt", "-f", "-n", "42", "-N", "42", NULL };
136 unsigned int num = 0;
137 unsigned long long lnum = 0;
139 const struct GNUNET_GETOPT_CommandLineOption logoptionlist[] =
140 { GNUNET_GETOPT_option_flag ('f', "--flag", "helptext", &flag),
141 GNUNET_GETOPT_option_uint ('n', "--num", "ARG", "helptext", &num),
142 GNUNET_GETOPT_option_ulong ('N', "--lnum", "ARG", "helptext", &lnum),
143 GNUNET_GETOPT_OPTION_END };
145 if (6 != GNUNET_GETOPT_run ("test_getopt", logoptionlist, 6, myargv))
150 if ((1 != flag) || (42 != num) || (42 != lnum))
160 main (int argc, char *argv[])
164 GNUNET_log_setup ("test_getopt", "WARNING", NULL);
165 /* suppress output from -h, -v options */
167 GNUNET_break (0 == close (1));
169 if (0 != testMinimal ())
171 if (0 != testVerbose ())
173 if (0 != testVersion ())
175 if (0 != testAbout ())
177 if (0 != testLogOpts ())
179 if (0 != testFlagNum ())