bunzip2.tests 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/bin/sh
  2. if test "${0##*/}" = "gunzip.tests"; then
  3. unpack=gunzip
  4. ext=gz
  5. elif test "${0##*/}" = "bunzip2.tests"; then
  6. unpack=bunzip2
  7. ext=bz2
  8. else
  9. echo "WTF? argv0='$0'"
  10. exit 1
  11. fi
  12. bb="busybox "
  13. unset LC_ALL
  14. unset LC_MESSAGES
  15. unset LANG
  16. unset LANGUAGE
  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. hello_bz2() {
  24. # Bzipped "HELLO\n"
  25. echo -ne "\x42\x5a\x68\x39\x31\x41\x59\x26\x53\x59\x5b\xb8\xe8\xa3\x00\x00"
  26. echo -ne "\x01\x44\x00\x00\x10\x02\x44\xa0\x00\x30\xcd\x00\xc3\x46\x29\x97"
  27. echo -ne "\x17\x72\x45\x38\x50\x90\x5b\xb8\xe8\xa3"
  28. }
  29. prep() {
  30. rm -f t*
  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 "$1: PASS"
  38. else
  39. echo "$1: FAIL"
  40. fi
  41. }
  42. mkdir testdir 2>/dev/null
  43. (
  44. cd testdir || { echo "cannot cd testdir!"; exit 1; }
  45. expected="$unpack: z: No such file or directory
  46. 1
  47. HELLO
  48. "
  49. prep; check "$unpack: doesnt exist" "${bb}$unpack z t1.$ext; echo \$?; cat t1"
  50. expected="$unpack: t.zz: unknown suffix - ignored
  51. 1
  52. HELLO
  53. "
  54. prep; >t.zz; check "$unpack: unknown suffix" "${bb}$unpack t.zz t1.$ext; echo \$?; cat t1"
  55. # In this case file "t1" exists, and we skip t1.gz and unpack t2.gz
  56. expected="$unpack: can't open 't1': File exists
  57. 1
  58. HELLO
  59. "
  60. prep; >t1; check "$unpack: already exists" "${bb}$unpack t1.$ext t2.$ext; echo \$?; cat t1 t2"
  61. # From old testsuite
  62. expected="HELLO\n0\n"
  63. prep; check "$unpack: stream unpack" "cat t1.$ext | ${bb}$unpack; echo $?"
  64. expected="ok\n"
  65. prep; check "$unpack: delete src" "${bb}$unpack t2.$ext; test ! -f t2.$ext && echo ok"
  66. )
  67. rm -rf testdir