Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/lib/libc/stdio add a symlink test



details:   https://anonhg.NetBSD.org/src/rev/7afee7c2c51f
branches:  trunk
changeset: 827641:7afee7c2c51f
user:      christos <christos%NetBSD.org@localhost>
date:      Mon Nov 06 17:32:53 2017 +0000

description:
add a symlink test

diffstat:

 tests/lib/libc/stdio/t_fopen.c |  42 ++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 40 insertions(+), 2 deletions(-)

diffs (70 lines):

diff -r 4a538077e9d7 -r 7afee7c2c51f tests/lib/libc/stdio/t_fopen.c
--- a/tests/lib/libc/stdio/t_fopen.c    Mon Nov 06 15:27:09 2017 +0000
+++ b/tests/lib/libc/stdio/t_fopen.c    Mon Nov 06 17:32:53 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: t_fopen.c,v 1.3 2011/09/14 14:34:37 martin Exp $ */
+/*     $NetBSD: t_fopen.c,v 1.4 2017/11/06 17:32:53 christos Exp $ */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: t_fopen.c,v 1.3 2011/09/14 14:34:37 martin Exp $");
+__RCSID("$NetBSD: t_fopen.c,v 1.4 2017/11/06 17:32:53 christos Exp $");
 
 #include <atf-c.h>
 #include <errno.h>
@@ -336,6 +336,43 @@
        }
 }
 
+static char linkpath[] = "symlink";
+
+ATF_TC_WITH_CLEANUP(fopen_symlink);
+ATF_TC_HEAD(fopen_symlink, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "Test fopen(3) with 'l' mode");
+}
+
+ATF_TC_BODY(fopen_symlink, tc)
+{
+       static const char *mode[] = { "rl", "r+l", "wl", "w+l", "al", "a+l" };
+       size_t j;
+       FILE *f;
+
+       ATF_CHECK(symlink("/dev/null", linkpath) != -1);
+
+       for (j = 0; j < __arraycount(mode); j++) {
+
+               errno = 0;
+               f = fopen(linkpath, mode[j]);
+
+               if (f == NULL && errno == EFTYPE)
+                       continue;
+
+               if (f != NULL)
+                       (void)fclose(f);
+
+               atf_tc_fail_nonfatal("opened %s as %s", linkpath, mode[j]);
+       }
+       ATF_REQUIRE(unlink(linkpath) == 0);
+}
+
+ATF_TC_CLEANUP(fopen_symlink, tc)
+{
+       (void)unlink(linkpath);
+}
+
 ATF_TC_WITH_CLEANUP(fopen_seek);
 ATF_TC_HEAD(fopen_seek, tc)
 {
@@ -435,6 +472,7 @@
        ATF_TP_ADD_TC(tp, fopen_mode);
        ATF_TP_ADD_TC(tp, fopen_perm);
        ATF_TP_ADD_TC(tp, fopen_regular);
+       ATF_TP_ADD_TC(tp, fopen_symlink);
        ATF_TP_ADD_TC(tp, fopen_seek);
        ATF_TP_ADD_TC(tp, freopen_std);
 



Home | Main Index | Thread Index | Old Index