diff options
author | Piotr Szarmanski | 2022-09-22 11:16:44 +0200 |
---|---|---|
committer | Piotr Szarmanski | 2022-09-22 11:16:44 +0200 |
commit | 4d82ef18a8bb18317be3e089f432f95b6e5dbd4a (patch) | |
tree | bfa28af036aeb0f3e41298867c449318675b5a07 /tests | |
parent | fdf5daa317c8a97ef8197200403db6f53a8f1777 (diff) |
Implement stream-read-byte
Diffstat (limited to 'tests')
-rw-r--r-- | tests/decode-tests.lisp | 43 |
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)) + |