diff options
author | pacien | 2018-11-30 21:06:39 +0100 |
---|---|---|
committer | pacien | 2018-11-30 21:06:39 +0100 |
commit | 1f0c6a7638353d1ebbbc4ba1a8de0887d5f68e98 (patch) | |
tree | ed9867c9997e9ceee750194fe8aaaa6f067a93f1 /tests/tstreamblock.nim | |
parent | 3d5a87a5879aa724e47546d1bdbb7f6c9466cf94 (diff) | |
download | gziplike-1f0c6a7638353d1ebbbc4ba1a8de0887d5f68e98.tar.gz |
isolate blocks
Diffstat (limited to 'tests/tstreamblock.nim')
-rw-r--r-- | tests/tstreamblock.nim | 68 |
1 files changed, 0 insertions, 68 deletions
diff --git a/tests/tstreamblock.nim b/tests/tstreamblock.nim deleted file mode 100644 index 57eaf3a..0000000 --- a/tests/tstreamblock.nim +++ /dev/null | |||
@@ -1,68 +0,0 @@ | |||
1 | # gzip-like LZSS compressor | ||
2 | # Copyright (C) 2018 Pacien TRAN-GIRARD | ||
3 | # | ||
4 | # This program is free software: you can redistribute it and/or modify | ||
5 | # it under the terms of the GNU Affero General Public License as | ||
6 | # published by the Free Software Foundation, either version 3 of the | ||
7 | # License, or (at your option) any later version. | ||
8 | # | ||
9 | # This program is distributed in the hope that it will be useful, | ||
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | # GNU Affero General Public License for more details. | ||
13 | # | ||
14 | # You should have received a copy of the GNU Affero General Public License | ||
15 | # along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
16 | |||
17 | import unittest, streams | ||
18 | import bitio/bitreader, bitio/bitwriter, streamblock | ||
19 | |||
20 | suite "streamblock": | ||
21 | test "serialise": | ||
22 | let rawStream = newStringStream() | ||
23 | defer: rawStream.close() | ||
24 | rawStream.write(0xFEDC_BA98_7654_3210'u64) | ||
25 | rawStream.setPosition(0) | ||
26 | let rawBitReader = rawStream.bitReader() | ||
27 | let streamBlock = readRaw(rawBitReader, uncompressed) | ||
28 | check streamBlock.isLast() | ||
29 | |||
30 | let outputStream = newStringStream() | ||
31 | defer: outputStream.close() | ||
32 | let outputBitWriter = outputStream.bitWriter() | ||
33 | streamBlock.writeSerialisedTo(outputBitWriter) | ||
34 | outputBitWriter.flush() | ||
35 | |||
36 | outputStream.setPosition(0) | ||
37 | let produceReader = outputStream.bitReader() | ||
38 | check produceReader.readBool() == true # last block flag | ||
39 | check produceReader.readBits(2, uint8) == 0x00'u8 # block kind | ||
40 | check produceReader.readBits(16, uint16) == 64 # raw block length | ||
41 | check produceReader.readSeq(64, uint8) == (64, @[0x10'u8, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE]) # raw block content | ||
42 | discard produceReader.readBits(8 - 2 - 1, uint8) | ||
43 | check produceReader.atEnd() | ||
44 | |||
45 | test "deserialise": | ||
46 | let serialisedStream = newStringStream() | ||
47 | defer: serialisedStream.close() | ||
48 | let serialisedBitWriter = serialisedStream.bitWriter() | ||
49 | serialisedBitWriter.writeBool(true) | ||
50 | serialisedBitWriter.writeBits(2, 0x00'u8) | ||
51 | serialisedBitWriter.writeBits(16, 64'u16) | ||
52 | serialisedBitWriter.writeBits(64, 0xFEDC_BA98_7654_3210'u64) | ||
53 | serialisedBitWriter.flush() | ||
54 | |||
55 | serialisedStream.setPosition(0) | ||
56 | let serialisedBitReader = serialisedStream.bitReader() | ||
57 | let streamBlock = readSerialised(serialisedBitReader) | ||
58 | |||
59 | let outputStream = newStringStream() | ||
60 | defer: outputStream.close() | ||
61 | let outputBitWriter = outputStream.bitWriter() | ||
62 | check streamBlock.isLast() | ||
63 | streamBlock.writeRawTo(outputBitWriter) | ||
64 | outputBitWriter.flush() | ||
65 | |||
66 | outputStream.setPosition(0) | ||
67 | check outputStream.readUint64 == 0xFEDC_BA98_7654_3210'u64 | ||
68 | check outputStream.atEnd() | ||