changeset 15698:8897fe9c964d

Tests for function fstat(). * modules/fstat-tests: New file. * tests/test-fstat.c: New file. * modules/sys_stat-tests (Depends-on): Add fstat-tests.
author Bruno Haible <bruno@clisp.org>
date Tue, 20 Sep 2011 22:26:34 +0200
parents a4ad24b6e079
children 2b0173137ba0
files ChangeLog modules/fstat-tests modules/sys_stat-tests tests/test-fstat.c
diffstat 4 files changed, 68 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+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.
new file mode 100644
--- /dev/null
+++ b/modules/fstat-tests
@@ -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
--- a/modules/sys_stat-tests
+++ b/modules/sys_stat-tests
@@ -4,6 +4,7 @@
 Depends-on:
 verify
 sys_stat-c++-tests
+fstat-tests
 
 configure.ac:
 
new file mode 100644
--- /dev/null
+++ b/tests/test-fstat.c
@@ -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;
+}