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. */
24 #include "signature.h"
25 SIGNATURE_CHECK (sig2str
, int, (int, char *));
26 SIGNATURE_CHECK (str2sig
, int, (char const *restrict
, int *restrict
));
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);
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);
98 return test_exit_status
;