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