Home | History | Annotate | Download | only in vsprojects
      1 @echo off
      2 rem Copyright 2008 Google Inc.
      3 rem Author: Lincoln Smith
      4 rem
      5 rem Licensed under the Apache License, Version 2.0 (the "License");
      6 rem you may not use this file except in compliance with the License.
      7 rem You may obtain a copy of the License at
      8 rem
      9 rem     http:#www.apache.org/licenses/LICENSE-2.0
     10 rem
     11 rem Unless required by applicable law or agreed to in writing, software
     12 rem distributed under the License is distributed on an "AS IS" BASIS,
     13 rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14 rem See the License for the specific language governing permissions and
     15 rem limitations under the License.
     16 rem
     17 rem This script tests the correctness of the vcdiff.exe command-line
     18 rem executable.  It is the Windows equivalent of the src/vcdiff_test.sh
     19 rem shell script for Unix systems, though some of the tests from that
     20 rem script are not included here.
     21 rem
     22 rem If you add a new test here, please add the same test to
     23 rem src/vcdiff_test.sh.
     24 
     25 rem The script should be passed one argument which is the location of the
     26 rem vcdiff.exe executable.
     27 if not exist %1 ^
     28     ( echo Must pass location of vcdiff.exe as script argument ^
     29       &&exit /b 1 )
     30 set VCDIFF=%1
     31 
     32 rem These options are only needed for the encoder;
     33 rem the decoder will recognize the interleaved and checksum formats
     34 rem without needing to specify any options.
     35 set TESTDATA_DIR=..\..\testdata
     36 set VCD_OPTIONS=-interleaved -checksum
     37 set DICTIONARY_FILE=%TESTDATA_DIR%\configure.ac.v0.1
     38 set TARGET_FILE=%TESTDATA_DIR%\configure.ac.v0.2
     39 set DELTA_FILE=%TEMP%\configure.ac.vcdiff
     40 set OUTPUT_TARGET_FILE=%TEMP%\configure.ac.output
     41 set MALICIOUS_ENCODING=%TESTDATA_DIR%\allocates_4gb.vcdiff
     42 set EMPTY_FILE=%TESTDATA_DIR%\empty_file.txt
     43 
     44 rem 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 )
     48 echo Test 1 ok
     49 
     50 rem vcdiff with three arguments but without "encode" or "decode"
     51 rem 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 )
     56 echo Test 2 ok
     57 
     58 rem 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 )
     70 fc /b %TARGET_FILE% %OUTPUT_TARGET_FILE% ^
     71     || ( echo Decoded target does not match original ^
     72          &&exit /b 1 )
     73 echo Test 3 ok
     74 
     75 del %DELTA_FILE%
     76 del %OUTPUT_TARGET_FILE%
     77 
     78 rem open-vcdiff Issue 7
     79 rem (http://code.google.com/p/open-vcdiff/issues/detail?id=7)
     80 rem 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 )
     92 fc /b %TARGET_FILE% %OUTPUT_TARGET_FILE% ^
     93     || ( echo Decoded target does not match original ^
     94          &&exit /b 1 )
     95 echo Test 4 ok
     96 
     97 del %DELTA_FILE%
     98 del %OUTPUT_TARGET_FILE%
     99 
    100 rem 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 )
    112 fc /b %TARGET_FILE% %OUTPUT_TARGET_FILE% ^
    113     || ( echo Decoded target does not match original ^
    114          &&exit /b 1 )
    115 echo Test 5 ok
    116 
    117 del %DELTA_FILE%
    118 del %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 )
    131 fc /b %TARGET_FILE% %OUTPUT_TARGET_FILE% ^
    132     || ( echo Decoded target does not match original ^
    133          &&exit /b 1 )
    134 echo Test 6 ok
    135 
    136 del %OUTPUT_TARGET_FILE%
    137 rem Don't remove %DELTA_FILE%; use it for the next test
    138 
    139 rem If using the wrong dictionary, and dictionary is smaller than the original
    140 rem dictionary, vcdiff will spot the mistake and return an error.  (It can't
    141 rem 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 )
    147 echo Test 7 ok
    148 
    149 del %DELTA_FILE%
    150 del %OUTPUT_TARGET_FILE%
    151 
    152 rem "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 )
    159 echo Test 8 ok
    160 
    161 del %DELTA_FILE%
    162 
    163 rem 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 )
    170 echo Test 9 ok
    171 
    172 rem 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 )
    179 echo Test 10 ok
    180 
    181 rem 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 )
    187 echo Test 11 ok
    188 
    189 rem 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 )
    203 fc /b %TARGET_FILE% %OUTPUT_TARGET_FILE% ^
    204     || ( echo Decoded target does not match original ^
    205          &&exit /b 1 )
    206 echo Test 13 ok
    207 
    208 del %DELTA_FILE%
    209 del %OUTPUT_TARGET_FILE%
    210 
    211 rem open-vcdiff Issue 6
    212 rem (http://code.google.com/p/open-vcdiff/issues/detail?id=6)
    213 rem Using empty file as dictionary should work, but (because dictionary is empty)
    214 rem 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 )
    222 echo Test 14 ok
    223 
    224 del %DELTA_FILE%
    225 
    226 rem 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 )
    232 echo 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 )
    240 echo 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 )
    248 echo 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 )
    256 echo 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 )
    265 echo Test 21 ok
    266 
    267 rem 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 )
    276 echo Test 22 ok
    277 
    278 del %DELTA_FILE%
    279 
    280 rem Using -buffersize=1 with stdin/stdout means that vcdiff
    281 rem 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 )
    296 fc /b %TARGET_FILE% %OUTPUT_TARGET_FILE% ^
    297     || ( echo Decoded target does not match original with -buffersize=1 ^
    298          &&exit /b 1 )
    299 echo Test 23 ok
    300 
    301 del %DELTA_FILE%
    302 del %OUTPUT_TARGET_FILE%
    303 
    304 rem 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 )
    312 echo Test 24 ok
    313 
    314 del %DELTA_FILE%
    315 
    316 rem 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 )
    325 echo Test 25 ok
    326 
    327 del %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 )
    336 echo 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 )
    343 echo 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 )
    349 echo Test 28 ok
    350 
    351 rem 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 )
    362 fc /b %TARGET_FILE% %OUTPUT_TARGET_FILE% ^
    363     || ( echo Decoded target does not match original with -interleaved ^
    364          &&exit /b 1 )
    365 echo Test 29 ok
    366 
    367 rem -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 )
    375 rem 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 )
    381 fc /b %TARGET_FILE% %OUTPUT_TARGET_FILE% ^
    382     || ( echo Decoded target does not match original with -target_matches ^
    383          &&exit /b 1 )
    384 echo Test 30 ok
    385 
    386 del %DELTA_FILE%
    387 del %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 )
    395 echo 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 )
    402 echo 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 )
    409 echo Test 33 ok
    410 
    411 rem open-vcdiff Issue 8
    412 rem (http://code.google.com/p/open-vcdiff/issues/detail?id=8)
    413 rem A malicious encoding that tries to produce a 4GB target file made up of 64
    414 rem 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 )
    422 echo Test 34 ok
    423 
    424 del %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 )
    433 echo Test 35 ok
    434 
    435 del %OUTPUT_TARGET_FILE%
    436 
    437 rem 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 )
    445 echo Test 36 ok
    446 
    447 rem 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 )
    455 echo Test 37 ok
    456 
    457 del %DELTA_FILE%
    458 
    459 echo PASS
    460