From: Colin Watson Date: Sun, 13 Jan 2008 23:27:28 +0000 (+0100) Subject: Tests for module 'strsignal'. X-Git-Tag: v0.1~7836 X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=ec1d2ed4fd41d9ff10d11a7a8784293163fb558d;p=gnulib.git Tests for module 'strsignal'. --- diff --git a/ChangeLog b/ChangeLog index 073d066f8..5b90e0019 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2008-01-13 Colin Watson + * modules/strsignal-tests: New file. + * tests/test-strsignal.c: New file. + * lib/strsignal.c: New file, from glibc with modifications. * lib/siglist.h: New file, from glibc with modifications. * lib/string.in.h (strsignal): New declaration. diff --git a/modules/strsignal-tests b/modules/strsignal-tests new file mode 100644 index 000000000..d0e50bfd9 --- /dev/null +++ b/modules/strsignal-tests @@ -0,0 +1,10 @@ +Files: +tests/test-strsignal.c + +Depends-on: + +configure.ac: + +Makefile.am: +TESTS += test-strsignal +check_PROGRAMS += test-strsignal diff --git a/tests/test-strsignal.c b/tests/test-strsignal.c new file mode 100644 index 000000000..16544f209 --- /dev/null +++ b/tests/test-strsignal.c @@ -0,0 +1,69 @@ +/* Test of strsignal() function. + Copyright (C) 2008 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Written by Colin Watson , 2008. */ + +#include + +#include +#include +#include +#include + +#define ASSERT(expr) \ + do \ + { \ + if (!(expr)) \ + { \ + fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ + abort (); \ + } \ + } \ + while (0) + +#if HAVE_DECL_SYS_SIGLIST +# define ASSERT_DESCRIPTION(got, expect) +#else +/* In this case, we can guarantee some signal descriptions. */ +# define ASSERT_DESCRIPTION(got, expect) ASSERT (!strcmp (got, expect)) +#endif + +int +main (int argc, char **argv) +{ + char *str; + + /* We try a couple of signals, since not all signals are supported + everywhere. Notwithstanding the #ifdef for neatness, SIGINT should in + fact be available on all platforms. */ + +#ifdef SIGHUP + str = strsignal (SIGHUP); + ASSERT (str); + ASSERT (*str); + ASSERT_DESCRIPTION (str, "Hangup"); +#endif + +#ifdef SIGINT + str = strsignal (SIGINT); + ASSERT (str); + ASSERT (*str); + ASSERT_DESCRIPTION (str, "Interrupt"); +#endif + + return 0; +}