root/maint/gnulib/tests/test-strsignal.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. main

   1 /* Test of strsignal() function.
   2    Copyright (C) 2008-2021 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, see <https://www.gnu.org/licenses/>.  */
  16 
  17 /* Written by Colin Watson <cjwatson@debian.org>, 2008.  */
  18 
  19 #include <config.h>
  20 
  21 #include <string.h>
  22 
  23 #include "signature.h"
  24 SIGNATURE_CHECK (strsignal, char *, (int));
  25 
  26 #include <signal.h>
  27 
  28 #include "macros.h"
  29 
  30 #if HAVE_DECL_SYS_SIGLIST
  31 # define ASSERT_DESCRIPTION(actual, expected)
  32 #else
  33 /* In this case, we can guarantee some signal descriptions.
  34    But allow the actual result to be longer than the expected result.  */
  35 # define ASSERT_DESCRIPTION(actual, expected) \
  36    ASSERT (strncmp (actual, expected, strlen (expected)) == 0)
  37 #endif
  38 
  39 int
  40 main (void)
     /* [previous][next][first][last][top][bottom][index][help] */
  41 {
  42   /* Work around bug in cygwin 1.5.25 <string.h> by declaring str as
  43      const char *, even though strsignal is supposed to return char *.
  44      At any rate, this doesn't hurt, since POSIX 200x states that "The
  45      string pointed to shall not be modified by the application."  */
  46   const char *str;
  47 
  48   /* We try a couple of signals, since not all signals are supported
  49      everywhere.  Notwithstanding the #ifdef for neatness, SIGINT should in
  50      fact be available on all platforms.  */
  51 
  52 #ifdef SIGHUP
  53   str = strsignal (SIGHUP);
  54   ASSERT (str);
  55   ASSERT (*str);
  56   ASSERT_DESCRIPTION (str, "Hangup");
  57 #endif
  58 
  59 #ifdef SIGINT
  60   str = strsignal (SIGINT);
  61   ASSERT (str);
  62   ASSERT (*str);
  63   ASSERT_DESCRIPTION (str, "Interrupt");
  64 #endif
  65 
  66   /* Test that for out-of-range signal numbers the result is usable.  */
  67 
  68   str = strsignal (-1);
  69   ASSERT (str);
  70   ASSERT (str != (char *) -1);
  71   ASSERT (strlen (str));
  72 
  73   str = strsignal (9249234);
  74   ASSERT (str);
  75   ASSERT (str != (char *) -1);
  76   ASSERT (strlen (str));
  77 
  78   return 0;
  79 }

/* [previous][next][first][last][top][bottom][index][help] */