blob: bcc9b90f9f1b265f89be9ca6e5ac87343404791f [file] [log] [blame]
openvcdiff83bbde02008-10-23 23:43:46 +00001@echo off
2rem Copyright 2008 Google Inc.
3rem Author: Lincoln Smith
4rem
5rem Licensed under the Apache License, Version 2.0 (the "License");
6rem you may not use this file except in compliance with the License.
7rem You may obtain a copy of the License at
8rem
9rem http:#www.apache.org/licenses/LICENSE-2.0
10rem
11rem Unless required by applicable law or agreed to in writing, software
12rem distributed under the License is distributed on an "AS IS" BASIS,
13rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14rem See the License for the specific language governing permissions and
15rem limitations under the License.
16rem
17rem This script tests the correctness of the vcdiff.exe command-line
18rem executable. It is the Windows equivalent of the src/vcdiff_test.sh
19rem shell script for Unix systems, though some of the tests from that
20rem script are not included here.
21rem
22rem If you add a new test here, please add the same test to
23rem src/vcdiff_test.sh.
24
25rem The script should be passed one argument which is the location of the
26rem vcdiff.exe executable.
27if not exist %1 ^
28 ( echo Must pass location of vcdiff.exe as script argument ^
29 &&exit /b 1 )
30set VCDIFF=%1
31
32rem These options are only needed for the encoder;
33rem the decoder will recognize the interleaved and checksum formats
34rem without needing to specify any options.
35set TESTDATA_DIR=..\..\testdata
36set VCD_OPTIONS=-interleaved -checksum
37set DICTIONARY_FILE=%TESTDATA_DIR%\configure.ac.v0.1
38set TARGET_FILE=%TESTDATA_DIR%\configure.ac.v0.2
39set DELTA_FILE=%TEMP%\configure.ac.vcdiff
40set OUTPUT_TARGET_FILE=%TEMP%\configure.ac.output
41set MALICIOUS_ENCODING=%TESTDATA_DIR%\allocates_4gb.vcdiff
42set EMPTY_FILE=%TESTDATA_DIR%\empty_file.txt
43
44rem vcdiff with no arguments shows usage information & error result
45%VCDIFF% ^
46 && ( echo vcdiff with no arguments should fail, but succeeded ^
47 &&exit /b 1 )
48echo Test 1 ok
49
50rem vcdiff with three arguments but without "encode" or "decode"
51rem shows usage information & error result
52%VCDIFF% %VCD_OPTIONS% ^
53 -dictionary %DICTIONARY_FILE% -target %TARGET_FILE% -delta %DELTA_FILE% ^
54 && ( echo vcdiff without operation argument should fail, but succeeded ^
55 &&exit /b 1 )
56echo Test 2 ok
57
58rem vcdiff with all three arguments. Verify that output file matches target file
59%VCDIFF% %VCD_OPTIONS% ^
60 encode -dictionary %DICTIONARY_FILE% ^
61 -target %TARGET_FILE% ^
62 -delta %DELTA_FILE% ^
63 || ( echo Encode with three arguments failed ^
64 &&exit /b 1 )
65%VCDIFF% decode -dictionary %DICTIONARY_FILE% ^
66 -delta %DELTA_FILE% ^
67 -target %OUTPUT_TARGET_FILE% ^
68 || ( echo Decode with three arguments failed ^
69 &&exit /b 1 )
70fc /b %TARGET_FILE% %OUTPUT_TARGET_FILE% ^
71 || ( echo Decoded target does not match original ^
72 &&exit /b 1 )
73echo Test 3 ok
74
75del %DELTA_FILE%
76del %OUTPUT_TARGET_FILE%
77
78rem open-vcdiff Issue 7
79rem (http://code.google.com/p/open-vcdiff/issues/detail?id=7)
80rem vcdiff using stdin/stdout. Verify that output file matches target file
81%VCDIFF% %VCD_OPTIONS% ^
82 encode -dictionary %DICTIONARY_FILE% ^
83 < %TARGET_FILE% ^
84 > %DELTA_FILE% ^
85 || ( echo Encode using stdin/stdout failed ^
86 &&exit /b 1 )
87%VCDIFF% decode -dictionary %DICTIONARY_FILE% ^
88 < %DELTA_FILE% ^
89 > %OUTPUT_TARGET_FILE% ^
90 || ( echo Decode using stdin/stdout failed ^
91 &&exit /b 1 )
92fc /b %TARGET_FILE% %OUTPUT_TARGET_FILE% ^
93 || ( echo Decoded target does not match original ^
94 &&exit /b 1 )
95echo Test 4 ok
96
97del %DELTA_FILE%
98del %OUTPUT_TARGET_FILE%
99
100rem vcdiff with mixed stdin/stdout.
101%VCDIFF% %VCD_OPTIONS% ^
102 encode -dictionary %DICTIONARY_FILE% ^
103 -target %TARGET_FILE% ^
104 > %DELTA_FILE% ^
105 || ( echo Encode with mixed arguments failed ^
106 &&exit /b 1 )
107%VCDIFF% decode -dictionary %DICTIONARY_FILE% ^
108 -delta %DELTA_FILE% ^
109 > %OUTPUT_TARGET_FILE% ^
110 || ( echo Decode with mixed arguments failed ^
111 &&exit /b 1 )
112fc /b %TARGET_FILE% %OUTPUT_TARGET_FILE% ^
113 || ( echo Decoded target does not match original ^
114 &&exit /b 1 )
115echo Test 5 ok
116
117del %DELTA_FILE%
118del %OUTPUT_TARGET_FILE%
119
120%VCDIFF% %VCD_OPTIONS% ^
121 encode -dictionary %DICTIONARY_FILE% ^
122 < %TARGET_FILE% ^
123 -delta %DELTA_FILE% ^
124 || ( echo Encode with mixed arguments failed ^
125 &&exit /b 1 )
126%VCDIFF% decode -dictionary %DICTIONARY_FILE% ^
127 < %DELTA_FILE% ^
128 -target %OUTPUT_TARGET_FILE% ^
129 || ( echo Decode with mixed arguments failed ^
130 &&exit /b 1 )
131fc /b %TARGET_FILE% %OUTPUT_TARGET_FILE% ^
132 || ( echo Decoded target does not match original ^
133 &&exit /b 1 )
134echo Test 6 ok
135
136del %OUTPUT_TARGET_FILE%
137rem Don't remove %DELTA_FILE%; use it for the next test
138
139rem If using the wrong dictionary, and dictionary is smaller than the original
140rem dictionary, vcdiff will spot the mistake and return an error. (It can't
141rem detect the case where the wrong dictionary is larger than the right one.)
142%VCDIFF% decode -dictionary %TARGET_FILE% ^
143 -delta %DELTA_FILE% ^
144 -target %OUTPUT_TARGET_FILE% ^
145 && ( echo Decode using larger dictionary should fail, but succeeded ^
146 &&exit /b 1 )
147echo Test 7 ok
148
149del %DELTA_FILE%
150del %OUTPUT_TARGET_FILE%
151
152rem "vcdiff test" with all three arguments.
153%VCDIFF% %VCD_OPTIONS% ^
154 test -dictionary %DICTIONARY_FILE% ^
155 -target %TARGET_FILE% ^
156 -delta %DELTA_FILE% ^
157 || ( echo vcdiff test with three arguments failed ^
158 &&exit /b 1 )
159echo Test 8 ok
160
161del %DELTA_FILE%
162
163rem Dictionary file not found.
164%VCDIFF% %VCD_OPTIONS% ^
165 encode -dictionary %TEMP%\nonexistent_file ^
166 -target %TARGET_FILE% ^
167 -delta %DELTA_FILE% ^
168 && ( echo vcdiff with missing dictionary file should fail, but succeeded ^
169 &&exit /b 1 )
170echo Test 9 ok
171
172rem Target file not found.
173%VCDIFF% %VCD_OPTIONS% ^
174 encode -dictionary %DICTIONARY_FILE% ^
175 -target %TEMP%\nonexistent_file ^
176 -delta %DELTA_FILE% ^
177 && ( echo vcdiff with missing target file should fail, but succeeded ^
178 &&exit /b 1 )
179echo Test 10 ok
180
181rem Delta file not found.
182%VCDIFF% decode -dictionary %DICTIONARY_FILE% ^
183 -delta %TEMP%\nonexistent_file ^
184 -target %OUTPUT_TARGET_FILE% ^
185 && ( echo vcdiff with missing delta file should fail, but succeeded ^
186 &&exit /b 1 )
187echo Test 11 ok
188
189rem Test using -stats flag
190%VCDIFF% %VCD_OPTIONS% ^
191 encode -dictionary %DICTIONARY_FILE% ^
192 -target %TARGET_FILE% ^
193 -delta %DELTA_FILE% ^
194 -stats ^
195 || ( echo Encode with -stats failed ^
196 &&exit /b 1 )
197%VCDIFF% -stats ^
198 decode -dictionary %DICTIONARY_FILE% ^
199 -delta %DELTA_FILE% ^
200 -target %OUTPUT_TARGET_FILE% ^
201 || ( echo Decode with -stats failed ^
202 &&exit /b 1 )
203fc /b %TARGET_FILE% %OUTPUT_TARGET_FILE% ^
204 || ( echo Decoded target does not match original ^
205 &&exit /b 1 )
206echo Test 13 ok
207
208del %DELTA_FILE%
209del %OUTPUT_TARGET_FILE%
210
211rem open-vcdiff Issue 6
212rem (http://code.google.com/p/open-vcdiff/issues/detail?id=6)
213rem Using empty file as dictionary should work, but (because dictionary is empty)
214rem it will not produce a small delta file.
215%VCDIFF% %VCD_OPTIONS% ^
216 test -dictionary %EMPTY_FILE% ^
217 -target %TARGET_FILE% ^
218 -delta %DELTA_FILE% ^
219 -stats ^
220 || ( echo vcdiff test with empty file as dictionary failed ^
221 &&exit /b 1 )
222echo Test 14 ok
223
224del %DELTA_FILE%
225
226rem Decode using something that isn't a delta file
227%VCDIFF% decode -dictionary %DICTIONARY_FILE% ^
228 -delta %DICTIONARY_FILE% ^
229 -target %OUTPUT_TARGET_FILE% ^
230 && ( echo vcdiff with invalid delta file should fail, but succeeded ^
231 &&exit /b 1 )
232echo Test 17 ok
233
234%VCDIFF% %VCD_OPTIONS% ^
235 encode -target %TARGET_FILE% ^
236 -delta %DELTA_FILE% ^
237 -dictionary ^
238 && ( echo -dictionary option with no file name should fail, but succeeded ^
239 &&exit /b 1 )
240echo Test 18 ok
241
242%VCDIFF% %VCD_OPTIONS% ^
243 encode -dictionary %DICTIONARY_FILE% ^
244 -delta %DELTA_FILE% ^
245 -target ^
246 && ( echo -target option with no file name should fail, but succeeded ^
247 &&exit /b 1 )
248echo Test 19 ok
249
250%VCDIFF% %VCD_OPTIONS% ^
251 encode -dictionary %DICTIONARY_FILE% ^
252 -target %TARGET_FILE% ^
253 -delta ^
254 && ( echo -delta option with no file name should fail, but succeeded ^
255 &&exit /b 1 )
256echo Test 20 ok
257
258%VCDIFF% %VCD_OPTIONS% ^
259 encode -dictionary %DICTIONARY_FILE% ^
260 -target %TARGET_FILE% ^
261 -delta %DELTA_FILE% ^
262 -buffersize ^
263 && ( echo -buffersize option with no argument should fail, but succeeded ^
264 &&exit /b 1 )
265echo Test 21 ok
266
267rem Using -buffersize=1 should still work.
268%VCDIFF% %VCD_OPTIONS% ^
269 test -dictionary %DICTIONARY_FILE% ^
270 -target %TARGET_FILE% ^
271 -delta %DELTA_FILE% ^
272 -buffersize 1 ^
273 -stats ^
274 || ( echo vcdiff test with -buffersize=1 failed ^
275 &&exit /b 1 )
276echo Test 22 ok
277
278del %DELTA_FILE%
279
280rem Using -buffersize=1 with stdin/stdout means that vcdiff
281rem will create a separate target window for each byte read.
282%VCDIFF% encode -dictionary %DICTIONARY_FILE% ^
283 -buffersize 1 ^
284 -stats ^
285 < %TARGET_FILE% ^
286 > %DELTA_FILE% ^
287 || ( echo Encode using stdin/stdout with -buffersize=1 failed ^
288 &&exit /b 1 )
289%VCDIFF% decode -dictionary %DICTIONARY_FILE% ^
290 -buffersize 1 ^
291 -stats ^
292 < %DELTA_FILE% ^
293 > %OUTPUT_TARGET_FILE% ^
294 || ( echo Decode using stdin/stdout with -buffersize=1 failed ^
295 &&exit /b 1 )
296fc /b %TARGET_FILE% %OUTPUT_TARGET_FILE% ^
297 || ( echo Decoded target does not match original with -buffersize=1 ^
298 &&exit /b 1 )
299echo Test 23 ok
300
301del %DELTA_FILE%
302del %OUTPUT_TARGET_FILE%
303
304rem Using -buffersize=0 should fail.
305%VCDIFF% %VCD_OPTIONS% ^
306 test -dictionary %DICTIONARY_FILE% ^
307 -target %TARGET_FILE% ^
308 -delta %DELTA_FILE% ^
309 -buffersize 0 ^
310 && ( echo vcdiff test with -buffersize=0 should fail, but succeeded ^
311 &&exit /b 1 )
312echo Test 24 ok
313
314del %DELTA_FILE%
315
316rem Using -buffersize=128M (larger than default maximum) should still work.
317%VCDIFF% %VCD_OPTIONS% ^
318 test -dictionary %DICTIONARY_FILE% ^
319 -target %TARGET_FILE% ^
320 -delta %DELTA_FILE% ^
321 -buffersize 134217728 ^
322 -stats ^
323 || ( echo vcdiff test with -buffersize=128M failed ^
324 &&exit /b 1 )
325echo Test 25 ok
326
327del %DELTA_FILE%
328
329%VCDIFF% %VCD_OPTIONS% ^
330 test -dictionary %DICTIONARY_FILE% ^
331 -target %TARGET_FILE% ^
332 -delta %DELTA_FILE% ^
333 -froobish ^
334 && ( echo vdiff test with unrecognized option should fail, but succeeded ^
335 &&exit /b 1 )
336echo Test 26 ok
337
338%VCDIFF% %VCD_OPTIONS% ^
339 encode -target %TARGET_FILE% ^
340 -delta %DELTA_FILE% ^
341 && ( echo encode with no dictionary option should fail, but succeeded ^
342 &&exit /b 1 )
343echo Test 27 ok
344
345%VCDIFF% decode -target %TARGET_FILE% ^
346 -delta %DELTA_FILE% ^
347 && ( echo decode with no dictionary option should fail, but succeeded ^
348 &&exit /b 1 )
349echo Test 28 ok
350
351rem Remove -interleaved and -checksum options
352%VCDIFF% encode -dictionary %DICTIONARY_FILE% ^
353 < %TARGET_FILE% ^
354 > %DELTA_FILE% ^
355 || ( echo Encode without -interleaved and -checksum options failed ^
356 &&exit /b 1 )
357%VCDIFF% decode -dictionary %DICTIONARY_FILE% ^
358 < %DELTA_FILE% ^
359 > %OUTPUT_TARGET_FILE% ^
360 || ( echo Decode non-interleaved output failed ^
361 &&exit /b 1 )
362fc /b %TARGET_FILE% %OUTPUT_TARGET_FILE% ^
363 || ( echo Decoded target does not match original with -interleaved ^
364 &&exit /b 1 )
365echo Test 29 ok
366
367rem -target_matches option
368%VCDIFF% encode -dictionary %DICTIONARY_FILE% ^
369 -target_matches ^
370 -stats ^
371 < %TARGET_FILE% ^
372 > %DELTA_FILE% ^
373 || ( echo Encode with -target_matches option failed ^
374 &&exit /b 1 )
375rem The decode operation ignores the -target_matches option.
376%VCDIFF% decode -dictionary %DICTIONARY_FILE% ^
377 < %DELTA_FILE% ^
378 > %OUTPUT_TARGET_FILE% ^
379 || ( echo Decode output failed with -target_matches ^
380 &&exit /b 1 )
381fc /b %TARGET_FILE% %OUTPUT_TARGET_FILE% ^
382 || ( echo Decoded target does not match original with -target_matches ^
383 &&exit /b 1 )
384echo Test 30 ok
385
386del %DELTA_FILE%
387del %OUTPUT_TARGET_FILE%
388
389%VCDIFF% %VCD_OPTIONS% ^
390 dencode -dictionary %DICTIONARY_FILE% ^
391 -target %TARGET_FILE% ^
392 -delta %DELTA_FILE% ^
393 && ( echo vdiff with unrecognized action should fail, but succeeded ^
394 &&exit /b 1 )
395echo Test 31 ok
396
397%VCDIFF% %VCD_OPTIONS% ^
398 test -dictionary %DICTIONARY_FILE% ^
399 -target %TARGET_FILE% ^
400 && ( echo vdiff test without delta option should fail, but succeeded ^
401 &&exit /b 1 )
402echo Test 32 ok
403
404%VCDIFF% %VCD_OPTIONS% ^
405 test -dictionary %DICTIONARY_FILE% ^
406 -delta %DELTA_FILE% ^
407 && ( echo vdiff test without target option should fail, but succeeded ^
408 &&exit /b 1 )
409echo Test 33 ok
410
411rem open-vcdiff Issue 8
412rem (http://code.google.com/p/open-vcdiff/issues/detail?id=8)
413rem A malicious encoding that tries to produce a 4GB target file made up of 64
414rem windows, each window having a size of 64MB.
415%VCDIFF% %VCD_OPTIONS% ^
416 decode -dictionary %DICTIONARY_FILE% ^
417 -delta %MALICIOUS_ENCODING% ^
418 -target %OUTPUT_TARGET_FILE% ^
419 -max_target_file_size=65536 ^
420 && ( echo Decoding malicious file should fail, but succeeded ^
421 &&exit /b 1 )
422echo Test 34 ok
423
424del %OUTPUT_TARGET_FILE%
425
426%VCDIFF% %VCD_OPTIONS% ^
427 decode -dictionary %DICTIONARY_FILE% ^
428 -delta %MALICIOUS_ENCODING% ^
429 -target %OUTPUT_TARGET_FILE% ^
430 -max_target_window_size=65536 ^
431 && ( echo Decoding malicious file should fail, but succeeded ^
432 &&exit /b 1 )
433echo Test 35 ok
434
435del %OUTPUT_TARGET_FILE%
436
437rem Decoding a small target with the -max_target_file_size option should succeed.
438%VCDIFF% %VCD_OPTIONS% ^
439 test -dictionary %DICTIONARY_FILE% ^
440 -target %TARGET_FILE% ^
441 -delta %DELTA_FILE% ^
442 -max_target_file_size=65536 ^
443 || ( echo vcdiff test with -max_target_file_size failed ^
444 &&exit /b 1 )
445echo Test 36 ok
446
447rem Decoding a small target with -max_target_window_size option should succeed.
448%VCDIFF% %VCD_OPTIONS% ^
449 test -dictionary %DICTIONARY_FILE% ^
450 -target %TARGET_FILE% ^
451 -delta %DELTA_FILE% ^
452 -max_target_window_size=65536 ^
453 || ( echo vcdiff test with -max_target_window_size failed ^
454 &&exit /b 1 )
455echo Test 37 ok
456
457del %DELTA_FILE%
458
459echo PASS