File: dictzip_test.in

package info (click to toggle)
dictd 1.13.1%2Bdfsg-1.1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 3,940 kB
  • sloc: ansic: 12,523; sh: 4,435; yacc: 512; makefile: 442; cpp: 277; lex: 256; perl: 175; awk: 12
file content (77 lines) | stat: -rwxr-xr-x 1,397 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/sh

set -e

export LC_ALL=C

DICTZIP=${DICTZIP-../dictzip}

gen_file (){
    # $1 - size
#    if test -c /dev/urandom -o -b /dev/urandom; then
#	dd if=/dev/urandom bs=1 count=$1 2>/dev/null
#	return 0
#    fi

    @AWK@ -v sz="$1" '
    BEGIN {
        c = 1
        for (i=0; i < sz; ++i) {
            printf "%c", c
            ++c
            if (c == 253) # not 256
                c = 1
        }
    }'
}

list_tests (){
    # output: filesize step
    cat <<'EOF'
116630 11663
1000000 500000
100000 25000
10000 250
0 1
1 1
10 1
100 1
1000 25
EOF
}

gen_regions (){
    # $1 - size
    # $2 - step
    @AWK@ -v size="$1" -v step="$2" '
    BEGIN {
        for (i=0; i < size; i += step)
            for (j=i+step; j <= size; j += step)
                print i, j-i
        exit 0
    }'
}

echo '                       DICTZIP!!!'
list_tests |
while read size step; do
    echo "test: bytes - $size, step - $step"

    gen_file "$size" > _input
    $DICTZIP -ck _input > _input.dz

    gen_regions "$size" "$step" |
    while read skip count; do
	dd if=_input bs=1 skip="$skip" count="$count" of=_region1 2>/dev/null || true
	printf '' >> _region1
	$DICTZIP -dc -s "$skip" -e "$count" _input.dz > _region2
	if ! cmp _region1 _region2; then
	    cat <<EOF
Uncompressing region ($skip, $count) failed,
please report a bug!
http://sf.net/projects/dict
EOF
	    exit 1
	fi
    done
done