diff options
author | jsing <> | 2014-12-28 16:34:23 +0000 |
---|---|---|
committer | jsing <> | 2014-12-28 16:34:23 +0000 |
commit | cdbf5d984f51d28354c8c515f784b96908acfee0 (patch) | |
tree | a8b7cd0b8489a0bffebe44522662f508c04ae729 | |
parent | b22c7be04463e72177bf89d6e8c6992f5af14710 (diff) | |
download | openbsd-cdbf5d984f51d28354c8c515f784b96908acfee0.tar.gz openbsd-cdbf5d984f51d28354c8c515f784b96908acfee0.tar.bz2 openbsd-cdbf5d984f51d28354c8c515f784b96908acfee0.zip |
Add regress tests for default option handling.
-rw-r--r-- | src/regress/usr.bin/openssl/options/optionstest.c | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/src/regress/usr.bin/openssl/options/optionstest.c b/src/regress/usr.bin/openssl/options/optionstest.c index 771e436fe5..c10c70b8c3 100644 --- a/src/regress/usr.bin/openssl/options/optionstest.c +++ b/src/regress/usr.bin/openssl/options/optionstest.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: optionstest.c,v 1.6 2014/12/28 16:24:48 jsing Exp $ */ | 1 | /* $OpenBSD: optionstest.c,v 1.7 2014/12/28 16:34:23 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> |
4 | * | 4 | * |
@@ -29,6 +29,7 @@ BIO *bio_err; | |||
29 | CONF *config; | 29 | CONF *config; |
30 | 30 | ||
31 | static int argfunc(char *arg); | 31 | static int argfunc(char *arg); |
32 | static int defaultarg(int argc, char **argv, int *argsused); | ||
32 | static int multiarg(int argc, char **argv, int *argsused); | 33 | static int multiarg(int argc, char **argv, int *argsused); |
33 | 34 | ||
34 | static struct { | 35 | static struct { |
@@ -59,6 +60,11 @@ static struct option test_options[] = { | |||
59 | .type = OPTION_ARGV_FUNC, | 60 | .type = OPTION_ARGV_FUNC, |
60 | .opt.argvfunc = multiarg, | 61 | .opt.argvfunc = multiarg, |
61 | }, | 62 | }, |
63 | { | ||
64 | .name = NULL, | ||
65 | .type = OPTION_ARGV_FUNC, | ||
66 | .opt.argvfunc = defaultarg, | ||
67 | }, | ||
62 | { NULL }, | 68 | { NULL }, |
63 | }; | 69 | }; |
64 | 70 | ||
@@ -74,6 +80,7 @@ char *args9[] = { "opts", "-arg", "arg", "-flag", "file1", "-file2", "file3" }; | |||
74 | char *args10[] = { "opts", "-arg", "arg", "-flag", "-", "file1", "file2" }; | 80 | char *args10[] = { "opts", "-arg", "arg", "-flag", "-", "file1", "file2" }; |
75 | char *args11[] = { "opts", "-arg", "arg", "-flag", "-", "-file1", "-file2" }; | 81 | char *args11[] = { "opts", "-arg", "arg", "-flag", "-", "-file1", "-file2" }; |
76 | char *args12[] = { "opts", "-multiarg", "arg1", "arg2", "-flag", "unnamed" }; | 82 | char *args12[] = { "opts", "-multiarg", "arg1", "arg2", "-flag", "unnamed" }; |
83 | char *args13[] = { "opts", "-multiargz", "arg1", "arg2", "-flagz", "unnamed" }; | ||
77 | 84 | ||
78 | struct options_test { | 85 | struct options_test { |
79 | int argc; | 86 | int argc; |
@@ -242,6 +249,26 @@ struct options_test options_tests[] = { | |||
242 | .wantarg = NULL, | 249 | .wantarg = NULL, |
243 | .wantflag = 1, | 250 | .wantflag = 1, |
244 | }, | 251 | }, |
252 | { | ||
253 | /* Test 17 - Default callback. */ | ||
254 | .argc = 6, | ||
255 | .argv = args13, | ||
256 | .unnamed = "unnamed", | ||
257 | .type = OPTIONS_TEST_UNNAMED, | ||
258 | .want = 0, | ||
259 | .wantarg = NULL, | ||
260 | .wantflag = 1, | ||
261 | }, | ||
262 | { | ||
263 | /* Test 18 - Default callback. */ | ||
264 | .argc = 6, | ||
265 | .argv = args13, | ||
266 | .used = 5, | ||
267 | .type = OPTIONS_TEST_ARGSUSED, | ||
268 | .want = 0, | ||
269 | .wantarg = NULL, | ||
270 | .wantflag = 1, | ||
271 | }, | ||
245 | }; | 272 | }; |
246 | 273 | ||
247 | #define N_OPTIONS_TESTS \ | 274 | #define N_OPTIONS_TESTS \ |
@@ -255,6 +282,26 @@ argfunc(char *arg) | |||
255 | } | 282 | } |
256 | 283 | ||
257 | static int | 284 | static int |
285 | defaultarg(int argc, char **argv, int *argsused) | ||
286 | { | ||
287 | if (argc < 1) | ||
288 | return (1); | ||
289 | |||
290 | if (strcmp(argv[0], "-multiargz") == 0) { | ||
291 | if (argc < 3) | ||
292 | return (1); | ||
293 | *argsused = 3; | ||
294 | return (0); | ||
295 | } else if (strcmp(argv[0], "-flagz") == 0) { | ||
296 | test_config.flag = 1; | ||
297 | *argsused = 1; | ||
298 | return (0); | ||
299 | } | ||
300 | |||
301 | return (1); | ||
302 | } | ||
303 | |||
304 | static int | ||
258 | multiarg(int argc, char **argv, int *argsused) | 305 | multiarg(int argc, char **argv, int *argsused) |
259 | { | 306 | { |
260 | if (argc < 3) | 307 | if (argc < 3) |