Tests for module 'strsignal'.
authorColin Watson <cjwatson@debian.org>
Sun, 13 Jan 2008 23:27:28 +0000 (00:27 +0100)
committerBruno Haible <bruno@clisp.org>
Sun, 13 Jan 2008 23:27:28 +0000 (00:27 +0100)
ChangeLog
modules/strsignal-tests [new file with mode: 0644]
tests/test-strsignal.c [new file with mode: 0644]

index 073d066..5b90e00 100644 (file)
--- 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.
diff --git a/modules/strsignal-tests b/modules/strsignal-tests
new file mode 100644 (file)
index 0000000..d0e50bf
--- /dev/null
@@ -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 (file)
index 0000000..16544f2
--- /dev/null
@@ -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;
+}