blob: 6e5cbf213b6b51401996f43a89018ed8adb0f438 [file] [log] [blame]
Elliott Hughesf2761402019-11-15 15:07:00 -08001# 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
9name: unzip -l
10command: unzip -l $FILES/example.zip d1/d2/x.txt
11after: [ ! -f d1/d2/x.txt ]
12expected-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
21name: unzip -lq
22command: unzip -lq $FILES/example.zip d1/d2/x.txt
23after: [ ! -f d1/d2/x.txt ]
24expected-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
32name: unzip -lv
33command: unzip -lv $FILES/example.zip d1/d2/x.txt
34after: [ ! -f d1/d2/file ]
35expected-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
44name: unzip -v
45command: unzip -v $FILES/example.zip d1/d2/x.txt
46after: [ ! -f d1/d2/file ]
47expected-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
56name: unzip one file
57command: unzip -q $FILES/example.zip d1/d2/a.txt && cat d1/d2/a.txt
58after: [ ! -f d1/d2/b.txt ]
59expected-stdout:
60 a
61---
62
63name: unzip all files
64command: unzip -q $FILES/example.zip
65after: [ -f d1/d2/a.txt ]
66after: [ -f d1/d2/b.txt ]
67after: [ -f d1/d2/c.txt ]
68after: [ -f d1/d2/empty.txt ]
69after: [ -f d1/d2/x.txt ]
70after: [ -d d1/d2/dir ]
71expected-stdout:
72---
73
74name: unzip -o
75before: mkdir -p d1/d2
76before: echo b > d1/d2/a.txt
77command: unzip -q -o $FILES/example.zip d1/d2/a.txt && cat d1/d2/a.txt
78expected-stdout:
79 a
80---
81
82name: unzip -n
83before: mkdir -p d1/d2
84before: echo b > d1/d2/a.txt
85command: unzip -q -n $FILES/example.zip d1/d2/a.txt && cat d1/d2/a.txt
86expected-stdout:
87 b
88---
89
90# The reference implementation will create *one* level of missing directories,
91# so this succeeds.
92name: unzip -d shallow non-existent
93command: unzip -q -d will-be-created $FILES/example.zip d1/d2/a.txt
94after: [ -d will-be-created ]
95after: [ -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.
100name: unzip -d deep non-existent
101command: unzip -q -d oh-no/will-not-be-created $FILES/example.zip d1/d2/a.txt 2> stderr ; echo $? > status
102after: [ ! -d oh-no ]
103after: [ ! -d oh-no/will-not-be-created ]
104after: [ ! -f oh-no/will-not-be-created/d1/d2/a.txt ]
105after: grep -q "oh-no/will-not-be-created" stderr
106after: 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.
108after: [ $(cat status) -gt 0 ]
109---
110
111name: unzip -d exists
112before: mkdir dir
113command: unzip -q -d dir $FILES/example.zip d1/d2/a.txt && cat dir/d1/d2/a.txt
114after: [ ! -f d1/d2/a.txt ]
115expected-stdout:
116 a
117---
118
119name: unzip -p
120command: unzip -p $FILES/example.zip d1/d2/a.txt
121after: [ ! -f d1/d2/a.txt ]
122expected-stdout:
123 a
124---
125
126name: unzip -x FILE...
127# Note: the RI ignores -x DIR for some reason, but it's not obvious we should.
128command: 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
129after: [ ! -f d1/d2/a.txt ]
130after: [ ! -f d1/d2/b.txt ]
131after: [ ! -f d1/d2/empty.txt ]
132after: [ ! -f d1/d2/x.txt ]
133after: [ -d d1/d2/dir ]
134expected-stdout:
135 ccc
136---
137
138name: unzip FILE -x FILE...
139command: unzip -q $FILES/example.zip d1/d2/a.txt d1/d2/b.txt -x d1/d2/a.txt && cat d1/d2/b.txt
140after: [ ! -f d1/d2/a.txt ]
141after: [ -f d1/d2/b.txt ]
142after: [ ! -f d1/d2/c.txt ]
143after: [ ! -f d1/d2/empty.txt ]
144after: [ ! -f d1/d2/x.txt ]
145after: [ ! -d d1/d2/dir ]
146expected-stdout:
147 bb
148---