source: trunk/source/tests/ansi-tests/make-two-way-stream.lsp @ 8991

Last change on this file since 8991 was 8991, checked in by gz, 12 years ago

Check in the gcl ansi test suite (original, in preparation for making local changes)

File size: 6.9 KB
Line 
1;-*- Mode:     Lisp -*-
2;;;; Author:   Paul Dietz
3;;;; Created:  Fri Jan 30 05:39:56 2004
4;;;; Contains: Tests for MAKE-TWO-WAY-STREAM
5
6(in-package :cl-test)
7
8(deftest make-two-way-stream.1
9  (let* ((is (make-string-input-stream "foo"))
10         (os (make-string-output-stream))
11         (s (make-two-way-stream is os)))
12    (assert (typep s 'stream))
13    (assert (typep s 'two-way-stream))
14    (assert (streamp s))
15    (assert (open-stream-p s))
16    (assert (input-stream-p s))
17    (assert (output-stream-p s))
18    (assert (stream-element-type s))
19    (values
20     (read-char s)
21     (write-char #\b s)
22     (read-char s)
23     (write-char #\a s)
24     (read-char s)
25     (write-char #\r s)
26     (get-output-stream-string os)))
27  #\f #\b #\o #\a #\o #\r "bar")
28
29(deftest make-two-way-stream.2
30   (let* ((is (make-string-input-stream "foo"))
31          (os (make-string-output-stream))
32          (s (make-two-way-stream is os)))
33     (values
34      (close s)
35      (open-stream-p s)
36      (notnot (open-stream-p is))
37      (notnot (open-stream-p os))
38      (write-char #\8 os)
39      (get-output-stream-string os)))
40   t nil t t #\8 "8")
41
42(deftest make-two-way-stream.3
43   (let* ((is (make-string-input-stream "foo"))
44          (os (make-string-output-stream))
45          (s (make-two-way-stream is os)))
46     (values
47      (peek-char nil s)
48      (read-char s)
49      (get-output-stream-string os)))
50   #\f #\f "")
51
52(deftest make-two-way-stream.4
53   (let* ((is (make-string-input-stream "foo"))
54          (os (make-string-output-stream))
55          (s (make-two-way-stream is os)))
56     (values
57      (read-char-no-hang s)
58      (read-char-no-hang s nil)
59      (read-char-no-hang s t :eof)
60      (read-char-no-hang s nil :eof)
61      (get-output-stream-string os)))
62   #\f #\o #\o :eof "")
63
64(deftest make-two-way-stream.5
65   (let* ((is (make-string-input-stream "foo"))
66          (os (make-string-output-stream))
67          (s (make-two-way-stream is os)))
68     (values
69      (terpri s)
70      (get-output-stream-string os)))
71   nil #.(string #\Newline))
72
73(deftest make-two-way-stream.6
74   (let* ((is (make-string-input-stream "foo"))
75          (os (make-string-output-stream))
76          (s (make-two-way-stream is os)))
77     (values
78      (write-char #\+ s)
79      (notnot (fresh-line s))
80      (read-char s)
81      (get-output-stream-string os)))
82   #\+ t #\f #.(coerce (list #\+ #\Newline) 'string))
83
84(deftest make-two-way-stream.7
85   (let* ((is (make-string-input-stream "foo"))
86          (os (make-string-output-stream))
87          (s (make-two-way-stream is os)))
88     (values
89      (read-char s)
90      (unread-char #\f s)
91      (read-char s)
92      (read-char s)
93      (unread-char #\o s)
94      (get-output-stream-string os)))
95   #\f nil #\f #\o nil "")
96
97(deftest make-two-way-stream.8
98   (let* ((is (make-string-input-stream "foo"))
99          (os (make-string-output-stream))
100          (s (make-two-way-stream is os)))
101     (values
102      (read-line s)
103      (get-output-stream-string os)))
104   "foo" "")
105
106(deftest make-two-way-stream.9
107   (let* ((is (make-string-input-stream "foo"))
108          (os (make-string-output-stream))
109          (s (make-two-way-stream is os)))
110     (values
111      (write-string "bar" s)
112      (get-output-stream-string os)))
113   "bar" "bar")
114
115(deftest make-two-way-stream.10
116   (let* ((is (make-string-input-stream "foo"))
117          (os (make-string-output-stream))
118          (s (make-two-way-stream is os)))
119     (values
120      (write-line "bar" s)
121      (get-output-stream-string os)))
122   "bar" #.(concatenate 'string "bar" '(#\Newline)))
123
124(deftest make-two-way-stream.11
125  (let* ((is (make-string-input-stream "foo"))
126          (os (make-string-output-stream))
127          (s (make-two-way-stream is os)))
128    (let ((x (vector nil nil nil)))
129     (values
130      (read-sequence x s)
131      x
132      (get-output-stream-string os))))
133  3 #(#\f #\o #\o) "")
134
135(deftest make-two-way-stream.12
136  (let ((pn1 #p"tmp.dat")
137        (pn2 #p"tmp2.dat")
138        (element-type '(unsigned-byte 8)))
139    (with-open-file (s pn1 :direction :output :if-exists :supersede
140                       :element-type element-type)
141                    (dolist (b '(3 8 19 41)) (write-byte b s)))
142    (with-open-file
143     (is pn1 :direction :input :element-type element-type)
144     (with-open-file
145      (os pn2 :direction :output :element-type element-type
146          :if-exists :supersede)
147      (let ((s (make-two-way-stream is os))
148            (x (vector nil nil nil nil)))
149        (assert (eql (read-sequence x s) 4))
150        (assert (equalp x #(3 8 19 41)))
151        (let ((y #(100 5 18 211 0 178)))
152          (assert (eql (write-sequence y s) y))
153          (close s)))))
154    (with-open-file
155     (s pn2 :direction :input :element-type element-type)
156     (let ((x (vector nil nil nil nil nil nil nil)))
157       (values
158        (read-sequence x s)
159        x))))
160  6
161  #(100 5 18 211 0 178 nil))
162
163(deftest make-two-way-stream.13
164  (let ((pn1 #p"tmp.dat")
165        (pn2 #p"tmp2.dat")
166        (element-type '(unsigned-byte 32)))
167    (with-open-file (s pn1 :direction :output :if-exists :supersede
168                       :element-type element-type)
169                    (dolist (b '(3 8 19 41)) (write-byte b s)))
170    (with-open-file
171     (is pn1 :direction :input :element-type element-type)
172     (with-open-file
173      (os pn2 :direction :output :element-type element-type
174          :if-exists :supersede)
175      (let ((s (make-two-way-stream is os))
176            (x (vector nil nil nil nil)))
177        (assert (eql (read-sequence x s) 4))
178        (assert (equalp x #(3 8 19 41)))
179        (let ((y #(100 5 18 211 0 178)))
180          (assert (eql (write-sequence y s) y))
181          (close s)))))
182    (with-open-file
183     (s pn2 :direction :input :element-type element-type)
184     (let ((x (vector nil nil nil nil nil nil nil)))
185       (values
186        (read-sequence x s)
187        x))))
188  6
189  #(100 5 18 211 0 178 nil))
190
191(deftest make-two-way-stream.14
192  (let* ((is (make-string-input-stream "foo"))
193         (os (make-string-output-stream))
194         (s (make-two-way-stream is os)))
195    (values
196     (write-string "abc" s)
197     (clear-input s)
198     (write-string "def" s)
199     (get-output-stream-string os)))
200  "abc" nil "def" "abcdef")
201
202;;; Error tests
203
204(deftest make-two-way-stream.error.1
205  (signals-error (make-two-way-stream) program-error)
206  t)
207
208(deftest make-two-way-stream.error.2
209  (signals-error (make-two-way-stream (make-string-input-stream "foo"))
210                 program-error)
211  t)
212
213(deftest make-two-way-stream.error.3
214  (signals-error (let ((os (make-string-output-stream)))
215                   (make-two-way-stream (make-string-input-stream "foo")
216                                        os nil))
217                 program-error)
218  t)
219
220(deftest make-two-way-stream.error.4
221  (check-type-error #'(lambda (x) (make-two-way-stream x (make-string-output-stream)))
222                    #'(lambda (x) (and (streamp x) (input-stream-p x))))
223  nil)
224
225(deftest make-two-way-stream.error.5
226  (check-type-error #'(lambda (x) (make-two-way-stream x (make-string-output-stream)))
227                    #'(lambda (x) (and (streamp x) (input-stream-p x)))
228                    *streams*)
229  nil)
230
231(deftest make-two-way-stream.error.6
232  (check-type-error #'(lambda (x) (make-two-way-stream (make-string-input-stream "foo") x))
233                    #'(lambda (x) (and (streamp x) (output-stream-p x))))
234  nil)
235
236(deftest make-two-way-stream.error.7
237  (check-type-error #'(lambda (x) (make-two-way-stream (make-string-input-stream "foo") x))
238                    #'(lambda (x) (and (streamp x) (output-stream-p x)))
239                    *streams*)
240  nil)
241
242
243
244                                               
Note: See TracBrowser for help on using the repository browser.