Mercurial > hg > octave-lyh > gnulib-hg
changeset 9617:ba0cb910b71e
Tests for module 'strsignal'.
author | Colin Watson <cjwatson@debian.org> |
---|---|
date | Mon, 14 Jan 2008 00:27:28 +0100 |
parents | 878f41b0e41e |
children | 9ce61ce5d2bd |
files | ChangeLog modules/strsignal-tests tests/test-strsignal.c |
diffstat | 3 files changed, 82 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2008-01-13 Colin Watson <cjwatson@debian.org> + * 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.
new file mode 100644 --- /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
new file mode 100644 --- /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 <cjwatson@debian.org>, 2008. */ + +#include <config.h> + +#include <signal.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#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; +}