tests/extmod/uzlib_decompress: Add uzlib tests to improve coverage.

This commit is contained in:
Damien George 2018-02-26 13:36:55 +11:00
parent a604451566
commit 4c2230add8
1 changed files with 9 additions and 1 deletions

View File

@ -15,7 +15,9 @@ PATTERNS = [
(bytes(range(64)), b'x\x9cc`dbfaec\xe7\xe0\xe4\xe2\xe6\xe1\xe5\xe3\x17\x10\x14\x12\x16\x11\x15\x13\x97\x90\x94\x92\x96\x91\x95\x93WPTRVQUS\xd7\xd0\xd4\xd2\xd6\xd1\xd5\xd370426153\xb7\xb0\xb4\xb2\xb6\xb1\xb5\xb3\x07\x00\xaa\xe0\x07\xe1'),
(b'hello', b'x\x01\x01\x05\x00\xfa\xffhello\x06,\x02\x15'), # compression level 0
# adaptive/dynamic huffman tree
(b'13371813150|13764518736|12345678901', b'x\x9c\x05\xc1\x81\x01\x000\x04\x04\xb1\x95\\\x1f\xcfn\x86o\x82d\x06Qq\xc8\x9d\xc5X}<e\xb5g\x83\x0f\x89X\x07\xab')
(b'13371813150|13764518736|12345678901', b'x\x9c\x05\xc1\x81\x01\x000\x04\x04\xb1\x95\\\x1f\xcfn\x86o\x82d\x06Qq\xc8\x9d\xc5X}<e\xb5g\x83\x0f\x89X\x07\xab'),
# dynamic Huffman tree with "case 17" (repeat code for 3-10 times)
(b'>I}\x00\x951D>I}\x00\x951D>I}\x00\x951D>I}\x00\x951D', b'x\x9c\x05\xc11\x01\x00\x00\x00\x010\x95\x14py\x84\x12C_\x9bR\x8cV\x8a\xd1J1Z)F\x1fw`\x089'),
]
for unpacked, packed in PATTERNS:
@ -41,3 +43,9 @@ try:
zlib.decompress(b'abc')
except Exception:
print("Exception")
# invalid block type
try:
zlib.decompress(b'\x07', -15) # final-block, block-type=3 (invalid)
except Exception as er:
print('Exception')