2 This file is part of GNUnet.
3 (C) 2003, 2004, 2005, 2006, 2009 Christian Grothoff (and other contributing authors)
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 2, 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., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
21 * @file util/test_getopt.c
22 * @brief testcase for util/getopt.c
25 #include "gnunet_common.h"
26 #include "gnunet_configuration_lib.h"
27 #include "gnunet_getopt_lib.h"
34 char *const emptyargv[] = {
38 const struct GNUNET_GETOPT_CommandLineOption emptyoptionlist[] = {
39 GNUNET_GETOPT_OPTION_END
42 if (1 != GNUNET_GETOPT_run ("test", emptyoptionlist, 1, emptyargv))
51 char *const myargv[] = {
58 unsigned int vflags = 0;
59 const struct GNUNET_GETOPT_CommandLineOption verboseoptionlist[] = {
60 GNUNET_GETOPT_OPTION_VERBOSE (&vflags),
61 GNUNET_GETOPT_OPTION_END
64 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),
87 GNUNET_GETOPT_OPTION_END
90 if (-1 != GNUNET_GETOPT_run ("test_getopt", versionoptionlist, 2, myargv))
101 char *const myargv[] = {
106 const struct GNUNET_GETOPT_CommandLineOption aboutoptionlist[] = {
107 GNUNET_GETOPT_OPTION_HELP ("Testing"),
108 GNUNET_GETOPT_OPTION_END
111 if (-1 != GNUNET_GETOPT_run ("test_getopt", aboutoptionlist, 2, myargv))
122 char *const myargv[] = {
128 char *level = GNUNET_strdup ("stuff");
130 const struct GNUNET_GETOPT_CommandLineOption logoptionlist[] = {
131 GNUNET_GETOPT_OPTION_LOGFILE (&fn),
132 GNUNET_GETOPT_OPTION_LOGLEVEL (&level),
133 GNUNET_GETOPT_OPTION_END
136 if (5 != GNUNET_GETOPT_run ("test_getopt", logoptionlist, 5, myargv))
141 GNUNET_assert (fn != NULL);
142 if ((0 != strcmp (level, "WARNING")) || (0 != strcmp (fn, "filename")))
157 char *const myargv[] = {
165 unsigned int num = 0;
166 unsigned long long lnum = 0;
167 const struct GNUNET_GETOPT_CommandLineOption logoptionlist[] = {
168 {'f', "--flag", NULL, "helptext", 0, &GNUNET_GETOPT_set_one,
170 {'n', "--num", "ARG", "helptext", 1, &GNUNET_GETOPT_set_uint,
172 {'N', "--lnum", "ARG", "helptext", 1, &GNUNET_GETOPT_set_ulong,
174 GNUNET_GETOPT_OPTION_END
177 if (6 != GNUNET_GETOPT_run ("test_getopt", logoptionlist, 6, myargv))
182 if ((1 != flag) || (42 != num) || (42 != lnum))
191 main (int argc, char *argv[])
195 GNUNET_log_setup ("test_getopt", "WARNING", NULL);
196 /* suppress output from -h, -v options */
198 GNUNET_break (0 == CLOSE (1));
200 if (0 != testMinimal ())
202 if (0 != testVerbose ())
204 if (0 != testVersion ())
206 if (0 != testAbout ())
208 if (0 != testLogOpts ())
210 if (0 != testFlagNum ())