Tests for function fstat().
authorBruno Haible <bruno@clisp.org>
Tue, 20 Sep 2011 20:26:34 +0000 (22:26 +0200)
committerBruno Haible <bruno@clisp.org>
Tue, 20 Sep 2011 21:27:58 +0000 (23:27 +0200)
* modules/fstat-tests: New file.
* tests/test-fstat.c: New file.
* modules/sys_stat-tests (Depends-on): Add fstat-tests.

ChangeLog
modules/fstat-tests [new file with mode: 0644]
modules/sys_stat-tests
tests/test-fstat.c [new file with mode: 0644]

index 8e970c2..ead3b95 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2011-09-20  Bruno Haible  <bruno@clisp.org>
 
+       Tests for function fstat().
+       * modules/fstat-tests: New file.
+       * tests/test-fstat.c: New file.
+       * modules/sys_stat-tests (Depends-on): Add fstat-tests.
+
+2011-09-20  Bruno Haible  <bruno@clisp.org>
+
        test-ttyname_r tests: EBADF tests.
        * tests/test-ttyname_r.c (main): Add tests for EBADF.
 
diff --git a/modules/fstat-tests b/modules/fstat-tests
new file mode 100644 (file)
index 0000000..27ebb38
--- /dev/null
@@ -0,0 +1,12 @@
+Files:
+tests/test-fstat.c
+tests/signature.h
+tests/macros.h
+
+Depends-on:
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-fstat
+check_PROGRAMS += test-fstat
index a5ede77..bfdc1a2 100644 (file)
@@ -4,6 +4,7 @@ tests/test-sys_stat.c
 Depends-on:
 verify
 sys_stat-c++-tests
+fstat-tests
 
 configure.ac:
 
diff --git a/tests/test-fstat.c b/tests/test-fstat.c
new file mode 100644 (file)
index 0000000..6c120d9
--- /dev/null
@@ -0,0 +1,48 @@
+/* Tests of fstat() function.
+   Copyright (C) 2011 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 of the License, 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, see <http://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+#include <sys/stat.h>
+
+#include "signature.h"
+SIGNATURE_CHECK (fstat, int, (int, struct stat *));
+
+#include <errno.h>
+
+#include "macros.h"
+
+int
+main (int argc, char *argv[])
+{
+  /* Test behaviour for invalid file descriptors.  */
+  {
+    struct stat statbuf;
+
+    errno = 0;
+    ASSERT (fstat (-1, &statbuf) == -1);
+    ASSERT (errno == EBADF);
+  }
+  {
+    struct stat statbuf;
+
+    errno = 0;
+    ASSERT (fstat (99, &statbuf) == -1);
+    ASSERT (errno == EBADF);
+  }
+
+  return 0;
+}