From b0c07505caf646089c8f22539e478904354f0156 Mon Sep 17 00:00:00 2001 From: jsing Date: Sun, 28 Dec 2014 16:24:48 +0000 Subject: [PATCH] Add regress tests for multiple argument callback functions. --- regress/usr.bin/openssl/options/optionstest.c | 39 ++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/regress/usr.bin/openssl/options/optionstest.c b/regress/usr.bin/openssl/options/optionstest.c index ee756b78803..771e436fe54 100644 --- a/regress/usr.bin/openssl/options/optionstest.c +++ b/regress/usr.bin/openssl/options/optionstest.c @@ -1,4 +1,4 @@ -/* $OpenBSD: optionstest.c,v 1.5 2014/12/28 16:11:54 jsing Exp $ */ +/* $OpenBSD: optionstest.c,v 1.6 2014/12/28 16:24:48 jsing Exp $ */ /* * Copyright (c) 2014 Joel Sing * @@ -29,6 +29,7 @@ BIO *bio_err; CONF *config; static int argfunc(char *arg); +static int multiarg(int argc, char **argv, int *argsused); static struct { char *arg; @@ -53,6 +54,11 @@ static struct option test_options[] = { .type = OPTION_FLAG, .opt.flag = &test_config.flag, }, + { + .name = "multiarg", + .type = OPTION_ARGV_FUNC, + .opt.argvfunc = multiarg, + }, { NULL }, }; @@ -67,6 +73,7 @@ char *args8[] = { "opts", "-arg", "arg", "-flag", "file1", "file2", "file3" }; char *args9[] = { "opts", "-arg", "arg", "-flag", "file1", "-file2", "file3" }; char *args10[] = { "opts", "-arg", "arg", "-flag", "-", "file1", "file2" }; char *args11[] = { "opts", "-arg", "arg", "-flag", "-", "-file1", "-file2" }; +char *args12[] = { "opts", "-multiarg", "arg1", "arg2", "-flag", "unnamed" }; struct options_test { int argc; @@ -215,6 +222,26 @@ struct options_test options_tests[] = { .wantarg = "arg", .wantflag = 1, }, + { + /* Test 15 - Multiple argument callback. */ + .argc = 6, + .argv = args12, + .unnamed = "unnamed", + .type = OPTIONS_TEST_UNNAMED, + .want = 0, + .wantarg = NULL, + .wantflag = 1, + }, + { + /* Test 16 - Multiple argument callback. */ + .argc = 6, + .argv = args12, + .used = 5, + .type = OPTIONS_TEST_ARGSUSED, + .want = 0, + .wantarg = NULL, + .wantflag = 1, + }, }; #define N_OPTIONS_TESTS \ @@ -227,6 +254,16 @@ argfunc(char *arg) return (0); } +static int +multiarg(int argc, char **argv, int *argsused) +{ + if (argc < 3) + return (1); + + *argsused = 3; + return (0); +} + static int do_options_test(int test_no, struct options_test *ot) { -- 2.20.1