summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/regress/usr.bin/openssl/options/optionstest.c48
1 files changed, 45 insertions, 3 deletions
diff --git a/src/regress/usr.bin/openssl/options/optionstest.c b/src/regress/usr.bin/openssl/options/optionstest.c
index 297cf8506f..d493f7801d 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.3 2014/12/28 15:07:52 jsing Exp $ */ 1/* $OpenBSD: optionstest.c,v 1.4 2014/12/28 15:49:36 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> 3 * Copyright (c) 2014 Joel Sing <jsing@openbsd.org>
4 * 4 *
@@ -62,6 +62,8 @@ char *args3[] = { "opts", "-arg", "arg", "-flag", "unnamed" };
62char *args4[] = { "opts", "-arg", "arg", "unnamed", "-flag" }; 62char *args4[] = { "opts", "-arg", "arg", "unnamed", "-flag" };
63char *args5[] = { "opts", "unnamed1", "-arg", "arg", "-flag", "unnamed2" }; 63char *args5[] = { "opts", "unnamed1", "-arg", "arg", "-flag", "unnamed2" };
64char *args6[] = { "opts", "-argfunc", "arg", "-flag" }; 64char *args6[] = { "opts", "-argfunc", "arg", "-flag" };
65char *args7[] = { "opts", "-arg", "arg", "-flag", "file1", "file2", "file3" };
66char *args8[] = { "opts", "-arg", "arg", "-flag", "file1", "-file2", "file3" };
65 67
66struct options_test { 68struct options_test {
67 int argc; 69 int argc;
@@ -69,6 +71,7 @@ struct options_test {
69 enum { 71 enum {
70 OPTIONS_TEST_NONE, 72 OPTIONS_TEST_NONE,
71 OPTIONS_TEST_UNNAMED, 73 OPTIONS_TEST_UNNAMED,
74 OPTIONS_TEST_ARGSUSED,
72 } type; 75 } type;
73 char *unnamed; 76 char *unnamed;
74 int used; 77 int used;
@@ -149,12 +152,42 @@ struct options_test options_tests[] = {
149 .wantarg = "arg", 152 .wantarg = "arg",
150 .wantflag = 1, 153 .wantflag = 1,
151 }, 154 },
155 {
156 /* Named and multiple unnamed. */
157 .argc = 7,
158 .argv = args7,
159 .used = 4,
160 .type = OPTIONS_TEST_ARGSUSED,
161 .want = 0,
162 .wantarg = "arg",
163 .wantflag = 1,
164 },
165 {
166 /* Named and multiple unnamed. */
167 .argc = 7,
168 .argv = args8,
169 .used = 4,
170 .type = OPTIONS_TEST_ARGSUSED,
171 .want = 0,
172 .wantarg = "arg",
173 .wantflag = 1,
174 },
175 {
176 /* Named only. */
177 .argc = 4,
178 .argv = args2,
179 .used = 4,
180 .type = OPTIONS_TEST_ARGSUSED,
181 .want = 0,
182 .wantarg = "arg",
183 .wantflag = 1,
184 },
152}; 185};
153 186
154#define N_OPTIONS_TESTS \ 187#define N_OPTIONS_TESTS \
155 (sizeof(options_tests) / sizeof(*options_tests)) 188 (sizeof(options_tests) / sizeof(*options_tests))
156 189
157int 190static int
158argfunc(char *arg) 191argfunc(char *arg)
159{ 192{
160 test_config.arg = arg; 193 test_config.arg = arg;
@@ -164,15 +197,19 @@ argfunc(char *arg)
164static int 197static int
165do_options_test(int test_no, struct options_test *ot) 198do_options_test(int test_no, struct options_test *ot)
166{ 199{
200 int *argsused = NULL;
167 char *unnamed = NULL; 201 char *unnamed = NULL;
168 char **arg = NULL; 202 char **arg = NULL;
203 int used = 0;
169 int ret; 204 int ret;
170 205
171 if (ot->type == OPTIONS_TEST_UNNAMED) 206 if (ot->type == OPTIONS_TEST_UNNAMED)
172 arg = &unnamed; 207 arg = &unnamed;
208 else if (ot->type == OPTIONS_TEST_ARGSUSED)
209 argsused = &used;
173 210
174 memset(&test_config, 0, sizeof(test_config)); 211 memset(&test_config, 0, sizeof(test_config));
175 ret = options_parse(ot->argc, ot->argv, test_options, arg); 212 ret = options_parse(ot->argc, ot->argv, test_options, arg, argsused);
176 if (ret != ot->want) { 213 if (ret != ot->want) {
177 fprintf(stderr, "FAIL: test %i options_parse() returned %i, " 214 fprintf(stderr, "FAIL: test %i options_parse() returned %i, "
178 "want %i\n", test_no, ret, ot->want); 215 "want %i\n", test_no, ret, ot->want);
@@ -201,6 +238,11 @@ do_options_test(int test_no, struct options_test *ot)
201 test_no, unnamed, ot->unnamed); 238 test_no, unnamed, ot->unnamed);
202 return (1); 239 return (1);
203 } 240 }
241 if (ot->type == OPTIONS_TEST_ARGSUSED && used != ot->used) {
242 fprintf(stderr, "FAIL: test %i got used %i, want %i\n",
243 test_no, used, ot->used);
244 return (1);
245 }
204 246
205 return (0); 247 return (0);
206} 248}