3 (defpackage sb-simple-streams-test
4 (:use #:common-lisp #:sb-simple-streams #:sb-rt))
7 (in-package #:sb-simple-streams-test)
9 (defparameter *dumb-string*
10 "This file created by simple-stream-tests.lisp. Nothing to see here, move along.")
12 (defparameter *test-path*
13 (merge-pathnames (make-pathname :name nil :type nil :version nil)
15 "Directory for temporary test files.")
17 (eval-when (:load-toplevel) (ensure-directories-exist *test-path*))
21 (deftest create-file-1
22 ;; Create a file-simple-stream, write data.
23 (let* ((file (merge-pathnames #p"test-data.txt" *test-path*)))
25 (with-open-stream (s (make-instance 'file-simple-stream
28 :if-exists :overwrite))
29 (string= (write-string *dumb-string* s) *dumb-string*))
33 (deftest create-file-2
34 ;; Create a file-simple-stream via :class argument to open, write data.
35 (let ((file (merge-pathnames #p"test-data.txt" *test-path*)))
37 (with-open-file (s file
38 :class 'file-simple-stream
39 :direction :output :if-exists :overwrite)
40 (string= (write-string *dumb-string* s) *dumb-string*))
44 (deftest create-read-file-1
45 ;; Via file-simple-stream objects, write and then re-read data.
47 (file (merge-pathnames #p"test-data.txt" *test-path*)))
48 (with-open-stream (s (make-instance 'file-simple-stream
51 :if-exists :overwrite))
52 (write-line *dumb-string* s)
53 (setf result (and result (string= (write-string *dumb-string* s)
55 (with-open-stream (s (make-instance 'file-simple-stream
58 :if-does-not-exist :error))
60 (multiple-value-bind (string missing-newline-p)
62 (setf result (and result (string= string *dumb-string*)
63 (not missing-newline-p))))
65 (multiple-value-bind (string missing-newline-p)
67 (setf result (and result (string= string *dumb-string*)
73 (deftest create-read-mapped-file-1
74 ;; Read data via a mapped-file-simple-stream object.
76 (file (merge-pathnames #p"test-data.txt" *test-path*)))
77 (with-open-file (s file
78 :class 'file-simple-stream
79 :direction :output :if-exists :overwrite)
80 (setf result (and result (string= (write-string *dumb-string* s)
82 (with-open-file (s file
83 :class 'mapped-file-simple-stream
85 (setf result (and result (string= (read-line s) *dumb-string*))))
90 (deftest write-read-inet
92 (with-open-stream (s (make-instance 'socket-simple-stream
93 :remote-host #(127 0 0 1)
95 (string= (prog1 (write-line "Got it!" s) (finish-output s))
97 (sb-bsd-sockets::connection-refused-error () t))
100 (deftest write-read-large-sc-1
101 ;; Do write and read with more data than the buffer will hold
102 ;; (single-channel simple-stream)
103 (let* ((file (merge-pathnames #p"test-data.txt" *test-path*))
104 (stream (make-instance 'file-simple-stream
107 (content (make-string (1+ (device-buffer-length stream))
108 :initial-element #\x)))
109 (with-open-stream (s stream)
110 (write-string content s))
111 (with-open-stream (s (make-instance 'file-simple-stream
114 (prog1 (string= content (read-line s))
115 (delete-file file))))
118 (deftest write-read-large-dc-1
119 ;; Do write and read with more data than the buffer will hold
120 ;; (dual-channel simple-stream; we only have socket streams atm)
122 (let* ((stream (make-instance 'socket-simple-stream
123 :remote-host #(127 0 0 1)
125 (content (make-string (1+ (device-buffer-length stream))
126 :initial-element #\x)))
127 (with-open-stream (s stream)
128 (string= (prog1 (write-line content s) (finish-output s))
130 (sb-bsd-sockets::connection-refused-error () t))