blob: 9a1c28425a214521e1409fb2efbddd8b129a5a1c [file] [log] [blame]
Denis Vlasenkoab9eef22007-03-07 22:02:23 +00001#!/bin/sh
2
Denys Vlasenkoc0e37b42011-10-31 01:08:35 +01003FAILCOUNT=0
Dan Fandrich140ac912010-08-29 04:47:03 +02004
Denys Vlasenkoc0e37b42011-10-31 01:08:35 +01005bb="busybox "
Denis Vlasenkoab9eef22007-03-07 22:02:23 +00006
Denys Vlasenkoc0e37b42011-10-31 01:08:35 +01007unset LC_ALL
8unset LC_MESSAGES
9unset LANG
10unset LANGUAGE
Denis Vlasenkoab9eef22007-03-07 22:02:23 +000011
Thiago Jung Bauermann17b16222015-05-11 17:18:59 +020012hello_Z() {
13 # Compressed "HELLO\n"
14 $ECHO -ne "\x1f\x9d\x90\x48\x8a\x30\x61\xf2\x44\x01"
15}
16
Denys Vlasenkoc0e37b42011-10-31 01:08:35 +010017hello_gz() {
18 # Gzipped "HELLO\n"
19 #_________________________ vvv vvv vvv vvv - mtime
20 $ECHO -ne "\x1f\x8b\x08\x00\x85\x1d\xef\x45\x02\x03\xf3\x70\xf5\xf1\xf1\xe7"
21 $ECHO -ne "\x02\x00\x6e\xd7\xac\xfd\x06\x00\x00\x00"
22}
23
24hello_bz2() {
25 # Bzipped "HELLO\n"
26 $ECHO -ne "\x42\x5a\x68\x39\x31\x41\x59\x26\x53\x59\x5b\xb8\xe8\xa3\x00\x00"
27 $ECHO -ne "\x01\x44\x00\x00\x10\x02\x44\xa0\x00\x30\xcd\x00\xc3\x46\x29\x97"
28 $ECHO -ne "\x17\x72\x45\x38\x50\x90\x5b\xb8\xe8\xa3"
29}
30
Thiago Jung Bauermann17b16222015-05-11 17:18:59 +020031for ext in gz bz2 Z
32do
33 prep() {
34 rm -f t1.$ext t2.$ext t_actual
35 hello_$ext >t1.$ext
36 hello_$ext >t2.$ext
37 }
Denys Vlasenkoc0e37b42011-10-31 01:08:35 +010038
Thiago Jung Bauermann17b16222015-05-11 17:18:59 +020039 check() {
40 eval $2 >t_actual 2>&1
41 if $ECHO -ne "$expected" | cmp - t_actual; then
42 echo "PASS: $1"
43 else
44 echo "FAIL: $1"
45 FAILCOUNT=$((FAILCOUNT + 1))
46 fi
47 }
Denys Vlasenkoc0e37b42011-10-31 01:08:35 +010048
Thiago Jung Bauermann17b16222015-05-11 17:18:59 +020049 mkdir testdir 2>/dev/null
50 (
51 cd testdir || { echo "cannot cd testdir!"; exit 1; }
Denys Vlasenkoc0e37b42011-10-31 01:08:35 +010052
Thiago Jung Bauermann17b16222015-05-11 17:18:59 +020053 expected="HELLO\nok\n"
54 prep; check "zcat: dont delete $ext src" "${bb}zcat t2.$ext; test -f t2.$ext && echo ok"
Denys Vlasenkoc0e37b42011-10-31 01:08:35 +010055
Thiago Jung Bauermann17b16222015-05-11 17:18:59 +020056 )
57 rm -rf testdir
58done
Denys Vlasenkobcdae632011-10-31 01:10:47 +010059
60
61# Copyright 2011 by Denys Vlasenko
62# Licensed under GPLv2, see file LICENSE in this source tree.
63
64. ./testing.sh
65
66# testing "test name" "command" "expected result" "file input" "stdin"
67
Thiago Jung Bauermann17b16222015-05-11 17:18:59 +020068## bzip algorithm
69
Denys Vlasenkobcdae632011-10-31 01:10:47 +010070# "input" file is bzipped file with "a\n" data
71testing "bzcat can print many files" \
72"$ECHO -ne '$hexdump' | bzcat input input; echo \$?" \
73"\
74a
75a
760
77" "\
78\x42\x5a\x68\x39\x31\x41\x59\x26\x53\x59\x63\x3e\xd6\xe2\x00\x00\
79\x00\xc1\x00\x00\x10\x20\x00\x20\x00\x21\x00\x82\xb1\x77\x24\x53\
80\x85\x09\x06\x33\xed\x6e\x20\
81" ""
82
83# "input" file is bzipped zero byte file
84testing "bzcat can handle compressed zero-length bzip2 files" \
85"$ECHO -ne '$hexdump' | bzcat input input; echo \$?" \
86"0\n" \
87"\x42\x5a\x68\x39\x17\x72\x45\x38\x50\x90\x00\x00\x00\x00" ""
88
Thiago Jung Bauermann17b16222015-05-11 17:18:59 +020089## compress algorithm
90
91# "input" file is compressed (.Z) file with "a\n" data
92testing "zcat can print many files" \
93"$ECHO -ne '$hexdump' | zcat input input; echo \$?" \
94"\
95a
96a
970
98" "\
99\x1f\x9d\x90\x61\x14\x00\
100" ""
101
102# "input" file is compressed (.Z) zero byte file
103testing "zcat can handle compressed zero-length compressed (.Z) files" \
104"$ECHO -ne '$hexdump' | zcat input input; echo \$?" \
105"0\n" \
106"\x1f\x9d\x90\x00" ""
107
Denys Vlasenkobcdae632011-10-31 01:10:47 +0100108
109
Denys Vlasenkoc0e37b42011-10-31 01:08:35 +0100110exit $((FAILCOUNT <= 255 ? FAILCOUNT : 255))