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/>.
19 * @file util/test_getopt.c
20 * @brief testcase for util/getopt.c
23 #include "gnunet_util_lib.h"
29 char *const emptyargv[] = {
33 const struct GNUNET_GETOPT_CommandLineOption emptyoptionlist[] = {
34 GNUNET_GETOPT_OPTION_END
37 if (1 != GNUNET_GETOPT_run ("test", emptyoptionlist, 1, emptyargv))
47 char *const myargv[] = {
54 unsigned int vflags = 0;
56 const struct GNUNET_GETOPT_CommandLineOption verboseoptionlist[] = {
57 GNUNET_GETOPT_option_verbose (&vflags),
58 GNUNET_GETOPT_OPTION_END
61 if (3 != GNUNET_GETOPT_run ("test", verboseoptionlist, 4, myargv))
78 char *const myargv[] = {
83 const struct GNUNET_GETOPT_CommandLineOption versionoptionlist[] = {
84 GNUNET_GETOPT_option_version (PACKAGE_VERSION " " VCS_VERSION),
85 GNUNET_GETOPT_OPTION_END
88 if (0 != GNUNET_GETOPT_run ("test_getopt", versionoptionlist, 2, myargv))
100 char *const myargv[] = {
105 const struct GNUNET_GETOPT_CommandLineOption aboutoptionlist[] = {
106 GNUNET_GETOPT_option_help ("Testing"),
107 GNUNET_GETOPT_OPTION_END
110 if (0 != GNUNET_GETOPT_run ("test_getopt", aboutoptionlist, 2, myargv))
122 char *const myargv[] = {
128 char *level = GNUNET_strdup ("stuff");
131 const struct GNUNET_GETOPT_CommandLineOption logoptionlist[] = {
132 GNUNET_GETOPT_option_logfile (&fn),
133 GNUNET_GETOPT_option_loglevel (&level),
134 GNUNET_GETOPT_OPTION_END
137 if (5 != GNUNET_GETOPT_run ("test_getopt",
144 GNUNET_assert (NULL != fn);
145 if ( (0 != strcmp (level, "WARNING")) ||
146 (NULL == strstr (fn, "/filename")) )
162 char *const myargv[] = {
170 unsigned int num = 0;
171 unsigned long long lnum = 0;
173 const struct GNUNET_GETOPT_CommandLineOption logoptionlist[] = {
174 GNUNET_GETOPT_option_flag ('f',
178 GNUNET_GETOPT_option_uint ('n',
183 GNUNET_GETOPT_option_ulong ('N',
188 GNUNET_GETOPT_OPTION_END
192 GNUNET_GETOPT_run ("test_getopt",
212 main (int argc, char *argv[])
216 GNUNET_log_setup ("test_getopt",
219 /* suppress output from -h, -v options */
221 GNUNET_break (0 == CLOSE (1));
223 if (0 != testMinimal ())
225 if (0 != testVerbose ())
227 if (0 != testVersion ())
229 if (0 != testAbout ())
231 if (0 != testLogOpts ())
233 if (0 != testFlagNum ())