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
9
10
11good() {
12    if $expect_fail ; then
13        echo UNEXPECTED PASS
14    else
15        echo passed
16    fi
17}
18
19bad() {
20    if $expect_fail ; then
21        echo failed -- but we expected that.
22    else
23        fail "$@"
24    fi
25}
26
27
28# test_bin:
29# Usage:   test_bin LABEL <contents>
30#
31# create a flie containing the specified argument and check
32# that it is encoded as a binary file.
33test_bin() {
34label=$1
35echo_nonl ${label}...
36shift
37
38rm -f infile $s
39echo_nonl "$@" > infile
40if ${vg_admin} -iinfile ${adminflags} $s >/dev/null 2>&1
41then
42    if ( ${prs} -d:FL: $s 2>/dev/null; echo foo ) | grep encoded >/dev/null 2>&1
43    then
44        good
45    else
46        bad $label input did not produce an encoded s-file.
47    fi
48else
49    bad $label ${vg_admin} returned exit status $?.
50fi
51rm -f infile $s
52}
53
54# test_ascii:
55#
56# As for test_bin, but the resulting SCCS file must NOT be encoded.
57#
58test_ascii() {
59label=$1
60echo_nonl ${label}...
61shift
62
63rm -f infile $s
64echo_nonl "$@" > infile
65if ${vg_admin} -iinfile ${adminflags} $s >/dev/null 2>&1
66then
67    if ( ${prt} -f $s 2>/dev/null ; echo foo ) | grep encoded >/dev/null 2>&1
68    then
69        bad $label input produced an encoded s-file and should not have.
70    else
71        good
72    fi
73else
74    bad $label ${vg_admin} returned exit status $?.
75fi
76rm -f infile $s
77}
78
79g=testfile
80s=s.$g
81z=z.$g
82x=x.$g
83p=p.$g
84files="$s $z $x $p"
85
86remove command.log log  base [sxzp].$g
87
88expect_fail=false
89adminflags=""
90
91if $binary_support
92then
93
94test_ascii a1 "foo\n"
95test_ascii a2 "foo\nbar\n"
96test_ascii a3 ""                        # an empty input file should be OK.
97if $TESTING_SCCS_V6
98then
99  test_ascii b4 "\001\n"                # line starts with control-a
100else
101  test_bin   b4 "\001\n"                # line starts with control-a
102fi
103test_ascii a5 "x\001\n"                 # line contains ^A but doesnt start with it.
104
105adminflags=-b
106test_bin   b6 "foo\n"                   # Test manual encoding override.
107test_bin   b7 "x\000y\n"                # ASCII NUL.
108test_bin   b8 "\000"                    # Just the ASCII NUL alone.
109test_bin   b9 "\001"                    # Just the ^A alone.
110adminflags=
111
112if $TESTING_CSSC
113then
114    ## Real SCCS fails on these inputs:-
115    if $TESTING_SCCS_V6
116    then
117      test_ascii fb10 "foo"             # no newline at end of file.
118      test_ascii fa11 "x\000y\n"        # ASCII NUL.
119    else
120      test_bin   fb10 "foo"             # no newline at end of file.
121      test_bin   fa11 "x\000y\n"        # ASCII NUL.
122    fi
123    test_ascii fa12 "x\001y\n"          # ASCII SOH.
124else
125    echo "Some tests skipped (since SCCS fails them but CSSC should pass)"
126fi
127
128remove command.log $s $p $g $z $x infile
129
130else
131echo "No binary file support -- tests skipped"
132fi # binary support.
133
134success
135