Debian Codegraph @

contrib/mod_auth_otp/t/api/tests.c

raw symbols SCIP
1 /*
2 * ProFTPD - mod_auth_otp API testsuite
3 * Copyright (c) 2015 The ProFTPD Project team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
18 *
19 * As a special exemption, The ProFTPD Project team and other respective
20 * copyright holders give permission to link this program with OpenSSL, and
21 * distribute the resulting executable, without including the source code for
22 * OpenSSL in the source distribution.
23 */
24
25 #include "tests.h"
26
27 struct testsuite_info {
28 const char *name;
29 Suite *(*get_suite)(void);
30 };
31
32 static struct testsuite_info suites[] = {
33 { "base32", tests_get_base32_suite },
34 { "hotp", tests_get_hotp_suite },
35 { "totp", tests_get_totp_suite },
36
37 { NULL, NULL }
38 };
39
40 static Suite *tests_get_suite(const char *suite) {
41 if (strcmp(suite, "base32") == 0) {
42 return tests_get_base32_suite();
43 }
44
45 if (strcmp(suite, "hotp") == 0) {
46 return tests_get_hotp_suite();
47 }
48
49 if (strcmp(suite, "totp") == 0) {
50 return tests_get_totp_suite();
51 }
52
53 return NULL;
54 }
55
56 int main(int argc, char *argv[]) {
57 const char *log_file = "auth-otp-tests.log";
58 int nfailed = 0;
59 SRunner *runner = NULL;
60 char *requested = NULL;
61
62 runner = srunner_create(NULL);
63
64 /* XXX This log name should be set outside this code, e.g. via environment
65 * variable or command-line option.
66 */
67 srunner_set_log(runner, log_file);
68
69 requested = getenv("AUTH_OTP_TEST_SUITE");
70 if (requested) {
71 Suite *suite;
72
73 suite = tests_get_suite(requested);
74 if (suite) {
75 srunner_add_suite(runner, suite);
76
77 } else {
78 fprintf(stderr,
79 "No such test suite ('%s') requested via AUTH_OTP_TEST_SUITE\n",
80 requested);
81 return EXIT_FAILURE;
82 }
83
84 } else {
85 register unsigned int i;
86
87 for (i = 0; suites[i].name; i++) {
88 Suite *suite;
89
90 suite = (suites[i].get_suite)();
91 if (suite) {
92 srunner_add_suite(runner, suite);
93 }
94 }
95 }
96
97 requested = getenv("PR_TEST_NOFORK");
98 if (requested) {
99 srunner_set_fork_status(runner, CK_NOFORK);
100 }
101
102 srunner_run_all(runner, CK_NORMAL);
103
104 nfailed = srunner_ntests_failed(runner);
105
106 if (runner)
107 srunner_free(runner);
108
109 if (nfailed != 0) {
110 fprintf(stderr, "-------------------------------------------------\n");
111 fprintf(stderr, " FAILED %d %s\n\n", nfailed,
112 nfailed != 1 ? "tests" : "test");
113 fprintf(stderr, " Please send email to:\n\n");
114 fprintf(stderr, " [email protected]\n\n");
115 fprintf(stderr, " containing the `%s' file (in the t/ directory)\n", log_file);
116 fprintf(stderr, " and the output from running `proftpd -V'\n");
117 fprintf(stderr, "-------------------------------------------------\n");
118
119 return EXIT_FAILURE;
120 }
121
122 return EXIT_SUCCESS;
123 }