source: trunk/source/tests/ansi-tests/file-length.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: 4.5 KB
Line 
1;-*- Mode:     Lisp -*-
2;;;; Author:   Paul Dietz
3;;;; Created:  Wed Jan 21 06:21:11 2004
4;;;; Contains: Tests of FILE-LENGTH
5
6(in-package :cl-test)
7
8(deftest file-length.error.1
9  (signals-error (file-length) program-error)
10  t)
11
12(deftest file-length.error.2
13  (signals-error
14   (with-open-file (is "file-length.lsp" :direction :input)
15                   (file-length is nil))
16   program-error)
17  t)
18
19(deftest file-length.error.3
20  (loop for x in *mini-universe*
21        unless (or (typep x 'file-stream)
22                   (typep x 'broadcast-stream)
23                   (handler-case (progn (file-length x) nil)
24                                 (type-error (c)
25                                             (assert (not (typep x (type-error-expected-type c))))
26                                             t)
27                                 (condition () nil)))
28        collect x)
29  nil)
30
31(deftest file-length.error.4
32  :notes (:assume-no-simple-streams :assume-no-gray-streams)
33  (signals-error (with-input-from-string (s "abc") (file-length s))
34                 type-error)
35  t)
36
37(deftest file-length.error.5
38  (signals-error
39   (with-open-file
40    (is "file-length.lsp" :direction :input)
41    (with-open-file
42     (os "tmp.txt" :direction :output :if-exists :supersede)
43     (let ((s (make-two-way-stream is os)))
44       (unwind-protect (file-length s) (close s)))))
45   type-error)
46  t)
47
48(deftest file-length.error.6
49  (signals-error
50   (with-open-file
51    (is "file-length.lsp" :direction :input)
52    (with-open-file
53     (os "tmp.txt" :direction :output :if-exists :supersede)
54     (let ((s (make-echo-stream is os)))
55       (unwind-protect (file-length s) (close s)))))
56   type-error)
57  t)
58
59(deftest file-length.error.8
60  (with-open-file
61   (os "tmp.txt" :direction :output :if-exists :supersede)
62   (let ((s (make-broadcast-stream os)))
63     (eqlt (file-length s) (file-length os))))
64  t)
65
66(deftest file-length.error.9
67  (signals-type-error s (make-concatenated-stream)
68                      (unwind-protect (file-length s) (close s)))
69  t)
70
71(deftest file-length.error.10
72  (signals-error
73   (with-open-file
74    (is "file-length.lsp" :direction :input)
75    (let ((s (make-concatenated-stream is)))
76      (unwind-protect (file-length s) (close s))))
77   type-error)
78  t)
79
80(deftest file-length.error.11
81  :notes (:assume-no-simple-streams :assume-no-gray-streams)
82  (signals-type-error s (make-string-input-stream "abcde")
83                      (unwind-protect (file-length s) (close s)))
84  t)
85
86(deftest file-length.error.12
87  :notes (:assume-no-simple-streams :assume-no-gray-streams)
88  (signals-type-error s (make-string-output-stream)
89                      (unwind-protect (file-length s) (close s)))
90  t)
91
92;;; Non-error tests
93
94(deftest file-length.1
95  (let ((results (multiple-value-list
96                  (with-open-file
97                   (is "file-length.lsp" :direction :input)
98                   (file-length is)))))
99    (and (= (length results) 1)
100         (typep (car results) '(integer 1))
101         t))
102  t)
103
104(deftest file-length.2
105  (loop for i from 1 to 32
106        for etype = `(unsigned-byte ,i)
107        for e = (max 0 (- (ash 1 i) 5))
108        for os = (open "tmp.dat" :direction :output
109                               :if-exists :supersede
110                               :element-type etype)
111        do (loop repeat 17 do (write-byte e os))
112        do (finish-output os)
113        unless (= (file-length os) 17)
114        collect (list i (file-length os))
115        do (close os))
116  nil)
117
118(deftest file-length.3
119  (loop for i from 1 to 32
120        for etype = `(unsigned-byte ,i)
121        for e = (max 0 (- (ash 1 i) 5))
122        for os = (open "tmp.dat" :direction :output
123                               :if-exists :supersede
124                               :element-type etype)
125        for len = 0
126        do (loop repeat 17 do (write-byte e os))
127        do (close os)
128        unless (let ((is (open "tmp.dat" :direction :input
129                               :element-type etype)))
130                 (prog1
131                     (= (file-length is) 17)
132                   (close is)))
133        collect i)
134  nil)
135
136(deftest file-length.4
137  (loop for i from 33 to 100
138        for etype = `(unsigned-byte ,i)
139        for e = (max 0 (- (ash 1 i) 5))
140        for os = (open "tmp.dat" :direction :output
141                               :if-exists :supersede
142                               :element-type etype)
143        do (loop repeat 17 do (write-byte e os))
144        do (finish-output os)
145        unless (= (file-length os) 17)
146        collect (list i (file-length os))
147        do (close os))
148  nil)
149
150(deftest file-length.5
151  (loop for i from 33 to 100
152        for etype = `(unsigned-byte ,i)
153        for e = (max 0 (- (ash 1 i) 5))
154        for os = (open "tmp.dat" :direction :output
155                               :if-exists :supersede
156                               :element-type etype)
157        for len = 0
158        do (loop repeat 17 do (write-byte e os))
159        do (close os)
160        unless (let ((is (open "tmp.dat" :direction :input
161                               :element-type etype)))
162                 (prog1
163                     (= (file-length is) 17)
164                   (close is)))
165        collect i)
166  nil)           
167
168(deftest file-length.6
169  (with-open-file
170   (*foo* "file-length.lsp" :direction :input)
171   (declare (special *foo*))
172   (let ((s (make-synonym-stream '*foo*)))
173     (unwind-protect
174         (typep* (file-length s) '(integer 1))
175        (close s))))
176  t)
Note: See TracBrowser for help on using the repository browser.