aboutsummaryrefslogtreecommitdiff
path: root/tests/blocks/tlzssblock.nim
diff options
context:
space:
mode:
Diffstat (limited to 'tests/blocks/tlzssblock.nim')
-rw-r--r--tests/blocks/tlzssblock.nim48
1 files changed, 48 insertions, 0 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
17import unittest, streams
18import bitio/bitreader, bitio/bitwriter, blocks/lzssblock
19
20suite "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()