Elliott Hughes | f276140 | 2019-11-15 15:07:00 -0800 | [diff] [blame^] | 1 | # unzip tests. |
| 2 | |
| 3 | # Note: since "master key", Android uses libziparchive for all zip file |
| 4 | # handling, and that scans the whole central directory immediately. Not only |
| 5 | # lookups by name but also iteration is implemented using the resulting hash |
| 6 | # table, meaning that any test that makes assumptions about iteration order |
| 7 | # will fail on Android. |
| 8 | |
| 9 | name: unzip -l |
| 10 | command: unzip -l $FILES/example.zip d1/d2/x.txt |
| 11 | after: [ ! -f d1/d2/x.txt ] |
| 12 | expected-stdout: |
| 13 | Archive: $FILES/example.zip |
| 14 | Length Date Time Name |
| 15 | --------- ---------- ----- ---- |
| 16 | 1024 2017-06-04 08:45 d1/d2/x.txt |
| 17 | --------- ------- |
| 18 | 1024 1 file |
| 19 | --- |
| 20 | |
| 21 | name: unzip -lq |
| 22 | command: unzip -lq $FILES/example.zip d1/d2/x.txt |
| 23 | after: [ ! -f d1/d2/x.txt ] |
| 24 | expected-stdout: |
| 25 | Length Date Time Name |
| 26 | --------- ---------- ----- ---- |
| 27 | 1024 2017-06-04 08:45 d1/d2/x.txt |
| 28 | --------- ------- |
| 29 | 1024 1 file |
| 30 | --- |
| 31 | |
| 32 | name: unzip -lv |
| 33 | command: unzip -lv $FILES/example.zip d1/d2/x.txt |
| 34 | after: [ ! -f d1/d2/file ] |
| 35 | expected-stdout: |
| 36 | Archive: $FILES/example.zip |
| 37 | Length Method Size Cmpr Date Time CRC-32 Name |
| 38 | -------- ------ ------- ---- ---------- ----- -------- ---- |
| 39 | 1024 Defl:N 11 99% 2017-06-04 08:45 48d7f063 d1/d2/x.txt |
| 40 | -------- ------- --- ------- |
| 41 | 1024 11 99% 1 file |
| 42 | --- |
| 43 | |
| 44 | name: unzip -v |
| 45 | command: unzip -v $FILES/example.zip d1/d2/x.txt |
| 46 | after: [ ! -f d1/d2/file ] |
| 47 | expected-stdout: |
| 48 | Archive: $FILES/example.zip |
| 49 | Length Method Size Cmpr Date Time CRC-32 Name |
| 50 | -------- ------ ------- ---- ---------- ----- -------- ---- |
| 51 | 1024 Defl:N 11 99% 2017-06-04 08:45 48d7f063 d1/d2/x.txt |
| 52 | -------- ------- --- ------- |
| 53 | 1024 11 99% 1 file |
| 54 | --- |
| 55 | |
| 56 | name: unzip one file |
| 57 | command: unzip -q $FILES/example.zip d1/d2/a.txt && cat d1/d2/a.txt |
| 58 | after: [ ! -f d1/d2/b.txt ] |
| 59 | expected-stdout: |
| 60 | a |
| 61 | --- |
| 62 | |
| 63 | name: unzip all files |
| 64 | command: unzip -q $FILES/example.zip |
| 65 | after: [ -f d1/d2/a.txt ] |
| 66 | after: [ -f d1/d2/b.txt ] |
| 67 | after: [ -f d1/d2/c.txt ] |
| 68 | after: [ -f d1/d2/empty.txt ] |
| 69 | after: [ -f d1/d2/x.txt ] |
| 70 | after: [ -d d1/d2/dir ] |
| 71 | expected-stdout: |
| 72 | --- |
| 73 | |
| 74 | name: unzip -o |
| 75 | before: mkdir -p d1/d2 |
| 76 | before: echo b > d1/d2/a.txt |
| 77 | command: unzip -q -o $FILES/example.zip d1/d2/a.txt && cat d1/d2/a.txt |
| 78 | expected-stdout: |
| 79 | a |
| 80 | --- |
| 81 | |
| 82 | name: unzip -n |
| 83 | before: mkdir -p d1/d2 |
| 84 | before: echo b > d1/d2/a.txt |
| 85 | command: unzip -q -n $FILES/example.zip d1/d2/a.txt && cat d1/d2/a.txt |
| 86 | expected-stdout: |
| 87 | b |
| 88 | --- |
| 89 | |
| 90 | # The reference implementation will create *one* level of missing directories, |
| 91 | # so this succeeds. |
| 92 | name: unzip -d shallow non-existent |
| 93 | command: unzip -q -d will-be-created $FILES/example.zip d1/d2/a.txt |
| 94 | after: [ -d will-be-created ] |
| 95 | after: [ -f will-be-created/d1/d2/a.txt ] |
| 96 | --- |
| 97 | |
| 98 | # The reference implementation will *only* create one level of missing |
| 99 | # directories, so this fails. |
| 100 | name: unzip -d deep non-existent |
| 101 | command: unzip -q -d oh-no/will-not-be-created $FILES/example.zip d1/d2/a.txt 2> stderr ; echo $? > status |
| 102 | after: [ ! -d oh-no ] |
| 103 | after: [ ! -d oh-no/will-not-be-created ] |
| 104 | after: [ ! -f oh-no/will-not-be-created/d1/d2/a.txt ] |
| 105 | after: grep -q "oh-no/will-not-be-created" stderr |
| 106 | after: grep -q "No such file or directory" stderr |
| 107 | # The reference implementation has *lots* of non-zero exit values, but we stick to 0 and 1. |
| 108 | after: [ $(cat status) -gt 0 ] |
| 109 | --- |
| 110 | |
| 111 | name: unzip -d exists |
| 112 | before: mkdir dir |
| 113 | command: unzip -q -d dir $FILES/example.zip d1/d2/a.txt && cat dir/d1/d2/a.txt |
| 114 | after: [ ! -f d1/d2/a.txt ] |
| 115 | expected-stdout: |
| 116 | a |
| 117 | --- |
| 118 | |
| 119 | name: unzip -p |
| 120 | command: unzip -p $FILES/example.zip d1/d2/a.txt |
| 121 | after: [ ! -f d1/d2/a.txt ] |
| 122 | expected-stdout: |
| 123 | a |
| 124 | --- |
| 125 | |
| 126 | name: unzip -x FILE... |
| 127 | # Note: the RI ignores -x DIR for some reason, but it's not obvious we should. |
| 128 | command: unzip -q $FILES/example.zip -x d1/d2/a.txt d1/d2/b.txt d1/d2/empty.txt d1/d2/x.txt && cat d1/d2/c.txt |
| 129 | after: [ ! -f d1/d2/a.txt ] |
| 130 | after: [ ! -f d1/d2/b.txt ] |
| 131 | after: [ ! -f d1/d2/empty.txt ] |
| 132 | after: [ ! -f d1/d2/x.txt ] |
| 133 | after: [ -d d1/d2/dir ] |
| 134 | expected-stdout: |
| 135 | ccc |
| 136 | --- |
| 137 | |
| 138 | name: unzip FILE -x FILE... |
| 139 | command: unzip -q $FILES/example.zip d1/d2/a.txt d1/d2/b.txt -x d1/d2/a.txt && cat d1/d2/b.txt |
| 140 | after: [ ! -f d1/d2/a.txt ] |
| 141 | after: [ -f d1/d2/b.txt ] |
| 142 | after: [ ! -f d1/d2/c.txt ] |
| 143 | after: [ ! -f d1/d2/empty.txt ] |
| 144 | after: [ ! -f d1/d2/x.txt ] |
| 145 | after: [ ! -d d1/d2/dir ] |
| 146 | expected-stdout: |
| 147 | bb |
| 148 | --- |