source: trunk/source/tests/ansi-tests/file-position.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.1 KB
Line 
1;-*- Mode:     Lisp -*-
2;;;; Author:   Paul Dietz
3;;;; Created:  Thu Jan 22 03:02:31 2004
4;;;; Contains: Tests of FILE-POSITION
5
6(in-package :cl-test)
7
8(deftest file-position.1
9  (with-open-file (is "file-position.lsp":direction :input)
10                  (file-position is))
11  0)
12
13(deftest file-position.2
14  (with-open-file (is "file-position.lsp":direction :input)
15                  (values
16                   (multiple-value-list
17                    (notnot-mv (file-position is :start)))
18                   (file-position is)))
19                             
20  (t) 0)
21
22(deftest file-position.3
23  (with-open-file (is "file-position.lsp":direction :input)
24                  (values
25                   (multiple-value-list
26                    (notnot-mv (file-position is :end)))
27                   (notnot (> (file-position is) 0))))
28  (t) t)
29
30(deftest file-position.4
31  (with-open-file
32   (is "file-position.lsp":direction :input)
33   (values
34    (file-position is)
35    (read-char is)
36    (notnot (> (file-position is) 0))))
37  0 #\; t)
38
39(deftest file-position.5
40  (with-open-file
41   (os "tmp.dat":direction :output
42       :if-exists :supersede)
43   (values
44    (file-position os)
45    (write-char #\x os)
46    (notnot (> (file-position os) 0))))
47  0 #\x t)
48
49(deftest file-position.6
50  (with-open-file
51   (os "tmp.dat":direction :output
52       :if-exists :supersede)
53   (let ((p1 (file-position os))
54         (delta (file-string-length os #\x)))
55     (write-char #\x os)
56     (let ((p2 (file-position os)))
57       (or (null p1) (null p2) (null delta)
58           (=t (+ p1 delta) p2)))))
59  t)
60
61;;; Byte streams
62
63(deftest file-position.7
64  (loop for len from 1 to 32
65        for n = (ash 1 len)
66        do (with-open-file
67            (os "tmp.dat" :direction :output
68                :if-exists :supersede
69                :element-type `(unsigned-byte ,len))
70            (loop for i from 0 below 100
71                  for r = (logand (1- n) i)
72                  for pos = (file-position os)
73                  do (assert (or (not pos) (eql pos i)))
74                  do (write-byte r os)))
75        do (with-open-file
76            (is "tmp.dat" :direction :input
77                :element-type `(unsigned-byte ,len))
78            (loop for i from 0 below 100
79                  for pos = (file-position is)
80                  do (assert (or (not pos) (eql pos i)))
81                  do (let ((byte (read-byte is)))
82                       (assert (eql byte (logand (1- n) i)))))))
83  nil)
84
85(deftest file-position.8
86  (loop for len from 33 to 100
87        for n = (ash 1 len)
88        do (with-open-file
89            (os "tmp.dat" :direction :output
90                :if-exists :supersede
91                :element-type `(unsigned-byte ,len))
92            (loop for i from 0 below 100
93                  for r = (logand (1- n) i)
94                  for pos = (file-position os)
95                  do (assert (or (not pos) (eql pos i)))
96                  do (write-byte r os)))
97        do (with-open-file
98            (is "tmp.dat" :direction :input
99                :element-type `(unsigned-byte ,len))
100            (loop for i from 0 below 100
101                  for pos = (file-position is)
102                  do (assert (or (not pos) (eql pos i)))
103                  do (let ((byte (read-byte is)))
104                       (assert (eql byte (logand (1- n) i)))))))
105  nil)
106
107(deftest file-position.9
108  (with-input-from-string
109   (s "abcdefghijklmnopqrstuvwxyz")
110   (loop repeat 26
111         for p = (file-position s)
112         unless (or (not p)
113                    (progn
114                      (file-position s p)
115                      (eql (file-position s) p)))
116         collect p
117         do (read-char s)))
118  nil)
119
120(deftest file-position.10
121  (with-output-to-string
122   (s)
123   (loop repeat 26
124         for p = (file-position s)
125         unless (or (not p)
126                    (progn
127                      (file-position s p)
128                      (eql (file-position s) p)))
129         collect p
130         do (write-char #\x s)))
131  "xxxxxxxxxxxxxxxxxxxxxxxxxx")
132
133;;; Error tests
134
135(deftest file-position.error.1
136  (signals-error (file-position) program-error)
137  t)
138
139(deftest file-position.error.2
140  (signals-error
141   (file-position (make-string-input-stream "abc") :start nil)
142   program-error)
143  t)
144
145;;; It's not clear what 'too large' means -- can we set the
146;;; file position to a point where the file may later be extended
147;;; by some other writer?
148#|
149(deftest file-position.error.3
150  (signals-error
151   (with-open-file
152    (is "file-position.lsp" :direction :input)
153    (flet ((%fail () (error 'type-error)))
154      (unless (file-position is :end) (%fail))
155      (let ((fp (file-position is)))
156        (unless fp (%fail))
157        (file-position is (+ 1000000 fp)))))
158   error)
159  t)
160
161(deftest file-position.error.4
162  (signals-error
163   (with-open-file
164    (is "file-position.lsp" :direction :input)
165    (file-position is 1000000000000000000000))
166   error)
167  t)
168|#
169
170 
Note: See TracBrowser for help on using the repository browser.