X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=tests%2Fgray-streams.impure.lisp;h=ab827debdfc3c3db90856724d6f6cfc82d4f6d3e;hb=cf49f2d086069a9c1b57f501df9a6a0bd3a34c3c;hp=f20c68b5fe674ad382ceaaa68da8fd8b363fe902;hpb=175c318c892b0627b36fa3c4db66f59680242204;p=sbcl.git diff --git a/tests/gray-streams.impure.lisp b/tests/gray-streams.impure.lisp index f20c68b..ab827de 100644 --- a/tests/gray-streams.impure.lisp +++ b/tests/gray-streams.impure.lisp @@ -60,7 +60,8 @@ (defclass character-output-stream (fundamental-character-output-stream) ((lisp-stream :initarg :lisp-stream - :accessor character-output-stream-lisp-stream))) + :accessor character-output-stream-lisp-stream) + (position :initform 42 :accessor character-output-stream-position))) (defclass character-input-stream (fundamental-character-input-stream) ((lisp-stream :initarg :lisp-stream @@ -100,6 +101,11 @@ (defmethod stream-clear-output ((stream character-output-stream)) (clear-output (character-output-stream-lisp-stream stream))) + +(defmethod stream-file-position ((stream character-output-stream) &optional new-value) + (if new-value + (setf (character-output-stream-position stream) new-value) + (character-output-stream-position stream))) ;;;; example character input stream encapsulating a lisp-stream @@ -271,3 +277,62 @@ ((eq byte :eof)) (write-byte byte our-bin-to-char-output)))) test-string)))) + + + +;;; Minimal test of file-position +(let ((stream (make-instance 'character-output-stream))) + (assert (= (file-position stream) 42)) + (assert (file-position stream 50)) + (assert (= (file-position stream) 50))) + +;;; Using gray streams as parts of two-way-, concatenate-, and synonym-streams. + +(defvar *gray-binary-data* + (let ((vector (make-array 1024 :element-type '(unsigned-byte 8) :fill-pointer 0))) + (dotimes (i (length vector)) + (setf (aref vector i) (random 256))) + vector)) + +(defun vector-hop-or-eof (vector) + (let ((pos (fill-pointer vector))) + (if (< pos (array-total-size vector)) + (prog1 + (aref vector pos) + (incf (fill-pointer vector))) + :eof))) + +(defclass part-of-composite-stream (fundamental-binary-input-stream) + ()) + +(defmethod stream-read-byte ((stream part-of-composite-stream)) + (vector-hop-or-eof *gray-binary-data*)) + +(defmethod stream-element-type ((stream part-of-composite-stream)) + '(unsigned-byte 8)) + +(defvar *part-of-composite* (make-instance 'part-of-composite-stream)) + +(defun test-composite-reads (&rest streams) + (dolist (stream streams) + (setf (fill-pointer *gray-binary-data*) 0) + (let ((binary-buffer (make-array 1024 :element-type '(unsigned-byte 8)))) + (assert (eql 1024 (read-sequence binary-buffer stream))) + (dotimes (i 1024) + (unless (eql (aref *gray-binary-data* i) + (aref binary-buffer i)) + (error "wanted ~S at ~S, got ~S (~S)" + (aref *gray-binary-data* i) + i + (aref binary-buffer i) + stream)))))) + +(test-composite-reads + (make-two-way-stream *part-of-composite* *standard-output*) + (make-concatenated-stream *part-of-composite*) + (make-synonym-stream '*part-of-composite*)) + +;;; Using STREAM-FILE-POSITION on an ANSI-STREAM +(with-output-to-string (s) + (assert (zerop (file-position s))) + (assert (zerop (stream-file-position s))))