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 TST_ID="gzip" 32 TST_CNT=2 33 TST_TESTFUNC=test 34 TST_NEEDS_TMPDIR=1 35 TST_NEEDS_CMDS="gzip gunzip" 36 . tst_test.sh 37 38 creat_dirnfiles() 39 { 40 local numdirs=$2 41 local numfiles=$3 42 local dirname=$4 43 local dircnt=0 44 local fcnt=0 45 46 tst_res TINFO "Test #$1: Creating $numdirs directories" 47 tst_res TINFO "Test #$1: filling each dir with $numfiles files" 48 while [ $dircnt -lt $numdirs ]; do 49 dirname=$dirname/d.$dircnt 50 ROD_SILENT mkdir -p $dirname 51 52 fcnt=0 53 while [ $fcnt -lt $numfiles ]; do 54 ROD_SILENT touch $dirname/f.$fcnt 55 fcnt=$(($fcnt+1)) 56 done 57 dircnt=$(($dircnt+1)) 58 done 59 } 60 61 creat_expout() 62 { 63 local numdir=$1 64 local numfile=$2 65 local dirname=$3 66 local ext=$4 67 local dircnt=0 68 local fcnt=0 69 70 echo "$dirname:" 1> tst_gzip.exp 71 echo "d.$dircnt" 1>> tst_gzip.exp 72 while [ $dircnt -lt $numdirs ]; do 73 dirname=$dirname/d.$dircnt 74 dircnt=$(($dircnt+1)) 75 echo "$dirname:" 1>> tst_gzip.exp 76 if [ $dircnt -lt $numdirs ]; then 77 echo "d.$dircnt" 1>> tst_gzip.exp 78 fi 79 fcnt=0 80 while [ $fcnt -lt $numfiles ]; do 81 echo "f.$fcnt$ext " 1>> tst_gzip.exp 82 fcnt=$(($fcnt+1)) 83 done 84 printf "\n\n" 1>> tst_gzip.exp 85 done 86 } 87 88 test1() 89 { 90 numdirs=10 91 numfiles=10 92 dircnt=0 93 fcnt=0 94 95 ROD_SILENT mkdir tst_gzip.tmp 96 97 tst_res TINFO "Test #1: gzip -r will recursively compress contents" \ 98 "of directory" 99 100 creat_dirnfiles 1 $numdirs $numfiles tst_gzip.tmp 101 102 gzip -r tst_gzip.tmp > tst_gzip.err 2>&1 103 if [ $? -ne 0 ]; then 104 cat tst_gzip.err 105 tst_brk TFAIL "Test #1: gzip -r failed" 106 fi 107 108 tst_res TINFO "Test #1: creating output file" 109 ls -R tst_gzip.tmp > tst_gzip.out 2>&1 110 111 tst_res TINFO "Test #1: creating expected output file" 112 creat_expout $numdirs $numfiles tst_gzip.tmp .gz 113 114 diff -w -B tst_gzip.out tst_gzip.exp > tst_gzip.err 2>&1 115 if [ $? -ne 0 ]; then 116 cat tst_gzip.err 117 tst_res TFAIL "Test #1: gzip failed" 118 else 119 tst_res TPASS "Test #1: gzip -r success" 120 fi 121 122 ROD_SILENT rm -rf tst_gzip.tmp/ 123 } 124 125 test2() 126 { 127 numdirs=10 128 numfiles=10 129 dircnt=0 130 fcnt=0 131 132 ROD_SILENT mkdir tst_gzip.tmp 133 134 tst_res TINFO "Test #2: gunzip -r will recursively uncompress" \ 135 "contents of directory" 136 137 creat_dirnfiles 2 $numdirs $numfiles tst_gzip.tmp 138 139 gzip -r tst_gzip.tmp > tst_gzip.err 2>&1 140 if [ $? -ne 0 ]; then 141 cat tst_gzip.err 142 tst_brk TBROK "Test #2: compressing directory tst_gzip.tmp" \ 143 "failed" 144 fi 145 146 gunzip -r tst_gzip.tmp > tst_gzip.err 2>&1 147 if [ $? -ne 0 ]; then 148 cat tst_gzip.err 149 tst_brk TBROK "Test #2: uncompressing directory" \ 150 " tst_gzip.tmp failed" 151 fi 152 153 tst_res TINFO "Test #2: creating output file" 154 ls -R tst_gzip.tmp > tst_gzip.out 2>&1 155 156 tst_res TINFO "Test #2: creating expected output file" 157 creat_expout $numdirs $numfiles tst_gzip.tmp 158 159 tst_res TINFO "Test #2: comparing expected out and actual output file" 160 diff -w -B tst_gzip.out tst_gzip.exp > tst_gzip.err 2>&1 161 if [ $? -ne 0 ]; then 162 cat tst_gzip.err 163 tst_res TFAIL "Test #2: gunzip failed" 164 else 165 tst_res TPASS "Test #2: gunzip -r success" 166 fi 167 168 ROD_SILENT rm -rf tst_gzip.tmp/ 169 } 170 171 tst_run 172