|
31 | 31 | str=type('')
|
32 | 32 |
|
33 | 33 |
|
| 34 | +importio |
34 | 35 | importcompoundfilesascf
|
35 | 36 | importpytest
|
36 | 37 | importwarnings
|
@@ -66,7 +67,7 @@ def verify_example(doc, contents=None):
|
66 | 67 | DirEntry('Storage 1',False,1),
|
67 | 68 | DirEntry('Storage 1/Stream 1',True,544),
|
68 | 69 | )
|
69 |
| -verify_contents(doc,contents) |
| 70 | +verify_contents(doc,contents) |
70 | 71 |
|
71 | 72 |
|
72 | 73 | deftest_function_sample1_doc():
|
@@ -214,19 +215,70 @@ def test_invalid_dir_misc():
|
214 | 215 |
|
215 | 216 | deftest_invalid_dir_size():
|
216 | 217 | withwarnings.catch_warnings(record=True)asw:
|
217 |
| -# Same file as example.dat with size of Stream 1 corrupted; library |
218 |
| -# re-writes size to be within 32-bits |
219 |
| -doc=cf.CompoundFileReader('tests/invalid_dir_size.dat') |
| 218 | +# Same file as example.dat with size of Stream 1 corrupted (> 32-bits); |
| 219 | +#libraryre-writes size to be within 32-bits |
| 220 | +doc=cf.CompoundFileReader('tests/invalid_dir_size1.dat') |
220 | 221 | assertissubclass(w[0].category,cf.CompoundFileDirSizeWarning)
|
221 | 222 | assertissubclass(w[1].category,cf.CompoundFileDirSizeWarning)
|
222 | 223 | assertlen(w)==2
|
223 | 224 | verify_example(doc, (
|
224 | 225 | DirEntry('Storage 1',False,1),
|
225 |
| -DirEntry('Storage 1/Stream 1',False,0xFFFFFFFF), |
| 226 | +DirEntry('Storage 1/Stream 1',True,0xFFFFFFFF), |
226 | 227 | ))
|
227 | 228 |
|
228 | 229 | deftest_invalid_dir_loop():
|
229 | 230 | withpytest.raises(cf.CompoundFileDirLoopError):
|
| 231 | +# Same as example.dat but with Stream 1's left pointer corrupted to |
| 232 | +# point to the Root Entry |
230 | 233 | doc=cf.CompoundFileReader('tests/invalid_dir_loop.dat')
|
231 | 234 |
|
| 235 | +deftest_invalid_fat_loop(): |
| 236 | +withpytest.raises(cf.CompoundFileNormalLoopError): |
| 237 | +# Sample as example.dat but with Stream 1's FAT entry corrupted to |
| 238 | +# point to itself |
| 239 | +doc=cf.CompoundFileReader('tests/invalid_fat_loop.dat') |
| 240 | + |
| 241 | +deftest_stream_attr(): |
| 242 | +withcf.CompoundFileReader('tests/example.dat')asdoc: |
| 243 | +withdoc.open('Storage 1/Stream 1')asf: |
| 244 | +assertf.readable() |
| 245 | +assertnotf.writable() |
| 246 | +assertf.seekable() |
| 247 | + |
| 248 | +deftest_stream_seek(): |
| 249 | +withcf.CompoundFileReader('tests/example.dat')asdoc: |
| 250 | +withdoc.open('Storage 1/Stream 1')asf: |
| 251 | +assertf.seek(0,io.SEEK_END)==544 |
| 252 | +assertf.seek(0,io.SEEK_CUR)==544 |
| 253 | +withpytest.raises(ValueError): |
| 254 | +f.seek(-1) |
| 255 | + |
| 256 | +deftest_stream_read(): |
| 257 | +withcf.CompoundFileReader('tests/example2.dat')asdoc: |
| 258 | +# Same file as example.dat with an additional Stream 2 which is 4112 |
| 259 | +# bytes long (too long for mini FAT) |
| 260 | +withdoc.open('Storage 1/Stream 1')asf: |
| 261 | +assertlen(f.read())==544 |
| 262 | +f.seek(0) |
| 263 | +assertlen(f.read(1024))==544 |
| 264 | +f.seek(0) |
| 265 | +assertlen(f.read1())==64 |
| 266 | +f.seek(0,io.SEEK_END) |
| 267 | +assertf.read1()==b'' |
| 268 | +withdoc.open('Storage 1/Stream 2')asf: |
| 269 | +assertlen(f.read())==4112 |
| 270 | +f.seek(0) |
| 271 | +assertlen(f.read1())==512 |
| 272 | +f.seek(0,io.SEEK_END) |
| 273 | +assertf.read1()==b'' |
232 | 274 |
|
| 275 | +deftest_stream_read_broken_size(): |
| 276 | +withcf.CompoundFileReader('tests/invalid_dir_size2.dat')asdoc: |
| 277 | +# Same file as example.dat with size of Stream 1 corrupted to 3072 |
| 278 | +# bytes (small enough to fit in the mini FAT but too large for the |
| 279 | +# actual data which is 544 bytes), and additional Stream 2 which has |
| 280 | +# corrupted size 8192 bytes (actual size 512 bytes) |
| 281 | +withdoc.open('Storage 1/Stream 1')asf: |
| 282 | +assertf.seek(0,io.SEEK_END)==576 |
| 283 | +withdoc.open('Storage 1/Stream 2')asf: |
| 284 | +assertf.seek(0,io.SEEK_END)==512 |