toybox/tests/unzip.test
<<
>>
Prefs
   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
  14testing "-l" "unzip -l $FILES/zip/example.zip d1/d2/x.txt && [ ! -f d1/d2/x.txt ] && echo okay" "\
  15Archive:  $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\
  21okay\n" "" ""
  22
  23# unzip -lq
  24testing "-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\
  30okay\n" "" ""
  31
  32# unzip -lv
  33testing "-lv" "unzip -lv $FILES/zip/example.zip d1/d2/x.txt && [ ! -f d1/d2/file ] && echo okay" "\
  34Archive:  $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\
  40okay\n" "" ""
  41
  42# unzip -v
  43testing "-v" "unzip -v $FILES/zip/example.zip d1/d2/x.txt && [ ! -f d1/d2/file ] && echo okay" "\
  44Archive:  $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\
  50okay\n" "" ""
  51
  52# unzip
  53testing "one file" "unzip -q $FILES/zip/example.zip d1/d2/a.txt && [ ! -f d1/d2/b.txt ] && cat d1/d2/a.txt" "a\n" "" ""
  54rm -rf d1
  55testing "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" "" ""
  56rm -rf d1
  57
  58# unzip -o
  59mkdir -p d1/d2
  60echo b > d1/d2/a.txt
  61testing "-o" "unzip -q -o $FILES/zip/example.zip d1/d2/a.txt && cat d1/d2/a.txt" "a\n" "" ""
  62rm -rf d1
  63
  64# unzip -n
  65mkdir -p d1/d2
  66echo b > d1/d2/a.txt
  67testing "-n" "unzip -q -n $FILES/zip/example.zip d1/d2/a.txt && cat d1/d2/a.txt" "b\n" "" ""
  68rm -rf d1
  69
  70# unzip -d DIR
  71testing "-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" "" ""
  72mkdir dir
  73testing "-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" "" ""
  74rm -rf dir
  75
  76# unzip -p
  77testing "-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.
  81testing "-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" "" ""
  82rm -rf d1
  83
  84# unzip FILE -x FILE...
  85testing "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" "" ""
  86rm -rf d1
  87