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 | |
Denys Vlasenko | 69c8c69 | 2015-10-11 16:27:55 +0200 | [diff] [blame] | 31 | for ext in \ |
Denys Vlasenko | 57aeb62 | 2015-10-12 03:15:36 +0200 | [diff] [blame] | 32 | `test x"$CONFIG_GUNZIP" = x"y" && echo gz` \ |
| 33 | `test x"$CONFIG_BUNZIP2" = x"y" && echo bz2` \ |
Denys Vlasenko | 69c8c69 | 2015-10-11 16:27:55 +0200 | [diff] [blame] | 34 | `test x"$CONFIG_UNCOMPRESS" = x"y" && echo Z` |
Thiago Jung Bauermann | 17b1622 | 2015-05-11 17:18:59 +0200 | [diff] [blame] | 35 | do |
| 36 | prep() { |
| 37 | rm -f t1.$ext t2.$ext t_actual |
| 38 | hello_$ext >t1.$ext |
| 39 | hello_$ext >t2.$ext |
| 40 | } |
Denys Vlasenko | c0e37b4 | 2011-10-31 01:08:35 +0100 | [diff] [blame] | 41 | |
Thiago Jung Bauermann | 17b1622 | 2015-05-11 17:18:59 +0200 | [diff] [blame] | 42 | check() { |
| 43 | eval $2 >t_actual 2>&1 |
| 44 | if $ECHO -ne "$expected" | cmp - t_actual; then |
| 45 | echo "PASS: $1" |
| 46 | else |
| 47 | echo "FAIL: $1" |
| 48 | FAILCOUNT=$((FAILCOUNT + 1)) |
| 49 | fi |
| 50 | } |
Denys Vlasenko | c0e37b4 | 2011-10-31 01:08:35 +0100 | [diff] [blame] | 51 | |
Thiago Jung Bauermann | 17b1622 | 2015-05-11 17:18:59 +0200 | [diff] [blame] | 52 | mkdir testdir 2>/dev/null |
| 53 | ( |
| 54 | cd testdir || { echo "cannot cd testdir!"; exit 1; } |
Thiago Jung Bauermann | 17b1622 | 2015-05-11 17:18:59 +0200 | [diff] [blame] | 55 | expected="HELLO\nok\n" |
Denys Vlasenko | 69c8c69 | 2015-10-11 16:27:55 +0200 | [diff] [blame] | 56 | prep |
| 57 | check "zcat: dont delete $ext src" "${bb}zcat t2.$ext; test -f t2.$ext && echo ok" |
| 58 | exit $FAILCOUNT |
Thiago Jung Bauermann | 17b1622 | 2015-05-11 17:18:59 +0200 | [diff] [blame] | 59 | ) |
Denys Vlasenko | 69c8c69 | 2015-10-11 16:27:55 +0200 | [diff] [blame] | 60 | FAILCOUNT=$? |
Thiago Jung Bauermann | 17b1622 | 2015-05-11 17:18:59 +0200 | [diff] [blame] | 61 | rm -rf testdir |
| 62 | done |
Denys Vlasenko | bcdae63 | 2011-10-31 01:10:47 +0100 | [diff] [blame] | 63 | |
| 64 | |
| 65 | # Copyright 2011 by Denys Vlasenko |
| 66 | # Licensed under GPLv2, see file LICENSE in this source tree. |
| 67 | |
| 68 | . ./testing.sh |
| 69 | |
| 70 | # testing "test name" "command" "expected result" "file input" "stdin" |
| 71 | |
Thiago Jung Bauermann | 17b1622 | 2015-05-11 17:18:59 +0200 | [diff] [blame] | 72 | ## bzip algorithm |
| 73 | |
Denys Vlasenko | bcdae63 | 2011-10-31 01:10:47 +0100 | [diff] [blame] | 74 | # "input" file is bzipped file with "a\n" data |
| 75 | testing "bzcat can print many files" \ |
| 76 | "$ECHO -ne '$hexdump' | bzcat input input; echo \$?" \ |
| 77 | "\ |
| 78 | a |
| 79 | a |
| 80 | 0 |
| 81 | " "\ |
| 82 | \x42\x5a\x68\x39\x31\x41\x59\x26\x53\x59\x63\x3e\xd6\xe2\x00\x00\ |
| 83 | \x00\xc1\x00\x00\x10\x20\x00\x20\x00\x21\x00\x82\xb1\x77\x24\x53\ |
| 84 | \x85\x09\x06\x33\xed\x6e\x20\ |
| 85 | " "" |
| 86 | |
| 87 | # "input" file is bzipped zero byte file |
| 88 | testing "bzcat can handle compressed zero-length bzip2 files" \ |
| 89 | "$ECHO -ne '$hexdump' | bzcat input input; echo \$?" \ |
| 90 | "0\n" \ |
| 91 | "\x42\x5a\x68\x39\x17\x72\x45\x38\x50\x90\x00\x00\x00\x00" "" |
| 92 | |
Thiago Jung Bauermann | 17b1622 | 2015-05-11 17:18:59 +0200 | [diff] [blame] | 93 | ## compress algorithm |
| 94 | |
| 95 | # "input" file is compressed (.Z) file with "a\n" data |
Denys Vlasenko | 69c8c69 | 2015-10-11 16:27:55 +0200 | [diff] [blame] | 96 | test x"$CONFIG_UNCOMPRESS" = x"y" && \ |
Thiago Jung Bauermann | 17b1622 | 2015-05-11 17:18:59 +0200 | [diff] [blame] | 97 | testing "zcat can print many files" \ |
| 98 | "$ECHO -ne '$hexdump' | zcat input input; echo \$?" \ |
| 99 | "\ |
| 100 | a |
| 101 | a |
| 102 | 0 |
| 103 | " "\ |
| 104 | \x1f\x9d\x90\x61\x14\x00\ |
| 105 | " "" |
| 106 | |
| 107 | # "input" file is compressed (.Z) zero byte file |
Denys Vlasenko | 69c8c69 | 2015-10-11 16:27:55 +0200 | [diff] [blame] | 108 | test x"$CONFIG_UNCOMPRESS" = x"y" && \ |
| 109 | testing "zcat can handle compressed zero-length (.Z) files" \ |
Thiago Jung Bauermann | 17b1622 | 2015-05-11 17:18:59 +0200 | [diff] [blame] | 110 | "$ECHO -ne '$hexdump' | zcat input input; echo \$?" \ |
| 111 | "0\n" \ |
| 112 | "\x1f\x9d\x90\x00" "" |
| 113 | |
Denys Vlasenko | bcdae63 | 2011-10-31 01:10:47 +0100 | [diff] [blame] | 114 | |
| 115 | |
Denys Vlasenko | c0e37b4 | 2011-10-31 01:08:35 +0100 | [diff] [blame] | 116 | exit $((FAILCOUNT <= 255 ? FAILCOUNT : 255)) |