Source-Changes-HG archive

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

[src/trunk]: src/tests/lib/librumphijack a basic getcwd() test



details:   https://anonhg.NetBSD.org/src/rev/c0183f0c2864
branches:  trunk
changeset: 762327:c0183f0c2864
user:      pooka <pooka%NetBSD.org@localhost>
date:      Sat Feb 19 13:19:52 2011 +0000

description:
a basic getcwd() test

diffstat:

 tests/lib/librumphijack/Makefile |   4 +-
 tests/lib/librumphijack/h_cwd.c  |  90 ++++++++++++++++++++++++++++++++++++++++
 tests/lib/librumphijack/t_cwd.sh |  53 +++++++++++++++++++++++
 3 files changed, 146 insertions(+), 1 deletions(-)

diffs (172 lines):

diff -r 35db77d79d96 -r c0183f0c2864 tests/lib/librumphijack/Makefile
--- a/tests/lib/librumphijack/Makefile  Sat Feb 19 13:10:35 2011 +0000
+++ b/tests/lib/librumphijack/Makefile  Sat Feb 19 13:19:52 2011 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.3 2011/02/14 15:14:00 pooka Exp $
+#      $NetBSD: Makefile,v 1.4 2011/02/19 13:19:52 pooka Exp $
 #
 
 .include <bsd.own.mk>
@@ -6,9 +6,11 @@
 TESTSDIR=      ${TESTSBASE}/lib/librumphijack
 
 TESTS_SH=      t_asyncio
+TESTS_SH+=     t_cwd
 TESTS_SH+=     t_tcpip
 TESTS_C=       h_client
 TESTS_C+=      h_netget
+TESTS_C+=      h_cwd
 
 FILES=         netstat.expout index.html
 FILESDIR=      ${TESTSDIR}
diff -r 35db77d79d96 -r c0183f0c2864 tests/lib/librumphijack/h_cwd.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/lib/librumphijack/h_cwd.c   Sat Feb 19 13:19:52 2011 +0000
@@ -0,0 +1,90 @@
+/*      $NetBSD: h_cwd.c,v 1.1 2011/02/19 13:19:52 pooka Exp $ */
+
+/*-
+ * Copyright (c) 2011 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
+ * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+ * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <err.h>
+#include <errno.h>
+#include <string.h>
+#include <unistd.h>
+
+int
+main(void)
+{
+       char pwd[1024];
+
+       if (chdir("/rump") == -1)
+               err(1, "chdir1");
+       if (getcwd(pwd, sizeof(pwd)) == NULL)
+               err(1, "getcwd1");
+       if (strcmp(pwd, "/rump") != 0)
+               errx(1, "strcmp1");
+
+       if (mkdir("dir", 0777) == -1)
+               err(1, "mkdir2");
+       if (chdir("dir") == -1)
+               err(1, "chdir2");
+       if (getcwd(pwd, sizeof(pwd)) == NULL)
+               err(1, "getcwd2");
+       if (strcmp(pwd, "/rump/dir") != 0)
+               errx(1, "strcmp2");
+
+       if (mkdir("dir", 0777) == -1)
+               err(1, "mkdir3");
+       if (chdir("dir") == -1)
+               err(1, "chdir3");
+       if (getcwd(pwd, sizeof(pwd)) == NULL)
+               err(1, "getcwd3");
+       if (strcmp(pwd, "/rump/dir/dir") != 0)
+               errx(1, "strcmp3");
+
+       if (chdir("..") == -1)
+               err(1, "chdir4");
+       if (getcwd(pwd, sizeof(pwd)) == NULL)
+               err(1, "getcwd4");
+       if (strcmp(pwd, "/rump/dir") != 0)
+               errx(1, "strcmp4");
+
+       if (chdir("../../../../../../..") == -1)
+               err(1, "chdir5");
+       if (getcwd(pwd, sizeof(pwd)) == NULL)
+               err(1, "getcwd5");
+       if (strcmp(pwd, "/rump") != 0)
+               errx(1, "strcmp5");
+
+       if (chdir("/") == -1)
+               err(1, "chdir6");
+       if (getcwd(pwd, sizeof(pwd)) == NULL)
+               err(1, "getcwd6");
+       if (strcmp(pwd, "/") != 0)
+               errx(1, "strcmp6");
+
+       return 0;
+}
diff -r 35db77d79d96 -r c0183f0c2864 tests/lib/librumphijack/t_cwd.sh
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/lib/librumphijack/t_cwd.sh  Sat Feb 19 13:19:52 2011 +0000
@@ -0,0 +1,53 @@
+#       $NetBSD: t_cwd.sh,v 1.1 2011/02/19 13:19:52 pooka Exp $
+#
+# Copyright (c) 2011 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+rumpsrv='rump_server -lrumpvfs'
+export RUMP_SERVER=unix://csock
+
+atf_test_case basic cleanup
+basic_head()
+{
+        atf_set "descr" "basic cwd test"
+}
+
+basic_body()
+{
+
+       atf_check -s exit:0 ${rumpsrv} ${RUMP_SERVER}
+       atf_check -s exit:0 env LD_PRELOAD=/usr/lib/librumphijack.so \
+           $(atf_get_srcdir)/h_cwd
+}
+
+basic_cleanup()
+{
+       rump.halt
+}
+
+atf_init_test_cases()
+{
+       atf_add_test_case basic
+}



Home | Main Index | Thread Index | Old Index