• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    ##
19##                                                                            ##
20################################################################################
21#
22# File :         unzip_tests.sh
23#
24# Description:   Test Basic functionality of unzip command. Pass in the zip
25#		 file to test.
26#
27# Author:        Manoj Iyer, manjo@mail.utexas.edu
28#
29# History:       Mar 03 2003 - Created - Manoj Iyer.
30#
31
32
33
34# Function: 	chk_ifexists
35#
36# Description:  - Check if command required for this test exits.
37#
38# Input:        - $1 - calling test case.
39#               - $2 - command that needs to be checked.
40#
41# Return:		- zero on success.
42# 				- non-zero on failure.
43
44chk_ifexists()
45{
46	RC=0
47	which $2 > "$PWD/tst_unzip.err" || RC=$?
48	if [ $? -ne 0 ]
49	then
50		tst_brkm TBROK NULL "$1: command $2 not found."
51	fi
52	return $RC
53}
54
55
56# Function: 	cleanup
57#
58# Description:  - remove temporaty files and directories.
59#
60# Return:		- zero on success.
61# 				- non-zero on failure.
62cleanup()
63{
64	cd /
65	# remove all the temporary files created by this test.
66	tst_resm TINFO "CLEAN: removing \"$LTPTMP\""
67	rm -fr "$LTPTMP"
68}
69
70
71# Function: init
72#
73# Description:  - Check if command required for this test exits.
74#               - Create temporary directories required for this test.
75#               - Initialize global variables.
76#
77# Return:		- zero on success.
78# 				- non-zero on failure.
79init()
80{
81	# Initialize global variables.
82	export RC=0
83	export TST_TOTAL=1
84	export TCID="unzip01"
85	export TST_COUNT=0
86
87	# Inititalize cleanup function.
88
89	# create the temporary directory used by this testcase
90	LTPTMP=`mktemp -d $$.XXXXXX` || tst_resm TBROK "Unable to create temporary directory with: mktemp -d $$.XXXXXX"
91	trap "cleanup" 0
92	cd "$LTPTMP"
93
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
99
100	# create expected output files. tst_unzip.exp
101	cat > $PWD/tst_unzip.out.exp <<-EOF
102	Archive:  $1
103    creating: tst_unzip.dir/
104    creating: tst_unzip.dir/d.0/
105    extracting: tst_unzip.dir/d.0/f.0
106    extracting: tst_unzip.dir/d.0/f.1
107    extracting: tst_unzip.dir/d.0/f.2
108    creating: tst_unzip.dir/d.0/d.1/
109    extracting: tst_unzip.dir/d.0/d.1/f.0
110    extracting: tst_unzip.dir/d.0/d.1/f.1
111    extracting: tst_unzip.dir/d.0/d.1/f.2
112    creating: tst_unzip.dir/d.0/d.1/d.2/
113    extracting: tst_unzip.dir/d.0/d.1/d.2/f.0
114    extracting: tst_unzip.dir/d.0/d.1/d.2/f.1
115    extracting: tst_unzip.dir/d.0/d.1/d.2/f.2
116	EOF
117
118	return $RC
119}
120
121
122# Function: 	test01
123#
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.
128#
129# Return:		- zero on success.
130# 				- non-zero on failure.
131test01()
132{
133	count=0
134	files=" "
135	filesize=0
136	zipfile="$1"
137
138	TCID=unzip01
139	TST_COUNT=1
140
141	tst_resm TINFO "Test #1: unzip command un-compresses a .zip file."
142
143	unzip "${zipfile}" > "$PWD/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"
152
153		diff -iwB "$PWD/tst_unzip.out" "$PWD/tst_unzip.out.exp" >\
154    		          "$PWD/tst_unzip.out.err" || RC=$?
155
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 \"$PWD/tst_unzip.dir\" exits."
162			if ! [ -d $PWD/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: \"$PWD/tst_unzip.dir\" was created by unzip"
170				tst_resm TPASS \
171				   "Test #1: unzip can uncompress .zip file correctly."
172			fi
173		fi
174	fi
175
176	return $RC
177}
178
179# Function:	main
180#
181# Description:	- Execute all tests and report results.
182#
183# Exit:			- zero on success
184#               - non-zero on failure.
185
186RC=0
187stat "$1" || exit $?
188init "$1" || exit $?
189
190test01 "$1" || RC=$?
191
192exit $RC
193