gnupload: Support option -h as alias of --help.
[gnulib.git] / tests / test-strsignal.c
blobb184e59e72ae4195a1c6f4417982a307fa702f4f
1 /* Test of strsignal() function.
2 Copyright (C) 2008-2018 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3, or (at your option)
7 any later version.
9 This program 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 Colin Watson <cjwatson@debian.org>, 2008. */
19 #include <config.h>
21 #include <string.h>
23 #include "signature.h"
24 SIGNATURE_CHECK (strsignal, char *, (int));
26 #include <signal.h>
28 #include "macros.h"
30 #if HAVE_DECL_SYS_SIGLIST
31 # define ASSERT_DESCRIPTION(got, expect)
32 #else
33 /* In this case, we can guarantee some signal descriptions. */
34 # define ASSERT_DESCRIPTION(got, expect) ASSERT (!strcmp (got, expect))
35 #endif
37 int
38 main (void)
40 /* Work around bug in cygwin 1.5.25 <string.h> by declaring str as
41 const char *, even though strsignal is supposed to return char *.
42 At any rate, this doesn't hurt, since POSIX 200x states that "The
43 string pointed to shall not be modified by the application." */
44 const char *str;
46 /* We try a couple of signals, since not all signals are supported
47 everywhere. Notwithstanding the #ifdef for neatness, SIGINT should in
48 fact be available on all platforms. */
50 #ifdef SIGHUP
51 str = strsignal (SIGHUP);
52 ASSERT (str);
53 ASSERT (*str);
54 ASSERT_DESCRIPTION (str, "Hangup");
55 #endif
57 #ifdef SIGINT
58 str = strsignal (SIGINT);
59 ASSERT (str);
60 ASSERT (*str);
61 ASSERT_DESCRIPTION (str, "Interrupt");
62 #endif
64 /* Test that for out-of-range signal numbers the result is usable. */
66 str = strsignal (-1);
67 ASSERT (str);
68 ASSERT (str != (char *) -1);
69 ASSERT (strlen (str));
71 str = strsignal (9249234);
72 ASSERT (str);
73 ASSERT (str != (char *) -1);
74 ASSERT (strlen (str));
76 return 0;