added missing dependencies to fix failing unistr/ tests
[gnulib.git] / tests / test-strsignal.c
1 /* Test of strsignal() function.
2    Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
3
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.
8
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.
13
14    You should have received a copy of the GNU General Public License
15    along with this program; if not, write to the Free Software Foundation,
16    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
17
18 /* Written by Colin Watson <cjwatson@debian.org>, 2008.  */
19
20 #include <config.h>
21
22 #include <string.h>
23
24 #include "signature.h"
25 SIGNATURE_CHECK (strsignal, char *, (int));
26
27 #include <signal.h>
28
29 #include "macros.h"
30
31 #if HAVE_DECL_SYS_SIGLIST
32 # define ASSERT_DESCRIPTION(got, expect)
33 #else
34 /* In this case, we can guarantee some signal descriptions.  */
35 # define ASSERT_DESCRIPTION(got, expect) ASSERT (!strcmp (got, expect))
36 #endif
37
38 int
39 main (void)
40 {
41   /* Work around bug in cygwin 1.5.25 <string.h> by declaring str as
42      const char *, even though strsignal is supposed to return char *.
43      At any rate, this doesn't hurt, since POSIX 200x states that "The
44      string pointed to shall not be modified by the application."  */
45   const char *str;
46
47   /* We try a couple of signals, since not all signals are supported
48      everywhere.  Notwithstanding the #ifdef for neatness, SIGINT should in
49      fact be available on all platforms.  */
50
51 #ifdef SIGHUP
52   str = strsignal (SIGHUP);
53   ASSERT (str);
54   ASSERT (*str);
55   ASSERT_DESCRIPTION (str, "Hangup");
56 #endif
57
58 #ifdef SIGINT
59   str = strsignal (SIGINT);
60   ASSERT (str);
61   ASSERT (*str);
62   ASSERT_DESCRIPTION (str, "Interrupt");
63 #endif
64
65   /* Test that for out-of-range signal numbers the result is usable.  */
66
67   str = strsignal (-1);
68   ASSERT (str);
69   ASSERT (str != (char *) -1);
70   ASSERT (strlen (str));
71
72   str = strsignal (9249234);
73   ASSERT (str);
74   ASSERT (str != (char *) -1);
75   ASSERT (strlen (str));
76
77   return 0;
78 }