Merge branch 'dfsg_clean'
[ltp-debian.git] / testcases / commands / unzip / unzip_tests.sh
blob8ee7af758ee02fc1b18a9a5565c1be409aa3629e
1 #! /bin/sh
2 ################################################################################
3 ## ##
4 ## Copyright (c) International Business Machines Corp., 2001 ##
5 ## ##
6 ## This program is free software; you can redistribute it and#or modify ##
7 ## it under the terms of the GNU General Public License as published by ##
8 ## the Free Software Foundation; either version 2 of the License, or ##
9 ## (at your option) any later version. ##
10 ## ##
11 ## This program is distributed in the hope that it will be useful, but ##
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ##
13 ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ##
14 ## for more details. ##
15 ## ##
16 ## You should have received a copy of the GNU General Public License ##
17 ## along with this program; if not, write to the Free Software ##
18 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ##
19 ## ##
20 ################################################################################
22 # File : unzip_tests.sh
24 # Description: Test Basic functionality of unzip command. Pass in the zip
25 # file to test.
27 # Author: Manoj Iyer, manjo@mail.utexas.edu
29 # History: Mar 03 2003 - Created - Manoj Iyer.
32 PATH=$PATH:$LTPTOOLS
34 LTPBIN=${LTPROOT:-$PWD}/testcases/bin
36 # Function: chk_ifexists
38 # Description: - Check if command required for this test exits.
40 # Input: - $1 - calling test case.
41 # - $2 - command that needs to be checked.
43 # Return: - zero on success.
44 # - non-zero on failure.
46 chk_ifexists()
48 RC=0
49 which $2 > "$PWD/tst_unzip.err" || RC=$?
50 if [ $? -ne 0 ]
51 then
52 tst_brkm TBROK NULL "$1: command $2 not found."
54 return $RC
58 # Function: cleanup
60 # Description: - remove temporaty files and directories.
62 # Return: - zero on success.
63 # - non-zero on failure.
64 cleanup()
66 # remove all the temporary files created by this test.
67 tst_resm TINFO "CLEAN: removing \"$LTPTMP\""
68 rm -fr "$LTPTMP"
72 # Function: init
74 # Description: - Check if command required for this test exits.
75 # - Create temporary directories required for this test.
76 # - Initialize global variables.
78 # Return: - zero on success.
79 # - non-zero on failure.
80 init()
82 # Initialize global variables.
83 export RC=0
84 export TST_TOTAL=1
85 export TCID="unzip01"
86 export TST_COUNT=0
88 # Inititalize cleanup function.
90 # create the temporary directory used by this testcase
91 LTPTMP=`mktemp -d -t $$.XXXXXX` || tst_resm TBROK "Unable to create temporary directory with: mktemp -d $$.XXXXXX"
92 trap "cleanup" 0
94 # check if commands tst_*, unzip, awk, etc exists.
95 chk_ifexists INIT tst_resm || return $RC
96 chk_ifexists INIT unzip || return $RC
97 chk_ifexists INIT mkdir || return $RC
98 chk_ifexists INIT awk || return $RC
100 # create expected output files. tst_unzip.exp
101 cat > $LTPTMP/tst_unzip.out.exp <<-EOF
102 Archive: $LTPBIN/tst_unzip_file.zip
103 creating: tmp/tst_unzip.dir/
104 creating: tmp/tst_unzip.dir/d.0/
105 extracting: tmp/tst_unzip.dir/d.0/f.0
106 extracting: tmp/tst_unzip.dir/d.0/f.1
107 extracting: tmp/tst_unzip.dir/d.0/f.2
108 creating: tmp/tst_unzip.dir/d.0/d.1/
109 extracting: tmp/tst_unzip.dir/d.0/d.1/f.0
110 extracting: tmp/tst_unzip.dir/d.0/d.1/f.1
111 extracting: tmp/tst_unzip.dir/d.0/d.1/f.2
112 creating: tmp/tst_unzip.dir/d.0/d.1/d.2/
113 extracting: tmp/tst_unzip.dir/d.0/d.1/d.2/f.0
114 extracting: tmp/tst_unzip.dir/d.0/d.1/d.2/f.1
115 extracting: tmp/tst_unzip.dir/d.0/d.1/d.2/f.2
118 return $RC
122 # Function: test01
124 # Description: - Test that unzip can uncompress .zip file correctly.
125 # - Execute unzip command on a .zip file, save output to file.
126 # - If unzip exits with a non-zero value or, the expected output
127 # is different from actual output, test fails.
129 # Return: - zero on success.
130 # - non-zero on failure.
131 test01()
133 count=0
134 files=" "
135 filesize=0
136 zipfile="$1"
138 TCID=unzip01
139 TST_COUNT=1
141 tst_resm TINFO "Test #1: unzip command un-compresses a .zip file."
143 ( cd $LTPTMP; unzip "$zipfile" > "$LTPTMP/tst_unzip.out") || RC=$?
144 if [ $RC -ne 0 ]
145 then
146 tst_res TFAIL "$PWD/tst_unzip.out" \
147 "Test #1: unzip command failed. Return value = $RC. Details:"
148 return $RC
149 else
150 sort -o "$PWD/tst_unzip.out" "$PWD/tst_unzip.out"
151 sort -o "$PWD/tst_unzip.out.exp" "$PWD/tst_unzip.out.exp"
153 diff -iwB "$PWD/tst_unzip.out" "$PWD/tst_unzip.out.exp" >\
154 "$PWD/tst_unzip.out.err" || RC=$?
156 if [ $RC -ne 0 ]
157 then
158 tst_res TFAIL "$PWD/tst_unzip.out.err" \
159 "Test #1: unzip output differs from expected output. Details"
160 else
161 tst_resm TINFO "Test #1: check if $LTPTMP/tmp/tst_unzip.dir exits."
162 if ! [ -d $LTPTMP/tmp/tst_unzip.dir ]
163 then
164 tst_resm TFAIL \
165 "Test #1: unzip did not uncompress the .zip file"
166 $((RC+1))
167 else
168 tst_resm TINFO \
169 "Test #1: $LTPTMP/tmp/tst_unzip.dir was created by unzip"
170 tst_resm TPASS \
171 "Test #1: unzip can uncompress .zip file correctly."
176 return $RC
179 # Function: main
181 # Description: - Execute all tests and report results.
183 # Exit: - zero on success
184 # - non-zero on failure.
186 RC=0
187 stat "$1" || exit $?
188 init "$1" || exit $?
190 test01 "$1" || RC=$?
192 exit $RC