diff options
author | pacien | 2018-11-25 16:45:35 +0100 |
---|---|---|
committer | pacien | 2018-11-25 16:45:35 +0100 |
commit | 680c0a3c94f0bb84a2773bc9a95dc5399b6925fb (patch) | |
tree | 8b7efa786f14aa4d17ab22ab11b55eda1981519f /tests | |
parent | 643d2d72fab23df30d29c10614bfa89648cd3655 (diff) | |
download | gziplike-680c0a3c94f0bb84a2773bc9a95dc5399b6925fb.tar.gz |
Fix bitreader look-ahead overflow
Diffstat (limited to 'tests')
-rw-r--r-- | tests/tbitreader.nim | 23 | ||||
-rw-r--r-- | tests/tintegers.nim | 7 |
2 files changed, 30 insertions, 0 deletions
diff --git a/tests/tbitreader.nim b/tests/tbitreader.nim index 8285f63..294f6c9 100644 --- a/tests/tbitreader.nim +++ b/tests/tbitreader.nim | |||
@@ -49,6 +49,29 @@ suite "bitreader": | |||
49 | expect IOError: discard bitReader.readBits(16, uint16) | 49 | expect IOError: discard bitReader.readBits(16, uint16) |
50 | check bitReader.atEnd() | 50 | check bitReader.atEnd() |
51 | 51 | ||
52 | test "readBits (look-ahead overflow)": | ||
53 | let stream = newStringStream() | ||
54 | defer: stream.close() | ||
55 | stream.write(0xAB'u8) | ||
56 | stream.setPosition(0) | ||
57 | |||
58 | let bitReader = stream.bitReader() | ||
59 | check bitReader.readBits(4, uint16) == 0x000B'u16 | ||
60 | check bitReader.readBits(4, uint16) == 0x000A'u16 | ||
61 | check bitReader.atEnd() | ||
62 | |||
63 | test "readBits (from buffer composition)": | ||
64 | let stream = newStringStream() | ||
65 | defer: stream.close() | ||
66 | stream.write(0xABCD'u16) | ||
67 | stream.setPosition(0) | ||
68 | |||
69 | let bitReader = stream.bitReader() | ||
70 | check bitReader.readBits(4, uint16) == 0x000D'u16 | ||
71 | check bitReader.readBits(8, uint16) == 0x00BC'u16 | ||
72 | check bitReader.readBits(4, uint16) == 0x000A'u16 | ||
73 | check bitReader.atEnd() | ||
74 | |||
52 | test "readSeq": | 75 | test "readSeq": |
53 | let stream = newStringStream() | 76 | let stream = newStringStream() |
54 | defer: stream.close() | 77 | defer: stream.close() |
diff --git a/tests/tintegers.nim b/tests/tintegers.nim index c77abec..956e4aa 100644 --- a/tests/tintegers.nim +++ b/tests/tintegers.nim | |||
@@ -27,6 +27,13 @@ suite "integers": | |||
27 | check truncateToUint8(0x00FA'u16) == 0xFA'u8 | 27 | check truncateToUint8(0x00FA'u16) == 0xFA'u8 |
28 | check truncateToUint8(0xFFFA'u16) == 0xFA'u8 | 28 | check truncateToUint8(0xFFFA'u16) == 0xFA'u8 |
29 | 29 | ||
30 | test "leastSignificantBits": | ||
31 | check leastSignificantBits(0xFF'u8, 3) == 0b0000_0111'u8 | ||
32 | check leastSignificantBits(0b0001_0101'u8, 3) == 0b0000_0101'u8 | ||
33 | check leastSignificantBits(0xFF'u8, 10) == 0xFF'u8 | ||
34 | check leastSignificantBits(0xFFFF'u16, 16) == 0xFFFF'u16 | ||
35 | check leastSignificantBits(0xFFFF'u16, 8) == 0x00FF'u16 | ||
36 | |||
30 | test "chunks iterator": | 37 | test "chunks iterator": |
31 | check toSeq(chunks(70, uint32)) == @[(0, 32), (1, 32), (2, 6)] | 38 | check toSeq(chunks(70, uint32)) == @[(0, 32), (1, 32), (2, 6)] |
32 | check toSeq(chunks(32, uint16)) == @[(0, 16), (1, 16)] | 39 | check toSeq(chunks(32, uint16)) == @[(0, 16), (1, 16)] |