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

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

Rewrite zzcat to make it a lot more configurable.

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