1/*
2 * Copyright 2018-2020 The OpenSSL Project Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License 2.0 (the "License").  You may not use
5 * this file except in compliance with the License.  You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
8 */
9
10#include "../testutil.h"
11#include "internal/nelem.h"
12#include "tu_local.h"
13#include "output.h"
14
15
16static int used[100] = { 0 };
17
18int test_skip_common_options(void)
19{
20    OPTION_CHOICE_DEFAULT o;
21
22    while ((o = (OPTION_CHOICE_DEFAULT)opt_next()) != OPT_EOF) {
23        switch (o) {
24        case OPT_TEST_CASES:
25           break;
26        default:
27        case OPT_ERR:
28            return 0;
29        }
30    }
31    return 1;
32}
33
34size_t test_get_argument_count(void)
35{
36    return opt_num_rest();
37}
38
39char *test_get_argument(size_t n)
40{
41    char **argv = opt_rest();
42
43    OPENSSL_assert(n < sizeof(used));
44    if ((int)n >= opt_num_rest() || argv == NULL)
45        return NULL;
46    used[n] = 1;
47    return argv[n];
48}
49
50void opt_check_usage(void)
51{
52    int i;
53    char **argv = opt_rest();
54    int n, arg_count = opt_num_rest();
55
56    if (arg_count > (int)OSSL_NELEM(used))
57        n = (int)OSSL_NELEM(used);
58    else
59        n = arg_count;
60    for (i = 0; i < n; i++) {
61        if (used[i] == 0)
62            test_printf_stderr("Warning ignored command-line argument %d: %s\n",
63                               i, argv[i]);
64    }
65    if (i < arg_count)
66        test_printf_stderr("Warning arguments %d and later unchecked\n", i);
67}
68
69int opt_printf_stderr(const char *fmt, ...)
70{
71    va_list ap;
72    int ret;
73
74    va_start(ap, fmt);
75    ret = test_vprintf_stderr(fmt, ap);
76    va_end(ap);
77    return ret;
78}
79
80