bzcat.tests 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #!/bin/sh
  2. FAILCOUNT=0
  3. bb="busybox "
  4. unset LC_ALL
  5. unset LC_MESSAGES
  6. unset LANG
  7. unset LANGUAGE
  8. hello_Z() {
  9. # Compressed "HELLO\n"
  10. $ECHO -ne "\x1f\x9d\x90\x48\x8a\x30\x61\xf2\x44\x01"
  11. }
  12. hello_gz() {
  13. # Gzipped "HELLO\n"
  14. #_________________________ vvv vvv vvv vvv - mtime
  15. $ECHO -ne "\x1f\x8b\x08\x00\x85\x1d\xef\x45\x02\x03\xf3\x70\xf5\xf1\xf1\xe7"
  16. $ECHO -ne "\x02\x00\x6e\xd7\xac\xfd\x06\x00\x00\x00"
  17. }
  18. hello_bz2() {
  19. # Bzipped "HELLO\n"
  20. $ECHO -ne "\x42\x5a\x68\x39\x31\x41\x59\x26\x53\x59\x5b\xb8\xe8\xa3\x00\x00"
  21. $ECHO -ne "\x01\x44\x00\x00\x10\x02\x44\xa0\x00\x30\xcd\x00\xc3\x46\x29\x97"
  22. $ECHO -ne "\x17\x72\x45\x38\x50\x90\x5b\xb8\xe8\xa3"
  23. }
  24. for ext in \
  25. `test x"$CONFIG_GUNZIP" = x"y" && echo gz` \
  26. `test x"$CONFIG_BUNZIP2" = x"y" && echo bz2` \
  27. `test x"$CONFIG_UNCOMPRESS" = x"y" && echo Z`
  28. do
  29. prep() {
  30. rm -f t1.$ext t2.$ext t_actual
  31. hello_$ext >t1.$ext
  32. hello_$ext >t2.$ext
  33. }
  34. check() {
  35. eval $2 >t_actual 2>&1
  36. if $ECHO -ne "$expected" | cmp - t_actual; then
  37. echo "PASS: $1"
  38. else
  39. echo "FAIL: $1"
  40. FAILCOUNT=$((FAILCOUNT + 1))
  41. fi
  42. }
  43. mkdir testdir 2>/dev/null
  44. (
  45. cd testdir || { echo "cannot cd testdir!"; exit 1; }
  46. expected="HELLO\nok\n"
  47. prep
  48. check "zcat: dont delete $ext src" "${bb}zcat t2.$ext; test -f t2.$ext && echo ok"
  49. exit $FAILCOUNT
  50. )
  51. FAILCOUNT=$?
  52. rm -rf testdir
  53. done
  54. # Copyright 2011 by Denys Vlasenko
  55. # Licensed under GPLv2, see file LICENSE in this source tree.
  56. . ./testing.sh
  57. # testing "test name" "command" "expected result" "file input" "stdin"
  58. ## bzip algorithm
  59. # "input" file is bzipped file with "a\n" data
  60. testing "bzcat can print many files" \
  61. "$ECHO -ne '$hexdump' | bzcat input input; echo \$?" \
  62. "\
  63. a
  64. a
  65. 0
  66. " "\
  67. \x42\x5a\x68\x39\x31\x41\x59\x26\x53\x59\x63\x3e\xd6\xe2\x00\x00\
  68. \x00\xc1\x00\x00\x10\x20\x00\x20\x00\x21\x00\x82\xb1\x77\x24\x53\
  69. \x85\x09\x06\x33\xed\x6e\x20\
  70. " ""
  71. # "input" file is bzipped zero byte file
  72. testing "bzcat can handle compressed zero-length bzip2 files" \
  73. "$ECHO -ne '$hexdump' | bzcat input input; echo \$?" \
  74. "0\n" \
  75. "\x42\x5a\x68\x39\x17\x72\x45\x38\x50\x90\x00\x00\x00\x00" ""
  76. ## compress algorithm
  77. # "input" file is compressed (.Z) file with "a\n" data
  78. test x"$CONFIG_UNCOMPRESS" = x"y" && \
  79. testing "zcat can print many files" \
  80. "$ECHO -ne '$hexdump' | zcat input input; echo \$?" \
  81. "\
  82. a
  83. a
  84. 0
  85. " "\
  86. \x1f\x9d\x90\x61\x14\x00\
  87. " ""
  88. # "input" file is compressed (.Z) zero byte file
  89. test x"$CONFIG_UNCOMPRESS" = x"y" && \
  90. testing "zcat can handle compressed zero-length (.Z) files" \
  91. "$ECHO -ne '$hexdump' | zcat input input; echo \$?" \
  92. "0\n" \
  93. "\x1f\x9d\x90\x00" ""
  94. exit $((FAILCOUNT <= 255 ? FAILCOUNT : 255))