unzip.test 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #!/bin/bash
  2. [ -f testing.sh ] && . testing.sh
  3. #testing "name" "command" "result" "infile" "stdin"
  4. # Note: since "master key", Android uses libziparchive for all zip file
  5. # handling, and that scans the whole central directory immediately. Not only
  6. # lookups by name but also iteration is implemented using the resulting hash
  7. # table, meaning that any test that makes assumptions about iteration order
  8. # will fail on Android.
  9. # unzip -l
  10. testing "-l" "unzip -l $FILES/zip/example.zip d1/d2/x.txt && [ ! -f d1/d2/x.txt ] && echo okay" "\
  11. Archive: $FILES/zip/example.zip\n\
  12. Length Date Time Name\n\
  13. --------- ---------- ----- ----\n\
  14. 1024 2017-06-04 08:45 d1/d2/x.txt\n\
  15. --------- -------\n\
  16. 1024 1 file\n\
  17. okay\n" "" ""
  18. # unzip -lq
  19. testing "-lq" "unzip -lq $FILES/zip/example.zip d1/d2/x.txt && [ ! -f d1/d2/x.txt ] && echo okay" "\
  20. Length Date Time Name\n\
  21. --------- ---------- ----- ----\n\
  22. 1024 2017-06-04 08:45 d1/d2/x.txt\n\
  23. --------- -------\n\
  24. 1024 1 file\n\
  25. okay\n" "" ""
  26. # unzip -lv
  27. testing "-lv" "unzip -lv $FILES/zip/example.zip d1/d2/x.txt && [ ! -f d1/d2/file ] && echo okay" "\
  28. Archive: $FILES/zip/example.zip\n\
  29. Length Method Size Cmpr Date Time CRC-32 Name\n\
  30. -------- ------ ------- ---- ---------- ----- -------- ----\n\
  31. 1024 Defl:N 11 99% 2017-06-04 08:45 48d7f063 d1/d2/x.txt\n\
  32. -------- ------- --- -------\n\
  33. 1024 11 99% 1 file\n\
  34. okay\n" "" ""
  35. # unzip -v
  36. testing "-v" "unzip -v $FILES/zip/example.zip d1/d2/x.txt && [ ! -f d1/d2/file ] && echo okay" "\
  37. Archive: $FILES/zip/example.zip\n\
  38. Length Method Size Cmpr Date Time CRC-32 Name\n\
  39. -------- ------ ------- ---- ---------- ----- -------- ----\n\
  40. 1024 Defl:N 11 99% 2017-06-04 08:45 48d7f063 d1/d2/x.txt\n\
  41. -------- ------- --- -------\n\
  42. 1024 11 99% 1 file\n\
  43. okay\n" "" ""
  44. # unzip
  45. testing "one file" "unzip -q $FILES/zip/example.zip d1/d2/a.txt && [ ! -f d1/d2/b.txt ] && cat d1/d2/a.txt" "a\n" "" ""
  46. rm -rf d1
  47. testing "all files" "unzip -q $FILES/zip/example.zip && [ -f d1/d2/a.txt ] && [ -f d1/d2/b.txt ] && [ -f d1/d2/c.txt ] && [ -f d1/d2/empty.txt ] && [ -f d1/d2/x.txt ] && [ -d d1/d2/dir ] && echo okay" "okay\n" "" ""
  48. rm -rf d1
  49. # unzip -o
  50. mkdir -p d1/d2
  51. echo b > d1/d2/a.txt
  52. testing "-o" "unzip -q -o $FILES/zip/example.zip d1/d2/a.txt && cat d1/d2/a.txt" "a\n" "" ""
  53. rm -rf d1
  54. # unzip -n
  55. mkdir -p d1/d2
  56. echo b > d1/d2/a.txt
  57. testing "-n" "unzip -q -n $FILES/zip/example.zip d1/d2/a.txt && cat d1/d2/a.txt" "b\n" "" ""
  58. rm -rf d1
  59. # unzip -d DIR
  60. testing "-d non-existent" "unzip -q -d will/not/be/created $FILES/zip/example.zip d1/d2/a.txt 2> /dev/null ; [ ! -d will ] && echo okay" "okay\n" "" ""
  61. mkdir dir
  62. testing "-d exists" "unzip -q -d dir $FILES/zip/example.zip d1/d2/a.txt && [ ! -f d1/d2/a.txt ] && cat dir/d1/d2/a.txt" "a\n" "" ""
  63. rm -rf dir
  64. # unzip -p
  65. testing "-p" "unzip -p $FILES/zip/example.zip d1/d2/a.txt && [ ! -f d1/d2/a.txt ] && echo okay" "a\nokay\n" "" ""
  66. # unzip -x FILE...
  67. # Note: the RI ignores -x DIR for some reason, but it's not obvious we should.
  68. testing "-x FILE..." "unzip -q $FILES/zip/example.zip -x d1/d2/a.txt d1/d2/b.txt d1/d2/empty.txt d1/d2/x.txt && [ ! -f d1/d2/a.txt ] && [ ! -f d1/d2/b.txt ] && [ ! -f d1/d2/empty.txt ] && [ ! -f d1/d2/x.txt ] && [ -d d1/d2/dir ] && cat d1/d2/c.txt" "ccc\n" "" ""
  69. rm -rf d1
  70. # unzip FILE -x FILE...
  71. testing "FILE... -x FILE..." "unzip -q $FILES/zip/example.zip d1/d2/a.txt d1/d2/b.txt -x d1/d2/a.txt && [ ! -f d1/d2/a.txt ] && [ -f d1/d2/b.txt ] && [ ! -f d1/d2/c.txt ] && [ ! -f d1/d2/empty.txt ] && [ ! -f d1/d2/x.txt ] && [ ! -d d1/d2/dir ] && cat d1/d2/b.txt" "bb\n" "" ""
  72. rm -rf d1