1 #!/bin/sh 2 ################################################################################ 3 ## ## 4 ## Copyright (c) International Business Machines Corp., 2001 ## 5 ## Author: Manoj Iyer, manjo (at] mail.utexas.edu ## 6 ## ## 7 ## This program is free software; you can redistribute it and#or modify ## 8 ## it under the terms of the GNU General Public License as published by ## 9 ## the Free Software Foundation; either version 2 of the License, or ## 10 ## (at your option) any later version. ## 11 ## ## 12 ## This program is distributed in the hope that it will be useful, but ## 13 ## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## 14 ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## 15 ## for more details. ## 16 ## ## 17 ## You should have received a copy of the GNU General Public License ## 18 ## along with this program; if not, write to the Free Software ## 19 ## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ## 20 ## ## 21 ################################################################################ 22 # 23 # Description: Test basic functionality of gzip and gunzip command 24 # - Test #1: Test that gzip -r will travel directories and 25 # compress all the files available. 26 # 27 # - Test #2: Test that gunzip -r will travel directories and 28 # uncompress all the files available. 29 # 30 31 TCID=gzip 32 TST_TOTAL=2 33 . test.sh 34 35 setup() 36 { 37 tst_check_cmds gzip 38 39 tst_check_cmds gunzip 40 41 tst_tmpdir 42 43 tst_resm TINFO "INIT: Inititalizing tests" 44 45 ROD_SILENT mkdir -p tst_gzip.tmp 46 } 47 48 cleanup() 49 { 50 tst_rmdir 51 } 52 53 cleanup_test() 54 { 55 ROD_SILENT rm -rf tst_gzip.tmp/* 56 } 57 58 creat_dirnfiles() 59 { 60 local numdirs=$2 61 local numfiles=$3 62 local dirname=$4 63 local dircnt=0 64 local fcnt=0 65 66 tst_resm TINFO "Test #$1: Creating $numdirs directories" 67 tst_resm TINFO "Test #$1: filling each dir with $numfiles files" 68 while [ $dircnt -lt $numdirs ] 69 do 70 dirname=$dirname/d.$dircnt 71 ROD_SILENT mkdir -p $dirname 72 73 fcnt=0 74 while [ $fcnt -lt $numfiles ] 75 do 76 ROD_SILENT touch $dirname/f.$fcnt 77 fcnt=$(($fcnt+1)) 78 done 79 dircnt=$(($dircnt+1)) 80 done 81 } 82 83 creat_expout() 84 { 85 local numdir=$1 86 local numfile=$2 87 local dirname=$3 88 local ext=$4 89 local dircnt=0 90 local fcnt=0 91 92 echo "$dirname:" 1> tst_gzip.exp 93 echo "d.$dircnt" 1>> tst_gzip.exp 94 while [ $dircnt -lt $numdirs ] 95 do 96 dirname=$dirname/d.$dircnt 97 dircnt=$(($dircnt+1)) 98 echo "$dirname:" 1>> tst_gzip.exp 99 if [ $dircnt -lt $numdirs ] 100 then 101 echo "d.$dircnt" 1>> tst_gzip.exp 102 fi 103 fcnt=0 104 while [ $fcnt -lt $numfiles ] 105 do 106 echo "f.$fcnt$ext " 1>> tst_gzip.exp 107 fcnt=$(($fcnt+1)) 108 done 109 printf "\n\n" 1>> tst_gzip.exp 110 done 111 } 112 113 test01() 114 { 115 numdirs=10 116 numfiles=10 117 dircnt=0 118 fcnt=0 119 120 tst_resm TINFO "Test #1: gzip -r will recursively compress contents" \ 121 "of directory" 122 123 creat_dirnfiles 1 $numdirs $numfiles tst_gzip.tmp 124 125 gzip -r tst_gzip.tmp > tst_gzip.err 2>&1 126 if [ $? -ne 0 ] 127 then 128 cat tst_gzip.err 129 tst_brkm TFAIL "Test #1: gzip -r failed" 130 fi 131 132 tst_resm TINFO "Test #1: creating output file" 133 ls -R tst_gzip.tmp > tst_gzip.out 2>&1 134 135 tst_resm TINFO "Test #1: creating expected output file" 136 creat_expout $numdirs $numfiles tst_gzip.tmp .gz 137 138 tst_resm TINFO "Test #1: comparing expected out and actual" \ 139 "output file" 140 diff -w -B tst_gzip.out tst_gzip.exp > tst_gzip.err 2>&1 141 if [ $? -ne 0 ] 142 then 143 cat tst_gzip.err 144 tst_resm TFAIL "Test #1: gzip failed" 145 else 146 tst_resm TINFO "Test #1: expected same as actual" 147 tst_resm TPASS "Test #1: gzip -r success" 148 fi 149 } 150 151 test02() 152 { 153 numdirs=10 154 numfiles=10 155 dircnt=0 156 fcnt=0 157 158 tst_resm TINFO "Test #2: gunzip -r will recursively uncompress" \ 159 "contents of directory" 160 161 creat_dirnfiles 2 $numdirs $numfiles tst_gzip.tmp 162 163 gzip -r tst_gzip.tmp > tst_gzip.err 2>&1 164 if [ $? -ne 0 ] 165 then 166 cat tst_gzip.err 167 tst_brkm TBROK "Test #2: compressing directory tst_gzip.tmp" \ 168 "failed" 169 fi 170 171 gunzip -r tst_gzip.tmp > tst_gzip.err 2>&1 172 if [ $? -ne 0 ] 173 then 174 cat tst_gzip.err 175 tst_brkm TBROK "Test #2: uncompressing directory" \ 176 " tst_gzip.tmp failed" 177 return $RC 178 fi 179 180 tst_resm TINFO "Test #2: creating output file" 181 ls -R tst_gzip.tmp > tst_gzip.out 2>&1 182 183 tst_resm TINFO "Test #2: creating expected output file" 184 creat_expout $numdirs $numfiles tst_gzip.tmp 185 186 tst_resm TINFO "Test #2: comparing expected out and actual output file" 187 diff -w -B tst_gzip.out tst_gzip.exp > tst_gzip.err 2>&1 188 if [ $? -ne 0 ] 189 then 190 cat tst_gzip.err 191 tst_resm TFAIL "Test #2: gunzip failed" 192 else 193 tst_resm TINFO "Test #2: expected same as actual" 194 tst_resm TPASS "Test #2: gunzip -r success" 195 fi 196 } 197 198 setup 199 TST_CLEANUP=cleanup 200 201 test01 202 cleanup_test 203 204 test02 205 206 tst_exit 207