aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorpacien2018-12-03 22:21:36 +0100
committerpacien2018-12-03 22:21:36 +0100
commitc34e84d7f3a1cb9aa85008645ff71a19d60671f8 (patch)
tree07c51c05b8e1ad5ee9b28b56d5b6705af29b0df9 /tests
parentd1c7371f4918431df970fbee112eca4f073716cd (diff)
downloadgziplike-c34e84d7f3a1cb9aa85008645ff71a19d60671f8.tar.gz
add lzss block testHEADmaster
Diffstat (limited to 'tests')
-rw-r--r--tests/blocks/tlzssblock.nim48
-rw-r--r--tests/blocks/trawblock.nim2
-rw-r--r--tests/tests.nim2
3 files changed, 50 insertions, 2 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()
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()
diff --git a/tests/tests.nim b/tests/tests.nim
index 23b6e1c..7d09347 100644
--- a/tests/tests.nim
+++ b/tests/tests.nim
@@ -36,7 +36,7 @@ import
36 lzsshuffman/tlzsshuffmandecoder, 36 lzsshuffman/tlzsshuffmandecoder,
37 37
38 blocks/trawblock, 38 blocks/trawblock,
39 # TODO: add lzssblock test 39 blocks/tlzssblock,
40 blocks/streamblock, 40 blocks/streamblock,
41 41
42 gziplike/tgziplike 42 gziplike/tgziplike