source: trunk/source/tests/ansi-tests/make-concatenated-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: 8.1 KB
Line 
1;-*- Mode:     Lisp -*-
2;;;; Author:   Paul Dietz
3;;;; Created:  Sat Feb 14 08:41:18 2004
4;;;; Contains: Tests of MAKE-CONCATENATED-STREAM
5
6(in-package :cl-test)
7
8(deftest make-concatenated-stream.1
9  (let ((s (make-concatenated-stream)))
10    (read s nil :eof))
11  :eof)
12
13(deftest make-concatenated-stream.2
14  (let ((s (make-concatenated-stream)))
15    (notnot-mv (input-stream-p s)))
16  t)
17
18(deftest make-concatenated-stream.3
19  (let ((s (make-concatenated-stream)))
20    (output-stream-p s))
21  nil)
22
23(deftest make-concatenated-stream.4
24  (let ((s (make-concatenated-stream)))
25    (notnot-mv (streamp s)))
26  t)
27
28(deftest make-concatenated-stream.5
29  (let ((s (make-concatenated-stream)))
30    (notnot-mv (typep s 'stream)))
31  t)
32
33(deftest make-concatenated-stream.6
34  (let ((s (make-concatenated-stream)))
35    (notnot-mv (typep s 'concatenated-stream)))
36  t)
37
38(deftest make-concatenated-stream.7
39  (let ((s (make-concatenated-stream)))
40    (notnot-mv (open-stream-p s)))
41  t)
42
43(deftest make-concatenated-stream.8
44  (let ((s (make-concatenated-stream *standard-input*)))
45    (notnot-mv (stream-element-type s)))
46  t)
47
48(deftest make-concatenated-stream.9
49  (let ((pn #p"tmp.dat")
50        (element-type '(unsigned-byte 8)))
51    (with-open-file (s pn :direction :output :element-type element-type
52                       :if-exists :supersede)
53                    (dolist (b '(1 5 9 13)) (write-byte b s)))
54    (with-open-file
55     (s1 pn :direction :input :element-type element-type)
56     (with-open-file
57      (s2 pn :direction :input :element-type element-type)
58      (let ((s (make-concatenated-stream s1 s2)))
59        (loop repeat 8 collect (read-byte s))))))
60  (1 5 9 13 1 5 9 13))
61
62(deftest make-concatenated-stream.10
63  (let ((s (make-concatenated-stream)))
64    (read-byte s nil :eof))
65  :eof)
66
67(deftest make-concatenated-stream.11
68  (let ((s (make-concatenated-stream)))
69    (peek-char nil s nil :eof))
70  :eof)
71
72(deftest make-concatenated-stream.12
73  (with-input-from-string
74   (s1 "a")
75   (with-input-from-string
76    (s2 "b")
77    (let ((s (make-concatenated-stream s1 s2)))
78      (values
79       (peek-char nil s)
80       (read-char s)
81       (peek-char nil s)
82       (read-char s)
83       (peek-char nil s nil :eof)))))
84  #\a #\a #\b #\b :eof)
85
86(deftest make-concatenated-stream.13
87  (with-input-from-string
88   (s1 "  a  ")
89   (with-input-from-string
90    (s2 "  b  ")
91    (let ((s (make-concatenated-stream s1 s2)))
92      (values
93       (peek-char t s)
94       (read-char s)
95       (peek-char t s)
96       (read-char s)
97       (peek-char t s nil :eof)))))
98  #\a #\a #\b #\b :eof)
99
100(deftest make-concatenated-stream.14
101  (with-input-from-string
102   (s1 "a")
103   (with-input-from-string
104    (s2 "b")
105    (let ((s (make-concatenated-stream s1 s2)))
106      (values
107       (read-char s)
108       (unread-char #\a s)
109       (read-char s)
110       (read-char s)
111       (unread-char #\b s)
112       (read-char s)
113       (read-char s nil :eof)))))
114  #\a nil #\a #\b nil #\b :eof)
115
116(deftest make-concatenated-stream.15
117  (let ((s (make-concatenated-stream)))
118    (read-char-no-hang s nil :eof))
119  :eof)
120
121(deftest make-concatenated-stream.16
122  (with-input-from-string
123   (s1 "a")
124   (with-input-from-string
125    (s2 "b")
126    (let ((s (make-concatenated-stream s1 s2)))
127      (values
128       (read-char-no-hang s)
129       (read-char-no-hang s)
130       (read-char-no-hang s nil :eof)))))
131  #\a #\b :eof)
132
133(deftest make-concatenated-stream.17
134  (with-input-from-string
135   (s1 "a")
136   (with-input-from-string
137    (s2 "b")
138    (let ((s (make-concatenated-stream s1 s2)))
139      (multiple-value-bind (str mnp)
140          (read-line s)
141        (values str (notnot mnp))))))
142  "ab" t)
143
144(deftest make-concatenated-stream.18
145  (with-input-from-string
146   (s1 "ab")
147   (with-input-from-string
148    (s2 "")
149    (let ((s (make-concatenated-stream s1 s2)))
150      (multiple-value-bind (str mnp)
151          (read-line s)
152        (values str (notnot mnp))))))
153  "ab" t)
154
155(deftest make-concatenated-stream.19
156  (with-input-from-string
157   (s1 "")
158   (with-input-from-string
159    (s2 "ab")
160    (let ((s (make-concatenated-stream s1 s2)))
161      (multiple-value-bind (str mnp)
162          (read-line s)
163        (values str (notnot mnp))))))
164  "ab" t)
165
166(deftest make-concatenated-stream.20
167  (with-input-from-string
168   (s1 "ab")
169   (with-input-from-string
170    (s2 (concatenate 'string (string #\Newline) "def"))
171    (let ((s (make-concatenated-stream s1 s2)))
172      (read-line s))))
173  "ab" nil)
174
175(deftest make-concatenated-stream.21
176  (with-input-from-string
177   (s1 "")
178   (with-input-from-string
179    (s2 "")
180    (let ((s (make-concatenated-stream s1 s2)))
181      (multiple-value-bind (str mnp)
182          (read-line s nil :eof)
183        (values str (notnot mnp))))))
184  :eof t)
185
186(deftest make-concatenated-stream.22
187  (let ((pn #p"tmp.dat")
188        (element-type '(unsigned-byte 8)))
189    (with-open-file (s pn :direction :output :element-type element-type
190                       :if-exists :supersede)
191                    (dolist (b '(1 5 9 13)) (write-byte b s)))
192    (with-open-file
193     (s1 pn :direction :input :element-type element-type)
194     (with-open-file
195      (s2 pn :direction :input :element-type element-type)
196      (let ((s (make-concatenated-stream s1 s2))
197            (x (vector nil nil nil nil nil nil nil nil)))
198        (values
199         (read-sequence x s)
200         x)))))
201  8
202  #(1 5 9 13 1 5 9 13))
203
204(deftest make-concatenated-stream.23
205  (let ((pn #p"tmp.dat")
206        (element-type '(unsigned-byte 8)))
207    (with-open-file (s pn :direction :output :element-type element-type
208                       :if-exists :supersede)
209                    (dolist (b '(1 5 9 13)) (write-byte b s)))
210    (with-open-file
211     (s1 pn :direction :input :element-type element-type)
212     (with-open-file
213      (s2 pn :direction :input :element-type element-type)
214      (let ((s (make-concatenated-stream s1 s2))
215            (x (vector nil nil nil nil nil nil)))
216        (values
217         (read-sequence x s)
218         x)))))
219  6
220  #(1 5 9 13 1 5))
221
222(deftest make-concatenated-stream.24
223  (let ((pn #p"tmp.dat")
224        (element-type '(unsigned-byte 8)))
225    (with-open-file (s pn :direction :output :element-type element-type
226                       :if-exists :supersede)
227                    (dolist (b '(1 5 9 13)) (write-byte b s)))
228    (with-open-file
229     (s1 pn :direction :input :element-type element-type)
230     (with-open-file
231      (s2 pn :direction :input :element-type element-type)
232      (let ((s (make-concatenated-stream s1 s2))
233            (x (vector nil nil nil nil nil nil nil nil nil nil)))
234        (values
235         (read-sequence x s)
236         x)))))
237  8
238  #(1 5 9 13 1 5 9 13 nil nil))
239
240(deftest make-concatenated-stream.25
241  (close (make-concatenated-stream))
242  t)
243
244(deftest make-concatenated-stream.26
245  (let ((s (make-concatenated-stream)))
246    (values (prog1 (close s) (close s))
247            (open-stream-p s)))
248  t nil)
249
250(deftest make-concatenated-stream.27
251  (with-input-from-string
252   (s1 "abc")
253   (let ((s (make-concatenated-stream s1)))
254     (values
255      (notnot (open-stream-p s1))
256      (notnot (open-stream-p s))
257      (close s)
258      (notnot (open-stream-p s1))
259      (open-stream-p s))))
260  t t t t nil)
261
262(deftest make-concatenated-stream.28
263  (with-input-from-string
264   (s1 "a")
265   (let ((s (make-concatenated-stream s1)))
266     (notnot-mv (listen s))))
267  t)
268
269(deftest make-concatenated-stream.28a
270  (listen (make-concatenated-stream))
271  nil)
272
273(deftest make-concatenated-stream.29
274  (with-input-from-string
275   (s1 "")
276   (let ((s (make-concatenated-stream s1)))
277     (listen s)))
278  nil)
279
280(deftest make-concatenated-stream.30
281  (with-input-from-string
282   (s1 "")
283   (with-input-from-string
284    (s2 "a")
285    (let ((s (make-concatenated-stream s1 s2)))
286      (notnot-mv (listen s)))))
287  t)
288
289(deftest make-concatenated-stream.31
290  (with-input-from-string
291   (s1 "")
292   (with-input-from-string
293    (s2 "")
294    (let ((s (make-concatenated-stream s1 s2)))
295      (listen s))))
296  nil)
297
298(deftest make-concatenated-stream.32
299  (clear-input (make-concatenated-stream))
300  nil)
301
302(deftest make-concatenated-stream.33
303  (with-input-from-string
304   (s1 "abc")
305   (clear-input (make-concatenated-stream s1)))
306  nil)
307
308;;; Error cases
309
310(deftest make-concatenated-stream.error.1
311  (loop for x in *mini-universe*
312        unless (or (and (streamp x) (input-stream-p x))
313                   (eval `(signals-error (make-concatenated-stream ',x) t)))
314        collect x)
315  nil)
316
317(deftest make-concatenated-stream.error.2
318  (loop for x in *streams*
319        unless (or (and (streamp x) (input-stream-p x))
320                   (eval `(signals-error (make-concatenated-stream ',x) t)))
321        collect x)
322  nil)
323
Note: See TracBrowser for help on using the repository browser.