source: zzuf/trunk/test/check-utils @ 4124

Last change on this file since 4124 was 4124, checked in by Sam Hocevar, 12 years ago

Make the check-utils output slightly clearer.

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 4.7 KB
Line 
1#!/bin/sh
2
3. "$(dirname "$0")/functions.inc"
4
5checkutils()
6{
7    r=$1
8    for type in 00 ff text random; do
9        file="$DIR/file-$type"
10        ZZOPTS="-s $seed -r $r"
11        case $file in
12          *text*) ZZOPTS="$ZZOPTS -P '\\n' -R '\\000'" ;;
13        esac
14        echo "*** file $file, ratio $r ***"
15        REFMD5=""
16        if [ $r = 0.0 -a $type = 00 ]; then
17            check="bb7df04e1b0a2570657527a7e108ae23"
18            echo "*** should be $check ***"
19            check "$ZZOPTS" "< $file" "zzuf" "$check"
20        else
21            check "$ZZOPTS" "< $file" "zzuf"
22        fi
23        if [ "$STATIC_CAT" = "" ]; then
24            check "$ZZOPTS" "cat $file" "cat"
25            check "$ZZOPTS" "-i cat < $file" "|cat"
26        fi
27        if [ "$STATIC_DD" = "" ]; then
28            check "$ZZOPTS" "dd bs=65536 if=$file" "dd(bs=65536)"
29            check "$ZZOPTS" "dd bs=1111 if=$file" "dd(bs=1111)"
30            check "$ZZOPTS" "dd bs=1024 if=$file" "dd(bs=1024)"
31            check "$ZZOPTS" "dd bs=1 if=$file" "dd(bs=1)"
32        fi
33        case $file in
34          *text*)
35            # We don't include grep or sed when the input is not text, because
36            # they put a newline at the end of their input if it was not there
37            # initially. (Linux sed doesn't, but OS X sed does.)
38            check "$ZZOPTS" "head -n 9999 $file" "head -n 9999"
39            check "$ZZOPTS" "${TAILN}9999 $file" "${TAILN}9999"
40            check "$ZZOPTS" "${TAILP}1 $file" "${TAILP}1"
41            if grep -a '' /dev/null >/dev/null 2>&1; then
42                check "$ZZOPTS" "grep -a '' $file" "grep -a ''"
43            fi
44            check "$ZZOPTS" "sed -e n $file" "sed -e n"
45            #check "$ZZOPTS" "cut -b1- $file" "cut -b1-"
46            check "$ZZOPTS" "-i head -n 9999 < $file" "|head -n 9999"
47            check "$ZZOPTS" "-i ${TAILN}9999 < $file" "|${TAILN}9999"
48            check "$ZZOPTS" "-i ${TAILP}1 < $file" "|${TAILP}1"
49            if grep -a '' /dev/null >/dev/null 2>&1; then
50                check "$ZZOPTS" "-i grep -a '' < $file" "|grep -a ''"
51            fi
52            check "$ZZOPTS" "-i sed -e n < $file" "|sed -e n"
53            #check "$ZZOPTS" "-i cut -b1- < $file" "|cut -b1-"
54            ;;
55        esac
56        for n in \
57          "fread(1,33000)" \
58          "repeat(33,fread(1,1000))" \
59          "repeat(1000,fread(1,33))" \
60          "getc() fread(1,33000)" \
61          "getc_unlocked() fread(1,33000)" \
62          "fgetc() fread(1,33000)" \
63          "fgetc_unlocked() fread(1,33000)" \
64          "getc() ungetc() fread(1,33000)" \
65          "getc_unlocked() ungetc() fread(1,33000)" \
66          "fgetc() ungetc() fread(1,33000)" \
67          "fgetc_unlocked() ungetc() fread(1,33000)" \
68          "repeat(33000,getc())" \
69          "repeat(33000,getc_unlocked())" \
70          "repeat(33000,fgetc())" \
71          "repeat(33000,fgetc_unlocked())" \
72          "repeat(8000,getc()) fread(1,33000)" \
73          "repeat(8000,getc_unlocked()) fread(1,33000)" \
74          "repeat(8000,fgetc()) fread(1,33000)" \
75          "repeat(8000,fgetc_unlocked()) fread(1,33000)" \
76          "repeat(10,getline()) fread(1,33000)" \
77          "repeat(10,getdelim(0)) fread(1,33000)" \
78          "repeat(10,getdelim(' ')) fread(1,33000)" \
79          "fread(1,100) fseek(50,SEEK_SET) fread(1,33000)" \
80          "fread(1,100) rewind() fseek(50,SEEK_CUR) fread(1,33000)" \
81          "fread(1,33000) rewind() repeat(10000,fseek(1,SEEK_CUR) fread(1,1))" \
82          "fread(1,33000) rewind() repeat(10000,fseek(2,SEEK_CUR) fread(1,2))" \
83          "fread(1,33000) rewind() repeat(10000,fseek(3,SEEK_CUR) fread(1,3))" \
84          "fread(1,33000) rewind() repeat(10000,fseek(4,SEEK_CUR) fread(1,4))" \
85          "repeat(33000,getc() ungetc() getline())" \
86          "repeat(33000,fgetc() ungetc() getline())" \
87          "repeat(33000,getc_unlocked() ungetc() getline())" \
88          "fread(1,33000) fseek(1000,SEEK_CUR) repeat(10000,fread(1,2))" \
89          "fread(1,33000) fseek(1000,SEEK_CUR) repeat(10000,getc())" \
90          "fread(1,33000) fseek(1000,SEEK_CUR) repeat(10000,fgetc())" \
91          "fread(1,33000) fseek(1000,SEEK_CUR) repeat(10000,getc_unlocked())" \
92          ; do
93            check "$ZZOPTS" "$ZZCAT \"$n\" $file" "$n"
94        done
95    done
96}
97
98check()
99{
100    ZZOPTS="$1"
101    CMD="$2"
102    ALIAS="$3"
103    CHECK="$4"
104    printf " $(echo "$ALIAS .................................." | cut -b1-38) "
105    MD5="$(eval "$ZZUF -m $ZZOPTS $CMD" 2>/dev/null | cut -f2 -d' ')"
106    if [ -n "$CHECK" ]; then
107        REFMD5="$CHECK"
108    fi
109    if [ -z "$REFMD5" ]; then
110        REFMD5="$MD5"
111        echo "$MD5"
112    elif [ "$MD5" != "$REFMD5" ]; then
113        fail_test "$MD5 FAILED"
114    else
115        pass_test 'ok'
116    fi
117}
118
119start_test "zzuf utils test suite"
120
121checkutils 0.0
122checkutils 0.001
123checkutils 1.0
124
125stop_test
126
Note: See TracBrowser for help on using the repository browser.