• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2################################################################################
3##                                                                            ##
4## Copyright (c) International Business Machines  Corp., 2001                 ##
5##  Author:       Manoj Iyer, manjo@mail.utexas.edu                           ##
6## Copyright (c) 2016 Cyril Hrubis <chrubis@suse.cz>                          ##
7##                                                                            ##
8## This program is free software;  you can redistribute it and#or modify      ##
9## it under the terms of the GNU General Public License as published by       ##
10## the Free Software Foundation; either version 2 of the License, or          ##
11## (at your option) any later version.                                        ##
12##                                                                            ##
13## This program is distributed in the hope that it will be useful, but        ##
14## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ##
15## or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   ##
16## for more details.                                                          ##
17##                                                                            ##
18## You should have received a copy of the GNU General Public License          ##
19## along with this program;  if not, write to the Free Software Foundation,   ##
20## Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA           ##
21##                                                                            ##
22################################################################################
23#
24# Basic test for ln
25#
26TST_ID="ln01"
27TST_CNT=6
28TST_TESTFUNC=do_test
29TST_SETUP=setup
30TST_NEEDS_TMPDIR=1
31. tst_test.sh
32
33setup()
34{
35	ROD mkdir -p dir/subdir
36	ROD echo "LTP" > file
37	ROD touch dir/file
38}
39
40check_dir_link()
41{
42	local dname="$1"
43	local lname="$2"
44
45	ROD ls "$lname" > lname.out
46	ROD ls "$dname" > dname.out
47
48	if diff lname.out dname.out; then
49		tst_res TPASS "Directory and link content is equal"
50	else
51		tst_res TFAIL "Directory and link content differs"
52		cat lname.out
53		echo
54		cat dname.out
55	fi
56}
57
58check_file_link()
59{
60	local fname="$1"
61	local lname="$2"
62
63	if diff $fname $lname; then
64		tst_res TPASS "File and link content is equal"
65	else
66		tst_res TFAIL "File and link content differs"
67	fi
68}
69
70ln_test()
71{
72	local args="$1"
73	local src="$2"
74	local link="$3"
75
76	EXPECT_PASS ln $args $src $link
77
78	if [ -f $src ]; then
79		check_file_link $src $link
80	else
81		check_dir_link $src $link
82	fi
83
84	ROD rm $link
85}
86
87do_test()
88{
89	case $1 in
90	1) ln_test ""   "file"      "file_link";;
91	2) ln_test "-s" "file"      "file_link";;
92	3) ln_test "-s" "dir"       "dir_link";;
93	4) ln_test ""   "$PWD/file" "file_link";;
94	5) ln_test "-s" "$PWD/file" "file_link";;
95	6) ln_test "-s" "$PWD/dir"  "dir_link";;
96	esac
97}
98
99tst_run
100