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
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 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 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
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_SET_ONE ('f',
180 GNUNET_GETOPT_OPTION_SET_UINT ('n',
185 GNUNET_GETOPT_OPTION_SET_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 ())