;;; -*- Mode:LISP; Package:MAC; Base:10; -*-
;;;
;;;  Test file for the Mac File System.
;;;



"begining of the test:"
  (ready-to-boot)



"MAC, various dired's:"
  (dired "kmac:root:")
  (dired "kmac:root:test-files:")
  (dired "kmac:root:changing-files:")
  (dired "kmac:root:test-files:*.lisp#<")
  (dired "kmac:root:test-files:*.lisp#>")
  (dired "kmac:root:changing-files:*s*.*#1")



"LAMA, file attribute list"
  (fs:file-attribute-list "lama:test-files;file-attribute-list.lisp")
  (setq s (open "lama:test-files;file-attribute-list.lisp"))
  (setq p (fs:parse-pathname "lama:test-files;file-attribute-list.lisp"))
  (fs:read-attribute-list p s)
  (dont-grind (describe p))
  (fs:file-attribute-bindings p)
  (close s)

"MAC, file attribute list"
  (fs:file-attribute-list "kmac:root:test-files:file-attribute-list.lisp")
  (setq s (open "kmac:root:test-files:file-attribute-list.lisp"))
  (setq p (fs:parse-pathname "kmac:root:test-files:file-attribute-list.lisp"))
  (fs:read-attribute-list p s)
  (dont-grind (describe p))
  (fs:file-attribute-bindings p)
  (close s)



"LAMA, directory creation:"
  (fs:create-directory "lama:changing-files;")
  (fs:create-directory "lama:changing-files.dir-a.dir-b;" :recursive nil)
  (fs:create-directory "lama:changing-files.dir-c.dir-d;" :recursive t)

"MAC, directory creation (and multiple delete):"
  (fs:create-directory "kmac:root:changing-files:")
  (fs:create-directory "kmac:root:changing-files:dir-a:dir-b:" :recursive nil)
  (fs:create-directory "kmac:root:changing-files:dir-c:dir-d:" :recursive t)



"LAMA, pathname operations:"
  (setq p (fs:parse-pathname "lama:test-files;example.lisp#>"))
  (send p :truename)
  (setq s (send p :open p))
  (close s)
  (send p :delete)
  (send p :undeletable-p)
  (send p :undelete)
  (send p :change-properties t :my-prop1 3 :my-prop2 5)
  (send p :properties)
  (send p :rename "lama:test-files;temp.lisp")
  (fs:rename-file "lama:test-files;temp.lisp" p)

"MAC, pathname operations:"
  (setq p (fs:parse-pathname "kmac:root:test-files:example.lisp#>"))
  (send p :truename)
  (setq s (send p :open p))
  (close s)
  (send p :delete)
  (send p :undeletable-p)
  (send p :undelete)
  (send p :change-properties t :my-prop1 3 :my-prop2 5)
  (send p :properties)
  (send p :rename "kmac:root:test-files:temp.lisp")
  (fs:rename-file "kmac:root:test-files:temp.lisp" p)



"LAMA, MAC, copying files:"
  (fs:copy-file "kmac:root:test-files:example.lisp" "lama:changing-files;")
  (fs:copy-file "lama:changing-files;example.lisp" "kmac:root:changing-files:new-name.c")
  (fs:copy-file "kmac:root:changing-files:new-name.c" "kmac:root:changing-files:new-name2.c#13")



"MAC, file property list:"
  ()



"MAC, files with strange caracters:"
  (with-open-file (s "kmac:root:varia:essai-    z 4.lisp"))



"MAC, the maximum lemgth of a file name is 31 characters:"
  (with-open-file (s "kmac:root:changing-files:12345678901234567890.12345678#8" :direction :output)
    (send s :truename))
  (with-open-file (s "kmac:root:changing-files:12345678901234567890.12345678#>" :direction :output)
    (send s :truename))
  (with-open-file (s "kmac:root:changing-files:12345678901234567890.12345678#>" :direction :output)
    (send s :truename))



"MAC, writing and appending test:"
  (with-open-file (s "kmac:root:changing-files:writing-test.text" :direction :output)
    (send s :tyo #/s)
    (send s :tyo #/a)
    (send s :tyo #/l)
    (send s :tyo #/u)
    (send s :tyo #/t))
  (viewf "kmac:root:changing-files:writing-test.text")
  (with-open-file (s "kmac:root:changing-files:writing-test.text" :direction :output :if-exists :append)
    (send s :tyo #/space)
    (send s :tyo #/j)
    (send s :tyo #/o)
    (send s :tyo #/e)
    (send s :tyo #/.))
  (viewf "kmac:root:changing-files:writing-test.text")



"LAMA, stream messages:"
  (setq s (open "lama:test-files:example.lisp"))
  (file-length s)
  (file-position s)
  (send s :tyi)
  (send s :tyi)
  (send s :tyi)
  (file-position s)
  (file-position s 0)
  (send s :tyi)
  (send s :tyi)
  (send s :tyi)
  (file-position s 2)
  (send s :pathname)
  (send s :truename)
  (send s :generic-pathname)
  (send s :qfaslp)
  (send s :length)
  (send s :creation-date)
  (send s :info)
  (send s :properties)
  (send s :set-byte-size 2)
  (send s :delete)
  (send s :undelete)
  (send s :rename "lama:test-files;new-name1")
  (send s :rename "lama:changing-files;new-name2")
  (send s :rename "lama:test-files;example")
  (close s)

"MAC, stream messages:"
  (setq s (open "kmac:root:test-files:example.lisp"))
  (file-length s)
  (file-position s)
  (send s :tyi)
  (send s :tyi)
  (send s :tyi)
  (file-position s)
  (file-position s 0)
  (send s :tyi)
  (send s :tyi)
  (send s :tyi)
  (file-position s 2)
  (send s :pathname)
  (send s :truename)
  (send s :generic-pathname)
  (send s :qfaslp)
  (send s :length)
  (send s :creation-date)
  (send s :info)
  (send s :properties)
  (send s :set-byte-size 2)
  (send s :delete)
  (send s :undelete)
  (send s :rename "kmac:root:essai:fich3.def")
  (send s :rename "kmac:root:essai:fich4.def")
  (send s :rename "kmac:root:diff-dirs.def")
  (close s)



"LAMA, bit dont-delete:"
  (with-open-file (s "lama:essai;bitdd.lisp" :direction :output)
    (send s :change-properties t :dont-delete t))
  (fs:file-properties "lama:essai;bitdd.lisp")
  (with-open-file (s "lama:essai;bitdd.lisp" :direction :output :if-exists :supersede))
  (with-open-file (s "lama:essai;bitdd.lisp" :direction :output :if-exists :overwrite))
  (with-open-file (s "lama:essai;bitdd.lisp" :direction :output :if-exists :truncate))
  (with-open-file (s "lama:essai;bitdd.lisp" :direction :output :if-exists :append))
  (with-open-file (s "lama:essai;bitdd.lisp" :direction :output :if-exists :rename))
  (with-open-file (s "lama:essai;bitdd.lisp" :direction :output)
    (send s :change-properties t :dont-delete t))
  (fs:file-properties "lama:essai;bitdd.lisp")
  (with-open-file (s "lama:essai;bitdd.lisp" :direction :output :if-exists :rename-and-delete))

"MAC, bit dont-delete:"
  (with-open-file (s "kmac:root:changing-files:bitdd.lisp" :direction :output)
    (send s :change-properties t :dont-delete t))
  (fs:file-properties "kmac:root:changing-files:bitdd.lisp")
  (with-open-file (s "kmac:root:changing-files:bitdd.lisp" :direction :output :if-exists :supersede))
  (with-open-file (s "kmac:root:changing-files:bitdd.lisp" :direction :output :if-exists :overwrite))
  (with-open-file (s "kmac:root:changing-files:bitdd.lisp" :direction :output :if-exists :truncate))
  (with-open-file (s "kmac:root:changing-files:bitdd.lisp" :direction :output :if-exists :append))
  (with-open-file (s "kmac:root:changing-files:bitdd.lisp" :direction :output :if-exists :rename))
  (with-open-file (s "kmac:root:changing-files:bitdd.lisp" :direction :output)
    (send s :change-properties t :dont-delete t))
  (fs:file-properties "kmac:root:changing-files:bitdd.lisp")
  (with-open-file (s "kmac:root:changing-files:bitdd.lisp" :direction :output :if-exists :rename-and-delete))



"LAMA, funny open #1:"
  (file-create "lama:essai;new-file36.lisp#1")
  (file-create "lama:essai;new-file36.lisp#2")
  (fs:delete-file "lama:essai;new-file36.lisp#2")
  (fs:file-properties "lama:essai;new-file36.lisp#2")
  (with-open-file (s "lama:essai;new-file36.lisp#>" :direction :output :if-exists :new-version)
    (send s :truename))

"MAC, funny open #1:"
  (file-create "kmac:root:changing-files:new-file36.lisp#1")
  (file-create "kmac:root:changing-files:new-file36.lisp#2")
  (fs:delete-file "kmac:root:changing-files:new-file36.lisp#2")
  (fs:file-properties "kmac:root:changing-files:new-file36.lisp#2")
  (with-open-file (s "kmac:root:changing-files:new-file36.lisp#>" :direction :output :if-exists :new-version)
    (send s :truename))



"LAMA, funny rename #1:"
  (file-create "lama:essai;qwerty")
  (file-create "lama:essai;qwerty")
  (file-create "lama:essai;yoyo")
  (rename-file "lama:essai;yoyo" "lama:essai;qwerty.lisp#<")

"MAC, funny rename #1:"
  (file-create "kmac:root:essai:qwerty")
  (file-create "kmac:root:essai:qwerty")
  (file-create "kmac:root:essai:yoyo")
  (rename-file "kmac:root:essai:yoyo" "kmac:root:essai:qwerty.lisp#<")



"MAC, open options"
  (with-open-file (s "kmac:root:essai:fich2.abcdef" :if-exists nil))
  (with-open-file (s "kmac:root:essai:fich2.abcdef" :if-exists :error))
  (with-open-file (s "kmac:root:essai:fich2.abcdef" :if-exists :supersede))
  (with-open-file (s "kmac:root:essai:fich2.abcdef" :if-exists :overwrite))
  (with-open-file (s "kmac:root:essai:fich2.abcdef" :if-exists :truncate))
  (with-open-file (s "kmac:root:essai:fich2.abcdef" :if-exists :append))
  (with-open-file (s "kmac:root:essai:fich2.abcdef" :if-exists :rename))
  (with-open-file (s "kmac:root:essai:fich2.abcdef" :if-exists :rename-and-delete))

"LAMA, multiple open"
  (with-open-file (s "lama:changing-files;rewrite.lisp#1" :direction :output) (send s :tyo #/a))
  (setq s-1 (open "lama:changing-files;rewrite.lisp#1" :direction :output :if-exist :supersede))
  (send s-1 :tyo #/b)
  (with-open-file (s "lama:changing-files;rewrite.lisp#1") (int-char (send s :tyi)))
  (with-open-file (s "lama:changing-files;rewrite.lisp#1" :direction :output :if-exist :overwrite))
  
"Mac, multiple open"
  (with-open-file (s "kmac:root:changing-files;rewrite.lisp#1" :direction :output) (send s :tyo #/a))
  (setq s-1 (open "kmac:root:changing-files;rewrite.lisp#1" :direction :output :if-exist :supersede))
  (send s-1 :tyo #/b)
  (with-open-file (s "kmac:root:changing-files;rewrite.lisp#1") (int-char (send s :tyi)))
  (with-open-file (s "kmac:root:changing-files;rewrite.lisp#1" :direction :output :if-exist :overwrite))
 
"lama, expunge with open file"
  (file-create "lama:changing-files;exp-file")
  (setq s (open "lama:changing-files;exp-file"))
  (with-open-file (s1 "lama:changing-files;exp-file") (send s1 :delete))
  (expunge-directory
"here is the end of the test."
  ()



(defvar s)
(defvar s1)
(defvar s2)
(defvar s3)

(defvar p)
(defvar p1)
(defvar p2)
(defvar p3)


(defun test ()
  (with-open-file (stream "ed:test")
    (let (expr
	  kbd
	  dont-grind
	  (read-p t))
      (catch 'end-of-test
	(do-forever
	  (when read-p
	    (setq expr       (read stream)
		  dont-grind (and (listp expr)
				  (eq 'dont-grind (car expr))))
	    (if dont-grind
		(setq expr (cadr expr))))
	  (if (stringp expr)
	      (format t "~2%~S~%" expr)
	    (grind-top-level expr)
	    (setq kbd (send *terminal-io* :tyi))
	    (send *terminal-io* :tyo kbd)
	    (selectq kbd
	      (#/end
	       (throw 'end-of-test "end."))
	      (#/b
	       (send stream :set-pointer 0)
	       (setq read-p t))
	      (#/clear-screen
	       (send *terminal-io* :clear-window)
	       (setq read-p nil))
	      (#/s
	       (setq read-p t))
	      (#/n
	       (loop with temp
		     until (stringp (setq temp (read stream)))
		     finally (format t "~2%~S~%" temp))
	       (setq read-p t))
	      ((#/0 #/1 #/2 #/3 #/4 #/5 #/6 #/7 #/8 #/9)
	       (loop repeat (- kbd #/1)
		     do (grind-top-level (read stream)))
	       (setq read-p t))
	      (#/space
	       (errset (if dont-grind
			   (eval expr)
			 (grind-top-level (eval expr))))
	       (setq read-p t))
	      (t
	       (setq read-p nil)))))))))

(defun file-create (string)
  (with-open-file (m string :direction :output)))


