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