1#! /bin/sh 2# errorcase.sh: Testing for the various error cases for "delta". 3 4# Import common functions & definitions. 5. ../../common/test-common 6. ../../common/real-thing 7 8# $TESTING_SCCS_V5 Test SCCSv5 features from SunOS 9# $TESTING_CSSC Relict from CSSC tests, also applies to SCCS 10# $TESTING_REAL_CSSC Test real CSSC 4-digit year extensions 11# $TESTING_REAL_SCCS Test real Schily SCCS 4 digit year extensions 12# $TESTING_SCCS_V6 Test SCCSv6 features 13 14remove command.log log log.stdout log.stderr 15mkdir test 2>/dev/null 16 17g=foo 18s=s.$g 19p=p.$g 20z=z.$g 21q=q.$g 22d=d.$g 23x=x.$g 24files="$g $s $p $z ${g}_1 ${g}_2 $g $q $d $x $g.saved $g.old" 25 26remove $files 27test -d $x.bak && rmdir $x.bak 28 29append() { 30 f="$1" 31 shift 32 echo "$@" >> "$f" || miscarry "Could not append a line to $1" 33} 34 35 36createfile () { 37 touch "$1" && test -r "$1" || miscarry "could not create file $1" 38} 39 40removedirs () { 41 for d 42 do 43 if test -d "$d" 44 then 45 rmdir "$d" || miscarry "Failed to remove directory $d" 46 else 47 if test -f "$d" 48 then 49 remove "$d" 50 fi 51 fi 52 done 53} 54 55 56if wrong_group=`${SRCROOT}/tests/testutils/user foreigngroup` 57then 58 true 59else 60 miscarry "could not select the name of a group to which you do not belong" 61fi 62# echo "You do not belong to group number" $wrong_group 63 64 65# Create the SCCS file - and make sure that delta can be made to work at all. 66docommand E1 "${admin} -n $s" 0 IGNORE IGNORE 67docommand E2 "${get} -e $s" 0 IGNORE IGNORE 68append $g "test data" 69docommand E3 "${vg_delta} -yNoComment $s" 0 IGNORE IGNORE 70 71# Now set up the authorised groups list. 72docommand E4 "${admin} -a${wrong_group} $s" 0 IGNORE IGNORE 73 74# cannot do get -e if you are not in the authorised user list. 75docommand E5 "${get} -e $s" 1 IGNORE IGNORE 76 77# Momentarily zap the authorised user list so that "get -e" works. 78docommand E6 "${admin} -e${wrong_group} $s" 0 IGNORE IGNORE 79docommand E7 "${get} -e $s" 0 IGNORE IGNORE 80docommand E8 "${admin} -a${wrong_group} $s" 0 IGNORE IGNORE 81 82append $g "more test data" 83 84# delta should still fail if we are not in the authorised user list 85# (in other words the list is checked both by get -e and delta). 86docommand E9 "${vg_delta} -yNoComment $s" 1 IGNORE IGNORE 87 88# Remove the authorised group list; check-in should now work 89docommand E10 "${admin} -e${wrong_group} $s" 0 IGNORE IGNORE 90docommand E11 "${vg_delta} -yNoComment $s" 0 IGNORE IGNORE 91 92 93# Now, what if the authorised user list just excludes? 94remove $s 95if mygroup=`${SRCROOT}/tests/testutils/user group` 96then 97 true 98else 99 miscarry "could not determine group-id" 100fi 101 102if myname=`${SRCROOT}/tests/testutils/user name` 103then 104 true 105else 106 miscarry "could not determine user name" 107fi 108 109# Regular SCCS does not underatand the use of "!username" 110# to specifically exclude users. Hence for compatibility 111# nor must we. 112docommand E12 "${admin} -n $s" 0 IGNORE IGNORE 113docommand E13 "${admin} -a${mygroup} $s" 0 IGNORE IGNORE 114docommand E14 "${admin} -a\!'${myname}' $s" 0 IGNORE IGNORE 115docommand E15 "${get} -e $s" 0 IGNORE IGNORE 116# this means that the above tests should succeed. 117 118# Check - use of delta when a q-file already exists... 119createfile $q 120docommand E16 "${vg_delta} -yNoComment $s" 1 IGNORE IGNORE 121remove $q 122 123# Unreadable g-file should also cause a failure. 124chmod 0 $g 125cat $g > /dev/null 2> /dev/null 126if [ $? -ne 0 ]; then 127 docommand E17 "${vg_delta} -yNoComment $s" 1 IGNORE IGNORE 128else 129 echo "Your permissions on your OS do not support chmod 0 to remove read permission - test E17 skipped" 130fi 131chmod +r $g 132docommand E18 "${vg_delta} -yNoComment $s" 0 IGNORE IGNORE 133 134 135# Failure to create the d-file should NOT cause a failure. 136docommand E19 "${get} -e $s" 0 IGNORE IGNORE 137remove $x 138createfile $d 139docommand E20 "${vg_delta} -yNoComment $s" 0 IGNORE IGNORE 140 141# This should not leave any other temporary file lying about 142# but it should also not delete the s-file 143docommand E22 "test -r $x" 1 "" "" 144docommand E23 "test -r $q" 1 "" "" 145 146# The d-file would have been deleted (without causing an error) in E20. 147# Since there was no error the g-file should no longer be there either. 148docommand E24 "test -r $d" 1 "" "" 149docommand E25 "test -r $s" 0 "" "" 150docommand E26 "test -w $g" 1 "" "" 151 152# Since E20 was successful, no need to do the delta again 153#remove $d 154#docommand E27 "${vg_delta} -yNoComment $s" 0 IGNORE IGNORE 155 156# %A as the last two characters of the file to be checked in 157# should not cause the world to end. 158remove $s 159if ${TESTING_REAL_CSSC} || ${TESTING_REAL_SCCS} 160then 161 docommand E28 "${admin} -b -n $s" 0 IGNORE IGNORE 162 163 docommand E29 "${get} -e $s" 0 IGNORE IGNORE 164 echo_nonl "%A" > $g 165 cp $g $g.saved || miscarry "could not back up $g" 166 docommand E30 "${vg_delta} -yNoComment $s" 0 IGNORE IGNORE 167 docommand E31 "${get} -k $s" 0 IGNORE IGNORE 168 169 echo_nonl E32... 170 if diff $g.saved $g 171 then 172 echo passed 173 else 174 fail "E32: Expcected to get the same contents back, did we did not" 175 fi 176 remove $g 177 178 179 # Now tests for not being able to rename an existing x-file. This 180 # is not an error - we just overwrite the original x-file as 181 # SCCS does, rather than backing it up. 182 # This test is specific to CSSC because SCCS doesn't rename the x-file... 183 mkdir $x.bak 184 createfile $x 185 docommand E33 "${get} -e $s" 0 IGNORE IGNORE 186 docommand E34 "${vg_delta} -yNoComment $s" 0 IGNORE IGNORE 187 removedirs $x.bak 188 189else 190 echo "(Some tests skipped - we are not sure if ${admin} has binary file support)" 191fi 192remove $s 193 194 195# Test for the case where the p-file lists a SID which is not in the 196# SCCS file. 197 198# Create deltas 1.1 and 1.2 199docommand E35 "${admin} -n $s" 0 IGNORE IGNORE 200docommand E36 "${get} -e $s" 0 IGNORE IGNORE 201docommand E37 "${vg_delta} -yNoComment $s" 0 IGNORE IGNORE 202 203# Edit delta 1.2 and then remove delta 1.2 204docommand E38 "${get} -e $s" 0 IGNORE IGNORE 205rename $p saved.$p 206docommand E39 "${rmdel} -r1.2 $s" 0 IGNORE IGNORE 207rename saved.$p $p 208 209# Try to check in the file - this should fail. 210docommand E40 "${delta} -yNoComment $s" 1 "" IGNORE 211remove $p 212 213remove $files 214 215 216success 217