3 ; qa-net - test network routines for server mode
6 ; tests http mode of: load, save, read-file, write-file, delete-file
8 ; assumes newlisp executable in the current directory:
11 ; usage to test on local host:
15 ; usage to test on a remote host
17 ; ./newlisp qa-net http://mysite.com:10001//home/test
19 ; ./newlisp qa-net http://localhost:4711//Users/Lutz/newlisp-8.9.8
21 ; running this test on Win32:
25 ; On Win32 this test may have timing issues, try running again.
29 (set 'start (time-of-day))
31 ; get operating system
32 (set 'opsys (& (last (sys-info)) 0xf))
36 (append "http://localhost:10001/" (real-path) "/qa-junk.txt")))
38 (replace "\\" targetURL "/") ; for Win32
40 (if (not (ends-with targetURL "/qa-junk.txt"))
41 (set 'targetURL (append targetURL "/qa-junk.txt")))
43 (set 'host ((regex "http://(.*?):" targetURL) 3))
44 (set 'port (int ((regex "http://.*?:(\\d+)/" targetURL) 3)))
45 (set 'path ((regex "http://.*:\\d+/(.*)" targetURL) 3))
48 (println "target URL: " targetURL)
50 (println "host: " host)
51 (println "port: " port)
52 (println "path: " path)
54 ; check if server is online or start it, if not
55 ; start one on localhost if no URL was specified
57 (set 'connection (net-connect host port))
60 (println "Starting server on localhost")
61 (if (and (not (main-args -2)) (> opsys 5) (< opsys 9))
62 (set 'pid (process (string "newlisp -c -d " port)))
63 (set 'pid (process (string "./newlisp -c -d " port)))))
65 (println "Server already running ...")
66 (net-close connection)))
69 (println "waiting for server ...")
72 ; test short syntax normal mode
73 (if (= (net-eval host port {(+ 3 4)} 1000) 7)
74 (println "net-eval normal mode ->OK")
75 (println "net-eval poblem with normal mode ->ERROR"))
77 ; test raw mode only in list syntax
78 (if (= (net-eval '((host port {(+ 3 4)} true)) 1000) '("7\n"))
79 (println "net-eval raw mode ->OK")
80 (println "net-eval problem with raw mode ->ERROR"))
86 (if (find "transferred" (print (save targetURL 'key)))
87 (println "save to URL ->OK")
88 (println "save to URL ->ERROR"))
90 (if (= opsys 6) (sleep 4000)) ; for Win32
92 ; test loading from URL
94 (println "loading target URL: " targetURL)
95 (= (load targetURL) verify)
97 (println "load from URL ->OK")
98 (println "load from URL ->ERROR"))
100 ; test writing file to remote
102 ; generate random binary data
105 (write-buffer content (pack "c" (rand 255))))
107 ; write content to remote URL
108 (if (find "transferred" (print (write-file targetURL content)) )
109 (println "write-file to remote URL ->OK")
110 (println "write-file to remote URL ->ERROR"))
112 (if (= opsys 6) (sleep 4000)) ; for Win32
114 ; read content from remote URL
115 (if (= content (read-file targetURL))
116 (println "read-file from remote URL ->OK")
117 (println "read-file from remote URL ->ERROR"))
119 ; delete file at remote URL
121 (if (starts-with (print (delete-file targetURL)) "File deleted:")
122 (println "delete-file from remote URL ->OK")
123 (println "delete-file from remote URL ->Error"))
127 (println "destroy -> " pid " ->" (destroy pid)))
129 (println "\nduration =>" (- (time-of-day) start) " ms\n")