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
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---
149
150name: unzip -j
151# Note: the RI outputs a bunch of trailing whitespace for some reason.
152command: unzip -j $FILES/example.zip d1/d2/x.txt | sed 's/ *$//'
153after: [ ! -f d1/d2/x.txt ]
154after: [ -f x.txt ]
155expected-stdout:
156	Archive:  $FILES/example.zip
157	  inflating: x.txt
158---
159
160name: unzip -t one
161command: unzip -t $FILES/example.zip d1/d2/x.txt
162after: [ ! -d d1 ]
163expected-stdout:
164	Archive:  $FILES/example.zip
165	    testing: d1/d2/x.txt              OK
166	No errors detected in $FILES/example.zip for the 1 file tested.
167---
168
169name: unzip -tq all
170command: unzip -tq $FILES/example.zip
171after: [ ! -f d1/d2/x.txt ]
172expected-stdout:
173	No errors detected in compressed data of $FILES/example.zip.
174---
175
176name: unzip -tq one
177command: unzip -tq $FILES/example.zip d1/d2/x.txt
178after: [ ! -f d1/d2/x.txt ]
179expected-stdout:
180	No errors detected in $FILES/example.zip for the 1 file tested.
181
182---
183
184name: unzip -tq two
185command: unzip -tq $FILES/example.zip d1/d2/x.txt d1/d2/b.txt
186after: [ ! -f d1/d2/x.txt ]
187expected-stdout:
188	No errors detected in $FILES/example.zip for the 2 files tested.
189
190---
191
192name: unzip -t one bad
193command: unzip -t $FILES/bad_crc.zip a.txt
194after: [ ! -f a.txt ]
195expected-stdout:
196	Archive:  $FILES/bad_crc.zip
197	    testing: a.txt                    bad CRC 950821c5  (should be 950821e5)
198	At least one error was detected in $FILES/bad_crc.zip.
199expected-exit-status: 2
200
201#---
202#
203# TODO: test requires file iteration order.
204#name: unzip -tq all bad
205#command: unzip -tq $FILES/bad_crc.zip
206#after: [ ! -f a.txt ]
207#after: [ ! -f b.txt ]
208#expected-stdout:
209#	a.txt                   bad CRC 950821c5  (should be 950821e5)
210#	b.txt                   bad CRC 5912b84d  (should be 5912b84e)
211#	At least one error was detected in $FILES/bad_crc.zip.
212#expected-exit-status: 2
213
214---
215
216name: unzip -tq one bad
217command: unzip -tq $FILES/bad_crc.zip a.txt
218after: [ ! -f a.txt ]
219expected-stdout:
220	a.txt                   bad CRC 950821c5  (should be 950821e5)
221	At least one error was detected in $FILES/bad_crc.zip.
222expected-exit-status: 2
223
224#---
225#
226# TODO: test requires file iteration order.
227#name: unzip -tq two bad
228#command: unzip -tq $FILES/bad_crc.zip a.txt b.txt
229#after: [ ! -f a.txt ]
230#after: [ ! -f b.txt ]
231#expected-stdout:
232#	a.txt                   bad CRC 950821c5  (should be 950821e5)
233#	b.txt                   bad CRC 5912b84d  (should be 5912b84e)
234#	At least one error was detected in $FILES/bad_crc.zip.
235#expected-exit-status: 2
236
237---
238