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