8000 tests/uzlib_decompio_gz: Test for DecompIO with gzip bitstream. · sparkfun/circuitpython@d46de80 · GitHub
[go: up one dir, main page]

Skip to content

Commit d46de80

Browse files
committed
tests/uzlib_decompio_gz: Test for DecompIO with gzip bitstream.
1 parent 7b901d6 commit d46de80

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

tests/extmod/uzlib_decompio_gz.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
try:
2+
import zlib
3+
except ImportError:
4+
import uzlib as zlib
5+
import uio as io
6+
7+
8+
# gzip bitstream
9+
buf = io.BytesIO(b'\x1f\x8b\x08\x08\x99\x0c\xe5W\x00\x03hello\x00\xcbH\xcd\xc9\xc9\x07\x00\x86\xa6\x106\x05\x00\x00\x00')
10+
inp = zlib.DecompIO(buf, 16 + 8)
11+
print(buf.seek(0, 1))
12+
print(inp.read(1))
13+
print(buf.seek(0, 1))
14+
print(inp.read(2))
15+
print(inp.read())
16+
print(buf.seek(0, 1))
17+
print(inp.read(1))
18+
print(inp.read())
19+
print(buf.seek(0, 1))
20+
21+
# broken header
22+
buf = io.BytesIO(b'\x1f\x8c\x08\x08\x99\x0c\xe5W\x00\x03hello\x00\xcbH\xcd\xc9\xc9\x07\x00\x86\xa6\x106\x05\x00\x00\x00')
23+
try:
24+
inp = zlib.DecompIO(buf, 16 + 8)
25+
except ValueError:
26+
print("ValueError")
27+
28+
# broken crc32
29+
buf = io.BytesIO(b'\x1f\x8b\x08\x08\x99\x0c\xe5W\x00\x03hello\x00\xcbH\xcd\xc9\xc9\x07\x00\x86\xa7\x106\x05\x00\x00\x00')
30+
inp = zlib.DecompIO(buf, 16 + 8)
31+
try:
32+
inp.read(6)
33+
except OSError as e:
34+
print(repr(e))
35+
36+
# broken uncompressed size - not checked so far
37+
#buf = io.BytesIO(b'\x1f\x8b\x08\x08\x99\x0c\xe5W\x00\x03hello\x00\xcbH\xcd\xc9\xc9\x07\x00\x86\xa6\x106\x06\x00\x00\x00')
38+
#inp = zlib.DecompIO(buf, 16 + 8)
39+
#inp.read(6)

tests/extmod/uzlib_decompio_gz.py.exp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
16
2+
b'h'
3+
18
4+
b'el'
5+
b'lo'
6+
31
7+
b''
8+
b''
9+
31
10+
ValueError
11+
OSError(22,)

0 commit comments

Comments
 (0)
0