1#! /bin/sh 2# auto.sh: Tests for "admin"'s detection of binary files. 3 4# Import common functions & definitions. 5. ../../common/test-common 6. ../../common/real-thing 7. ../../common/config-data 8 9if $binary_support 10then 11 true 12else 13 echo "Skipping these tests -- no binary file support." 14 exit 0 15fi 16 17 18 19good() { 20 if $expect_fail ; then 21 echo UNEXPECTED PASS 22 else 23 echo passed 24 fi 25} 26 27bad() { 28 if $expect_fail ; then 29 echo failed -- but we expected that. 30 else 31 fail "$@" 32 fi 33} 34 35 36# test_bin: 37# Usage: test_bin LABEL <contents> 38# 39# create a flie containing the specified argument and check 40# that it is encoded as a binary file. 41test_bin() { 42label=$1 43echo_nonl ${label}... 44shift 45 46infile=$1 47shift 48 49 50if ${use_stdin} 51then 52 cmd="cat ${infile} | ${vg_admin} -i ${adminflags} $s" 53else 54 cmd="${vg_admin} -i${infile} ${adminflags} $s" 55fi 56 57rm -f $s 58remove errmsg 59if ( eval "${cmd}" ) >/dev/null 2>errmsg 60then 61 if ( ${prs} -d:FL: $s 2>/dev/null; echo foo ) | grep encoded >/dev/null 2>&1 62 then 63 remove $g errmsg 64 if ${get} -p ${s} 2>errmsg >${g} 65 then 66 remove errmsg 67 if diff ${infile} ${g} >diffs 68 then 69 remove diffs 70 good 71 else 72 # We failed to get the data back correctly from the 73 # SCCS file. 74 bad "$label data lost (see file 'diffs') in ${cmd}". 75 fi 76 else 77 bad $label "${get} -p $s failed: `cat errmsg`" 78 fi 79 else 80 bad $label input did not produce an encoded s-file. 81 fi 82else 83 cat errmsg ; remove errmsg 84 bad $label ${admin} returned exit status $?. 85fi 86rm -f $s 87} 88 89# test_ascii: 90# 91# As for test_bin, but the resulting SCCS file must NOT be encoded. 92# 93test_ascii() { 94label=$1 95echo_nonl ${label}... 96shift 97 98rm -f infile $s 99echo_nonl "$@" > infile 100if ${vg_admin} -iinfile ${adminflags} $s >/dev/null 2>&1 101then 102 if ( ${prt} -f $s 2>/dev/null ; echo foo ) | grep encoded >/dev/null 2>&1 103 then 104 bad $label input produced an encoded s-file and should not have. 105 else 106 good 107 fi 108else 109 bad $label ${vg_admin} returned exit status $?. 110fi 111rm -f infile $s 112} 113 114 115g=testfile 116s=s.$g 117z=z.$g 118x=x.$g 119p=p.$g 120files="$s $z $x $p" 121 122remove $files long-text-file infile ctrl-A-file no-newline ctrl-A-end 123remove command.log log base [sxzp].$g errmsg $g 124 125expect_fail=false 126adminflags="" 127 128remove long-text-file 129${SRCROOT}/tests/testutils/yammer 1000 "this is a text file" > long-text-file 130#${SRCROOT}/tests/testutils/yes "this is a text file" | nl | head -1000 >long-text-file 131if test -s long-text-file 132then 133 true 134else 135 miscarry could not create long-text-file. 136fi 137 138remove no-newline 139echo_nonl "no newline here" > no-newline 140remove ctrl-A-file 141echo_nonl \ 142 "the next line of this file starts with " \ 143 "a ctrl-A,\n\001Which SCCS does not like" > ctrl-A-file 144remove ctrl-A-end 145echo_nonl \ 146 "This file ends with a ctrl-A.\n\001" > ctrl-A-end 147 148 149# Make sure that we correctly decide to encode the files, 150# and that we don't lose data. 151 152# First make sure that forcing binary mode works. 153use_stdin=false 154adminflags=-b 155test_bin s1 long-text-file 156adminflags= 157 158 159# Now try various nearly-text files. 160if $TESTING_SCCS_V6 161then 162 test_ascii s2 ctrl-A-file 163else 164 test_bin s2 ctrl-A-file 165fi 166 167# Create a file which we only discover needs encoding after 168# we have read loads of it. 169remove infile ; cat long-text-file ctrl-A-file > infile 170if $TESTING_SCCS_V6 171then 172 test_ascii s3 infile 173else 174 test_bin s3 infile 175fi 176 177# Another long file but binary because it lacks a newline at the end. 178if $TESTING_SCCS_V6 179then 180 test_ascii s4 ctrl-A-end 181else 182 test_bin s4 ctrl-A-end 183fi 184 185use_stdin=true 186 187 188## Same tests as before, but with the "-i" file on a pipe. 189 190 191 192if $TESTING_CSSC 193then 194 # Do the tests that SCCS does not pass. 195 use_stdin=false 196 197 if $TESTING_SCCS_V6 198 then 199 test_ascii s5 no-newline # Real SCCS fails this one. 200 else 201 test_bin s5 no-newline # Real SCCS fails this one. 202 fi 203 204 remove infile ; cat long-text-file no-newline > infile 205 if $TESTING_SCCS_V6 206 then 207 test_ascii s6 infile 208 else 209 test_bin s6 infile 210 fi 211 212 use_stdin=true 213 if $TESTING_SCCS_V6 214 then 215 test_ascii i1 ctrl-A-file 216 test_ascii i2 infile 217 else 218 test_bin i1 ctrl-A-file 219 test_bin i2 infile 220 fi 221 remove infile ; cat long-text-file ctrl-A-file > infile 222 if $TESTING_SCCS_V6 223 then 224 test_ascii i3 ctrl-A-end 225 test_ascii i4 no-newline 226 else 227 test_bin i3 ctrl-A-end 228 test_bin i4 no-newline 229 fi 230 231 remove infile ; cat long-text-file no-newline > infile 232 if $TESTING_SCCS_V6 233 then 234 test_ascii i5 infile 235 else 236 test_bin i5 infile 237 fi 238else 239 echo "Not running tests on CSSC; Some tests have been been omitted" 240fi 241 242remove $files long-text-file infile ctrl-A-file no-newline ctrl-A-end 243remove command.log log base errmsg $g 244success 245