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 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.
16 * @file util/test_getopt.c
17 * @brief testcase for util/getopt.c
20 #include "gnunet_util_lib.h"
26 char *const emptyargv[] = {
30 const struct GNUNET_GETOPT_CommandLineOption emptyoptionlist[] = {
31 GNUNET_GETOPT_OPTION_END
34 if (1 != GNUNET_GETOPT_run ("test", emptyoptionlist, 1, emptyargv))
44 char *const myargv[] = {
51 unsigned int vflags = 0;
53 const struct GNUNET_GETOPT_CommandLineOption verboseoptionlist[] = {
54 GNUNET_GETOPT_option_verbose (&vflags),
55 GNUNET_GETOPT_OPTION_END
58 if (3 != GNUNET_GETOPT_run ("test", verboseoptionlist, 4, myargv))
75 char *const myargv[] = {
80 const struct GNUNET_GETOPT_CommandLineOption versionoptionlist[] = {
81 GNUNET_GETOPT_option_version (PACKAGE_VERSION " " VCS_VERSION),
82 GNUNET_GETOPT_OPTION_END
85 if (0 != GNUNET_GETOPT_run ("test_getopt", versionoptionlist, 2, myargv))
97 char *const myargv[] = {
102 const struct GNUNET_GETOPT_CommandLineOption aboutoptionlist[] = {
103 GNUNET_GETOPT_option_help ("Testing"),
104 GNUNET_GETOPT_OPTION_END
107 if (0 != GNUNET_GETOPT_run ("test_getopt", aboutoptionlist, 2, myargv))
119 char *const myargv[] = {
125 char *level = GNUNET_strdup ("stuff");
128 const struct GNUNET_GETOPT_CommandLineOption logoptionlist[] = {
129 GNUNET_GETOPT_option_logfile (&fn),
130 GNUNET_GETOPT_option_loglevel (&level),
131 GNUNET_GETOPT_OPTION_END
134 if (5 != GNUNET_GETOPT_run ("test_getopt",
141 GNUNET_assert (NULL != fn);
142 if ( (0 != strcmp (level, "WARNING")) ||
143 (NULL == strstr (fn, "/filename")) )
159 char *const myargv[] = {
167 unsigned int num = 0;
168 unsigned long long lnum = 0;
170 const struct GNUNET_GETOPT_CommandLineOption logoptionlist[] = {
171 GNUNET_GETOPT_option_flag ('f',
175 GNUNET_GETOPT_option_uint ('n',
180 GNUNET_GETOPT_option_ulong ('N',
185 GNUNET_GETOPT_OPTION_END
189 GNUNET_GETOPT_run ("test_getopt",
209 main (int argc, char *argv[])
213 GNUNET_log_setup ("test_getopt",
216 /* suppress output from -h, -v options */
218 GNUNET_break (0 == CLOSE (1));
220 if (0 != testMinimal ())
222 if (0 != testVerbose ())
224 if (0 != testVersion ())
226 if (0 != testAbout ())
228 if (0 != testLogOpts ())
230 if (0 != testFlagNum ())