diff options
author | pacien | 2018-12-03 22:21:36 +0100 |
---|---|---|
committer | pacien | 2018-12-03 22:21:36 +0100 |
commit | c34e84d7f3a1cb9aa85008645ff71a19d60671f8 (patch) | |
tree | 07c51c05b8e1ad5ee9b28b56d5b6705af29b0df9 /tests/blocks | |
parent | d1c7371f4918431df970fbee112eca4f073716cd (diff) | |
download | gziplike-master.tar.gz |
Diffstat (limited to 'tests/blocks')
-rw-r--r-- | tests/blocks/tlzssblock.nim | 48 | ||||
-rw-r--r-- | tests/blocks/trawblock.nim | 2 |
2 files changed, 49 insertions, 1 deletions
diff --git a/tests/blocks/tlzssblock.nim b/tests/blocks/tlzssblock.nim new file mode 100644 index 0000000..3cf6d57 --- /dev/null +++ b/tests/blocks/tlzssblock.nim | |||
@@ -0,0 +1,48 @@ | |||
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, blocks/lzssblock | ||
19 | |||
20 | suite "lzssblock": | ||
21 | test "identity": | ||
22 | let value = 0xFEDC_BA98_7654_3210'u64 | ||
23 | let rawStream = newStringStream() | ||
24 | defer: rawStream.close() | ||
25 | rawStream.write(value) | ||
26 | rawStream.setPosition(0) | ||
27 | let rawBitReader = rawStream.bitReader() | ||
28 | let rawBlock = lzssblock.readRaw(rawBitReader) | ||
29 | |||
30 | let serialisedStream = newStringStream() | ||
31 | defer: serialisedStream.close() | ||
32 | let serialisedBitWriter = serialisedStream.bitWriter() | ||
33 | rawBlock.writeSerialisedTo(serialisedBitWriter) | ||
34 | serialisedBitWriter.flush() | ||
35 | |||
36 | serialisedStream.setPosition(0) | ||
37 | let serialisedBitReader = serialisedStream.bitReader() | ||
38 | let lzssBlock = lzssblock.readSerialised(serialisedBitReader) | ||
39 | |||
40 | let outputStream = newStringStream() | ||
41 | defer: outputStream.close() | ||
42 | let outputBitWriter = outputStream.bitWriter() | ||
43 | rawBlock.writeRawTo(outputBitWriter) | ||
44 | outputBitWriter.flush() | ||
45 | |||
46 | outputStream.setPosition(0) | ||
47 | check outputStream.readUint64 == value | ||
48 | check outputStream.atEnd() | ||
diff --git a/tests/blocks/trawblock.nim b/tests/blocks/trawblock.nim index 2426899..550f772 100644 --- a/tests/blocks/trawblock.nim +++ b/tests/blocks/trawblock.nim | |||
@@ -44,7 +44,7 @@ suite "rawblock": | |||
44 | serialisedStream.write(0xFEDC_BA98_7654_3210'u64) | 44 | serialisedStream.write(0xFEDC_BA98_7654_3210'u64) |
45 | serialisedStream.setPosition(0) | 45 | serialisedStream.setPosition(0) |
46 | let serialisedBitReader = serialisedStream.bitReader() | 46 | let serialisedBitReader = serialisedStream.bitReader() |
47 | let rawBlock = rawBlock.readSerialised(serialisedBitReader) | 47 | let rawBlock = rawblock.readSerialised(serialisedBitReader) |
48 | 48 | ||
49 | let outputStream = newStringStream() | 49 | let outputStream = newStringStream() |
50 | defer: outputStream.close() | 50 | defer: outputStream.close() |