Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
Denys Vlasenko | c0e37b4 | 2011-10-31 01:08:35 +0100 | [diff] [blame] | 3 | FAILCOUNT=0 |
Dan Fandrich | 140ac91 | 2010-08-29 04:47:03 +0200 | [diff] [blame] | 4 | |
Denys Vlasenko | c0e37b4 | 2011-10-31 01:08:35 +0100 | [diff] [blame] | 5 | bb="busybox " |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 6 | |
Denys Vlasenko | c0e37b4 | 2011-10-31 01:08:35 +0100 | [diff] [blame] | 7 | unset LC_ALL |
| 8 | unset LC_MESSAGES |
| 9 | unset LANG |
| 10 | unset LANGUAGE |
Denis Vlasenko | ab9eef2 | 2007-03-07 22:02:23 +0000 | [diff] [blame] | 11 | |
Thiago Jung Bauermann | 17b1622 | 2015-05-11 17:18:59 +0200 | [diff] [blame] | 12 | hello_Z() { |
| 13 | # Compressed "HELLO\n" |
| 14 | $ECHO -ne "\x1f\x9d\x90\x48\x8a\x30\x61\xf2\x44\x01" |
| 15 | } |
| 16 | |
Denys Vlasenko | c0e37b4 | 2011-10-31 01:08:35 +0100 | [diff] [blame] | 17 | hello_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 | |
| 24 | hello_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 Bauermann | 17b1622 | 2015-05-11 17:18:59 +0200 | [diff] [blame] | 31 | for ext in gz bz2 Z |
| 32 | do |
| 33 | prep() { |
| 34 | rm -f t1.$ext t2.$ext t_actual |
| 35 | hello_$ext >t1.$ext |
| 36 | hello_$ext >t2.$ext |
| 37 | } |
Denys Vlasenko | c0e37b4 | 2011-10-31 01:08:35 +0100 | [diff] [blame] | 38 | |
Thiago Jung Bauermann | 17b1622 | 2015-05-11 17:18:59 +0200 | [diff] [blame] | 39 | 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 Vlasenko | c0e37b4 | 2011-10-31 01:08:35 +0100 | [diff] [blame] | 48 | |
Thiago Jung Bauermann | 17b1622 | 2015-05-11 17:18:59 +0200 | [diff] [blame] | 49 | mkdir testdir 2>/dev/null |
| 50 | ( |
| 51 | cd testdir || { echo "cannot cd testdir!"; exit 1; } |
Denys Vlasenko | c0e37b4 | 2011-10-31 01:08:35 +0100 | [diff] [blame] | 52 | |
Thiago Jung Bauermann | 17b1622 | 2015-05-11 17:18:59 +0200 | [diff] [blame] | 53 | expected="HELLO\nok\n" |
| 54 | prep; check "zcat: dont delete $ext src" "${bb}zcat t2.$ext; test -f t2.$ext && echo ok" |
Denys Vlasenko | c0e37b4 | 2011-10-31 01:08:35 +0100 | [diff] [blame] | 55 | |
Thiago Jung Bauermann | 17b1622 | 2015-05-11 17:18:59 +0200 | [diff] [blame] | 56 | ) |
| 57 | rm -rf testdir |
| 58 | done |
Denys Vlasenko | bcdae63 | 2011-10-31 01:10:47 +0100 | [diff] [blame] | 59 | |
| 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 Bauermann | 17b1622 | 2015-05-11 17:18:59 +0200 | [diff] [blame] | 68 | ## bzip algorithm |
| 69 | |
Denys Vlasenko | bcdae63 | 2011-10-31 01:10:47 +0100 | [diff] [blame] | 70 | # "input" file is bzipped file with "a\n" data |
| 71 | testing "bzcat can print many files" \ |
| 72 | "$ECHO -ne '$hexdump' | bzcat input input; echo \$?" \ |
| 73 | "\ |
| 74 | a |
| 75 | a |
| 76 | 0 |
| 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 |
| 84 | testing "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 Bauermann | 17b1622 | 2015-05-11 17:18:59 +0200 | [diff] [blame] | 89 | ## compress algorithm |
| 90 | |
| 91 | # "input" file is compressed (.Z) file with "a\n" data |
| 92 | testing "zcat can print many files" \ |
| 93 | "$ECHO -ne '$hexdump' | zcat input input; echo \$?" \ |
| 94 | "\ |
| 95 | a |
| 96 | a |
| 97 | 0 |
| 98 | " "\ |
| 99 | \x1f\x9d\x90\x61\x14\x00\ |
| 100 | " "" |
| 101 | |
| 102 | # "input" file is compressed (.Z) zero byte file |
| 103 | testing "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 Vlasenko | bcdae63 | 2011-10-31 01:10:47 +0100 | [diff] [blame] | 108 | |
| 109 | |
Denys Vlasenko | c0e37b4 | 2011-10-31 01:08:35 +0100 | [diff] [blame] | 110 | exit $((FAILCOUNT <= 255 ? FAILCOUNT : 255)) |