1 /**
2 * @file
3 * Test code for mutt_str_sysexit()
4 *
5 * @authors
6 * Copyright (C) 2019 Richard Russon <rich@flatcap.org>
7 *
8 * @copyright
9 * This program is free software: you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License as published by the Free Software
11 * Foundation, either version 2 of the License, or (at your option) any later
12 * version.
13 *
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * details.
18 *
19 * You should have received a copy of the GNU General Public License along with
20 * this program. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23 #define TEST_NO_MAIN
24 #include "config.h"
25 #include "acutest.h"
26 #include "mutt/lib.h"
27 #ifdef HAVE_SYSEXITS_H
28 #include <sysexits.h>
29 #endif
30
31 struct TestValue
32 {
33 int err_num; ///< Error number to lookup
34 const char *result; ///< Expected result string
35 };
36
37 // clang-format off
38 static const struct TestValue tests[] = {
39 #ifdef EX_NOUSER
40 { 0xff & EX_NOUSER, "User unknown." },
41 #endif
42 #ifdef EX_NOHOST
43 { 0xff & EX_NOHOST, "Host unknown." },
44 #endif
45 #ifdef EX_UNAVAILABLE
46 { 0xff & EX_UNAVAILABLE, "Service unavailable." },
47 #endif
48 #ifdef EX_IOERR
49 { 0xff & EX_IOERR, "I/O error." },
50 #endif
51 #ifdef EX_NOPERM
52 { 0xff & EX_NOPERM, "Insufficient permission." },
53 #endif
54 { 255, NULL },
55 { -1, NULL },
56 };
57 // clang-format on
58
test_mutt_str_sysexit(void)59 void test_mutt_str_sysexit(void)
60 {
61 // const char *mutt_str_sysexit(int e);
62
63 const char *result = NULL;
64
65 for (size_t i = 0; i < mutt_array_size(tests); i++)
66 {
67 TEST_MSG("Testing %d, expecting '%s'\n", tests[i].err_num, NONULL(tests[i].result));
68 result = mutt_str_sysexit(tests[i].err_num);
69
70 if (!TEST_CHECK(mutt_str_equal(result, tests[i].result)))
71 {
72 TEST_MSG("Expected: '%s', Got: '%s'\n", result, NONULL(tests[i].result));
73 return;
74 }
75 }
76 }
77