0.8alpha.0.27:
[sbcl.git] / contrib / sb-simple-streams / simple-stream-tests.lisp
1 ;;;; -*- lisp -*-
2
3 (defpackage sb-simple-streams-test
4   (:use #:common-lisp #:sb-simple-streams #:sb-rt))
5
6
7 (in-package #:sb-simple-streams-test)
8
9 (defparameter *dumb-string* "This file created by simple-stream-tests.lisp. Nothing to see here, move along.")
10
11 (defparameter *test-path* (merge-pathnames
12                            (make-pathname :name nil :type nil :version nil)
13                            *load-truename*))
14
15 (eval-when (:load-toplevel) (ensure-directories-exist *test-path*))
16
17 (deftest create-file-1
18   (let* ((file (merge-pathnames #p"test-data.txt" *test-path*))
19          (stream-object (make-instance 'file-simple-stream
20                                       :filename file
21                                       :direction :output
22                                       :if-exists :overwrite)))
23     (prog1
24         (with-open-stream (s stream-object)
25            (string= (write-string *dumb-string* s) *dumb-string*))
26       (delete-file file)))
27   t)
28
29 (deftest create-file-2
30   (let ((file (merge-pathnames #p"test-data.txt" *test-path*)))
31     (prog1
32         (with-open-file (s file
33                            :class 'file-simple-stream
34                            :direction :output :if-exists :overwrite)
35            (string= (write-string *dumb-string* s) *dumb-string*))
36       (delete-file file)))
37   t)
38
39 (deftest create-read-file-1
40   (let ((result t)
41         (file (merge-pathnames #p"test-data.txt" *test-path*)))
42     (let ((stream-object (make-instance 'file-simple-stream
43                                       :filename file
44                                       :direction :output
45                                       :if-exists :overwrite)))
46       (with-open-stream (s stream-object)
47          (setf result (and result (string= (write-string *dumb-string* s)
48                                            *dumb-string*)))
49          (terpri s)))
50     (let ((stream-object (make-instance 'file-simple-stream
51                                       :filename file
52                                       :direction :input)))
53       (with-open-stream (s stream-object)
54          (setf result (and result (string= (read-line s) *dumb-string*)))))
55     result)
56   t)
57
58 (deftest create-read-mapped-file-1
59   (let ((result t)
60         (file (merge-pathnames #p"test-data.txt" *test-path*)))
61     (with-open-file (s file
62                        :class 'file-simple-stream
63                        :direction :output :if-exists :overwrite)
64        (setf result (and result (string= (write-string *dumb-string* s)
65                                          *dumb-string*))))
66     (with-open-file (s file
67                        :class 'mapped-file-simple-stream
68                        :direction :input)
69        (setf result (and result (string= (read-line s) *dumb-string*))))
70     (delete-file file)
71     result)
72   t)
73
74
75