errno-h: document Haiku errors can’t be -1
[gnulib.git] / tests / test-sig2str.c
blob64930630763d9d607f1c1835314ffb4443ec25bb
1 /* Test the sig2str and str2sig functions.
2 Copyright (C) 2024-2025 Free Software Foundation, Inc.
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published
6 by the Free Software Foundation, either version 3 of the License,
7 or (at your option) any later version.
9 This file is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 /* Written by Collin Funk <collin.funk1@gmail.com>, 2024. */
19 #include <config.h>
21 /* Specification. */
22 #include <signal.h>
24 #include "signature.h"
25 SIGNATURE_CHECK (sig2str, int, (int, char *));
26 SIGNATURE_CHECK (str2sig, int, (char const *restrict, int *restrict));
28 #include <string.h>
30 #include "macros.h"
32 static void
33 test_sig2str (void)
35 char buffer[SIG2STR_MAX];
37 /* Test sig2str on signals specified by ISO C. */
39 ASSERT (sig2str (SIGABRT, buffer) == 0);
40 ASSERT (STREQ (buffer, "ABRT"));
42 ASSERT (sig2str (SIGFPE, buffer) == 0);
43 ASSERT (STREQ (buffer, "FPE"));
45 ASSERT (sig2str (SIGILL, buffer) == 0);
46 ASSERT (STREQ (buffer, "ILL"));
48 ASSERT (sig2str (SIGINT, buffer) == 0);
49 ASSERT (STREQ (buffer, "INT"));
51 ASSERT (sig2str (SIGSEGV, buffer) == 0);
52 ASSERT (STREQ (buffer, "SEGV"));
54 ASSERT (sig2str (SIGTERM, buffer) == 0);
55 ASSERT (STREQ (buffer, "TERM"));
57 /* Check behavior of sig2str on invalid signals. */
59 ASSERT (sig2str (-714, buffer) == -1);
62 static void
63 test_str2sig (void)
65 int signo;
67 /* Test str2sig on signals specified by ISO C. */
69 ASSERT (str2sig ("ABRT", &signo) == 0);
70 ASSERT (signo == SIGABRT);
72 ASSERT (str2sig ("FPE", &signo) == 0);
73 ASSERT (signo == SIGFPE);
75 ASSERT (str2sig ("ILL", &signo) == 0);
76 ASSERT (signo == SIGILL);
78 ASSERT (str2sig ("INT", &signo) == 0);
79 ASSERT (signo == SIGINT);
81 ASSERT (str2sig ("SEGV", &signo) == 0);
82 ASSERT (signo == SIGSEGV);
84 ASSERT (str2sig ("TERM", &signo) == 0);
85 ASSERT (signo == SIGTERM);
87 /* Check behavior of str2sig on invalid signals. */
89 ASSERT (str2sig ("Not a signal", &signo) == -1);
92 int
93 main (void)
95 test_sig2str ();
96 test_str2sig ();
98 return test_exit_status;