bzcat.tests 2.8 KB

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