make-broadcast-stream.lsp 2.79 KB
Newer Older
1 2 3 4 5 6 7 8 9
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Thu Jan 29 21:28:25 2004
;;;; Contains: Tests of MAKE-BROADCAST-STREAM

(in-package :cl-test)

(deftest make-broadcast-stream.1
  (let ((s (make-broadcast-stream)))
10 11 12
    (assert (typep s 'stream))
    (assert (typep s 'broadcast-stream))
    (assert (output-stream-p s))
13
    ;; (assert (not (input-stream-p s)))
14 15
    (assert (open-stream-p s))
    (assert (streamp s))
16
    ;; (assert (eq (stream-element-type s) t))
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
    (values
     (notnot (typep s 'stream))
     (notnot (typep s 'broadcast-stream))
     (notnot (output-stream-p s))
     (progn (write-char #\x s) nil)
     ))
  t t t nil)

(deftest make-broadcast-stream.2
  (with-output-to-string
    (s1)
    (let ((s (make-broadcast-stream s1)))
      (assert (typep s 'stream))
      (assert (typep s 'broadcast-stream))
      (assert (output-stream-p s))
32
      ;; (assert (not (input-stream-p s)))
33 34
      (assert (open-stream-p s))
      (assert (streamp s))
35
      (assert (eql (stream-element-type s)
sds's avatar
sds committed
36
                   (stream-element-type s1)))
37 38 39 40 41
      (write-char #\x s)))
  "x")

(deftest make-broadcast-stream.3
  (let ((s1 (make-string-output-stream))
sds's avatar
sds committed
42
        (s2 (make-string-output-stream)))
43
    (let ((s (make-broadcast-stream s1 s2)))
44 45 46
      (assert (typep s 'stream))
      (assert (typep s 'broadcast-stream))
      (assert (output-stream-p s))
47
      ;; (assert (not (input-stream-p s)))
48 49
      (assert (open-stream-p s))
      (assert (streamp s))
50
      (assert (eql (stream-element-type s)
sds's avatar
sds committed
51
                   (stream-element-type s2)))
52 53 54 55 56 57 58
      (format s "This is a test"))
    (values
     (get-output-stream-string s1)
     (get-output-stream-string s2)))
  "This is a test"
  "This is a test")

59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
(deftest make-broadcast-stream.4
  (fresh-line (make-broadcast-stream))
  nil)

(deftest make-broadcast-stream.5
  (file-length (make-broadcast-stream))
  0)

(deftest make-broadcast-stream.6
  (file-position (make-broadcast-stream))
  0)

(deftest make-broadcast-stream.7
  (file-string-length (make-broadcast-stream) "antidisestablishmentarianism")
  1)

(deftest make-broadcast-stream.8
  (stream-external-format (make-broadcast-stream))
  :default)



81
;;; FIXME
82
;;; Add tests for: close,
83 84 85 86 87 88 89
;;;  peek-char, read-char-no-hang, terpri, fresh-line, unread-char,
;;;  read-line, write-line, write-string, read-sequence, write-sequence,
;;;  read-byte, write-byte, listen, clear-input, finish-output, force-output,
;;;  clear-output, print, prin1 princ

;;; Error tests

90
(deftest make-broadcast-stream.error.1
pfdietz's avatar
pfdietz committed
91
  (check-type-error #'make-broadcast-stream
sds's avatar
sds committed
92
                    #'(lambda (x) (and (streamp x) (output-stream-p x))))
93 94 95
  nil)

(deftest make-broadcast-stream.error.2
pfdietz's avatar
pfdietz committed
96
  (check-type-error #'make-broadcast-stream
sds's avatar
sds committed
97 98
                    #'(lambda (x) (and (streamp x) (output-stream-p x)))
                    *streams*)
99
  nil)