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

Last change on this file since 4032 was 4030, checked in by Sam Hocevar, 11 years ago

More zzcat stuff.

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 3.0 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 100 101 102 \
24                 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 \
25                 300 301 302 303 304 305 306 307 308 309 310 311 \
26                 400 401 402 403 404 405 406 407 \
27                 500; do
28            check "$ZZOPTS" "$ZZCAT $n $file" "zzcat $n"
29        done
30        if [ "$STATIC_CAT" = "" ]; then
31            check "$ZZOPTS" "cat $file" "cat"
32            check "$ZZOPTS" "-i cat < $file" "|cat"
33        fi
34        if [ "$STATIC_DD" = "" ]; then
35            check "$ZZOPTS" "dd bs=65536 if=$file" "dd(bs=65536)"
36            check "$ZZOPTS" "dd bs=1111 if=$file" "dd(bs=1111)"
37            check "$ZZOPTS" "dd bs=1024 if=$file" "dd(bs=1024)"
38            check "$ZZOPTS" "dd bs=1 if=$file" "dd(bs=1)"
39        fi
40        case $file in
41          *text*)
42            # We don't include grep or sed when the input is not text, because
43            # they put a newline at the end of their input if it was not there
44            # initially. (Linux sed doesn't, but OS X sed does.)
45            check "$ZZOPTS" "head -n 9999 $file" "head -n 9999"
46            check "$ZZOPTS" "${TAILN}9999 $file" "${TAILN}9999"
47            check "$ZZOPTS" "${TAILP}1 $file" "${TAILP}1"
48            if grep -a '' /dev/null >/dev/null 2>&1; then
49                check "$ZZOPTS" "grep -a '' $file" "grep -a ''"
50            fi
51            check "$ZZOPTS" "sed -e n $file" "sed -e n"
52            #check "$ZZOPTS" "cut -b1- $file" "cut -b1-"
53            check "$ZZOPTS" "-i head -n 9999 < $file" "|head -n 9999"
54            check "$ZZOPTS" "-i ${TAILN}9999 < $file" "|${TAILN}9999"
55            check "$ZZOPTS" "-i ${TAILP}1 < $file" "|${TAILP}1"
56            if grep -a '' /dev/null >/dev/null 2>&1; then
57                check "$ZZOPTS" "-i grep -a '' < $file" "|grep -a ''"
58            fi
59            check "$ZZOPTS" "-i sed -e n < $file" "|sed -e n"
60            #check "$ZZOPTS" "-i cut -b1- < $file" "|cut -b1-"
61            ;;
62        esac
63    done
64}
65
66check()
67{
68    ZZOPTS="$1"
69    CMD="$2"
70    ALIAS="$3"
71    CHECK="$4"
72    printf " $(echo "$ALIAS .............." | cut -b1-18) "
73    MD5="$(eval "$ZZUF -m $ZZOPTS $CMD" 2>/dev/null | cut -f2 -d' ')"
74    if [ -n "$CHECK" ]; then
75        REFMD5="$CHECK"
76    fi
77    if [ -z "$REFMD5" ]; then
78        REFMD5="$MD5"
79        echo "$MD5"
80    elif [ "$MD5" != "$REFMD5" ]; then
81        fail_test "$MD5 FAILED"
82    else
83        pass_test 'ok'
84    fi
85}
86
87start_test "zzuf utils test suite"
88
89checkutils 0.0
90checkutils 0.001
91checkutils 1.0
92
93stop_test
94
Note: See TracBrowser for help on using the repository browser.