summaryrefslogtreecommitdiff
path: root/tests/decode-tests.lisp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/decode-tests.lisp')
-rw-r--r--tests/decode-tests.lisp43
1 files changed, 41 insertions, 2 deletions
diff --git a/tests/decode-tests.lisp b/tests/decode-tests.lisp
index 2cd359a..af3edb0 100644
--- a/tests/decode-tests.lisp
+++ b/tests/decode-tests.lisp
@@ -83,8 +83,6 @@
else
do (replace decoded-array buf :start1 (* i s)))))))
-(assert-bytes-read-4096 (make-octets 16383 :element 1) 1024 (4096 4096 4096 4095))
-
(test simple-decoding-1kib
(assert-array-decode (make-octets 1 :element 1) 1024)
(assert-array-decode (make-octets 1023 :element 2) 1024)
@@ -204,3 +202,44 @@
(assert-length (make-array 16384 :element-type '(unsigned-byte 8) :initial-element 2) 1024))
+(defmacro assert-read-byte (array block-size)
+ `(let* ((*table* (make-hash-table :test #'equalp))
+ (array ,array)
+ (read-capability (eris-encode array ,block-size #'hashtable-encode))
+ (decoded-array (make-array (length array) :element-type '(unsigned-byte 8) :fill-pointer 0))
+ (stream (eris-decode read-capability #'hashtable-decode)))
+ (loop for i = (read-byte stream nil :eof)
+ until (eq i :eof)
+ do (vector-push i decoded-array))
+ (is (equalp decoded-array array))))
+
+(test check-read-byte
+ (assert-read-byte (make-octets 1 :element 2) 1024)
+ (assert-read-byte (make-octets 512 :element 2) 1024)
+ (assert-read-byte (make-octets 1023 :element 2) 1024)
+ (assert-read-byte (make-octets 1024 :element 2) 1024)
+ (assert-read-byte (make-octets 16383 :element 2) 1024)
+ (assert-read-byte (make-octets 16384 :element 2) 1024)
+ (assert-read-byte (make-octets 1024 :element 2) 32kib)
+ (assert-read-byte (make-octets 32767 :element 2) 32kib)
+ (assert-read-byte (make-octets 32768 :element 2) 32kib)
+ (assert-read-byte (make-octets 64000 :element 2) 32kib))
+
+(defmacro assert-read-byte-error (array block-size)
+ `(let* ((*table* (make-hash-table :test #'equalp))
+ (array ,array)
+ (read-capability (eris-encode array ,block-size #'hashtable-encode))
+ (stream (eris-decode read-capability #'hashtable-decode)))
+ (signals end-of-file
+ (loop for i = (read-byte stream t)
+ for n = 0 then (incf n)
+ until (eql n (length array))))))
+
+(test read-byte-eof
+ (assert-read-byte-error (make-octets 1 :element 2) 1024)
+ (assert-read-byte-error (make-octets 1024 :element 2) 1024)
+ (assert-read-byte-error (make-octets 16383 :element 2) 1024)
+ (assert-read-byte-error (make-octets 1024 :element 2) 32kib)
+ (assert-read-byte-error (make-octets 32767 :element 2) 32kib)
+ (assert-read-byte-error (make-octets 32768 :element 2) 32kib))
+