os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/httpold.test
First public contribution.
1 # Commands covered: http_config, http_get, http_wait, http_reset
3 # This file contains a collection of tests for the http script library.
4 # Sourcing this file into Tcl runs the tests and
5 # generates output for errors. No output means no errors were found.
7 # Copyright (c) 1991-1993 The Regents of the University of California.
8 # Copyright (c) 1994-1996 Sun Microsystems, Inc.
9 # Copyright (c) 1998-1999 by Scriptics Corporation.
11 # See the file "license.terms" for information on usage and redistribution
12 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
14 # RCS: @(#) $Id: httpold.test,v 1.11 2002/10/03 13:34:32 dkf Exp $
16 if {[lsearch [namespace children] ::tcltest] == -1} {
17 package require tcltest
18 namespace import -force ::tcltest::*
21 if {[catch {package require http 1.0}]} {
22 if {[info exists httpold]} {
23 catch {puts "Cannot load http 1.0 package"}
24 ::tcltest::cleanupTests
27 catch {puts "Running http 1.0 tests in slave interp"}
28 set interp [interp create httpold]
29 $interp eval [list set httpold "running"]
30 $interp eval [list set argv $argv]
31 $interp eval [list source [info script]]
33 ::tcltest::cleanupTests
38 set bindata "This is binary data\x0d\x0amore\x0dmore\x0amore\x00null"
42 ## The httpd script implement a stub http server
44 source [file join [file dirname [info script]] httpd]
47 if [catch {httpd_init $port} listen] {
48 puts "Cannot start http server, http test skipped"
50 ::tcltest::cleanupTests
54 test httpold-1.1 {http_config} {
56 } {-accept */* -proxyfilter httpProxyRequired -proxyhost {} -proxyport {} -useragent {Tcl http client package 1.0}}
58 test httpold-1.2 {http_config} {
59 http_config -proxyfilter
62 test httpold-1.3 {http_config} {
63 catch {http_config -junk}
66 test httpold-1.4 {http_config} {
67 http_config -proxyhost nowhere.come -proxyport 8080 -proxyfilter myFilter -useragent "Tcl Test Suite"
69 http_config -proxyhost {} -proxyport {} -proxyfilter httpProxyRequired \
70 -useragent "Tcl http client package 1.0"
72 } {-accept */* -proxyfilter myFilter -proxyhost nowhere.come -proxyport 8080 -useragent {Tcl Test Suite}}
74 test httpold-1.5 {http_config} {
75 catch {http_config -proxyhost {} -junk 8080}
78 test httpold-2.1 {http_reset} {
79 catch {http_reset http#1}
82 test httpold-3.1 {http_get} {
83 catch {http_get -bogus flag}
85 test httpold-3.2 {http_get} {
86 catch {http_get http:junk} err
88 } {Unsupported URL: http:junk}
90 set url [info hostname]:$port
91 test httpold-3.3 {http_get} {
92 set token [http_get $url]
94 } "<html><head><title>HTTP/1.0 TEST</title></head><body>
95 <h1>Hello, World!</h1>
100 set url [info hostname]:$port/a/b/c
101 set binurl [info hostname]:$port/binary
103 test httpold-3.4 {http_get} {
104 set token [http_get $url]
106 } "<html><head><title>HTTP/1.0 TEST</title></head><body>
107 <h1>Hello, World!</h1>
111 proc selfproxy {host} {
113 return [list [info hostname] $port]
115 test httpold-3.5 {http_get} {
116 http_config -proxyfilter selfproxy
117 set token [http_get $url]
118 http_config -proxyfilter httpProxyRequired
120 } "<html><head><title>HTTP/1.0 TEST</title></head><body>
121 <h1>Hello, World!</h1>
122 <h2>GET http://$url</h2>
125 test httpold-3.6 {http_get} {
126 http_config -proxyfilter bogus
127 set token [http_get $url]
128 http_config -proxyfilter httpProxyRequired
130 } "<html><head><title>HTTP/1.0 TEST</title></head><body>
131 <h1>Hello, World!</h1>
135 test httpold-3.7 {http_get} {
136 set token [http_get $url -headers {Pragma no-cache}]
138 } "<html><head><title>HTTP/1.0 TEST</title></head><body>
139 <h1>Hello, World!</h1>
143 test httpold-3.8 {http_get} {
144 set token [http_get $url -query Name=Value&Foo=Bar]
146 } "<html><head><title>HTTP/1.0 TEST</title></head><body>
147 <h1>Hello, World!</h1>
156 test httpold-3.9 {http_get} {
157 set token [http_get $url -validate 1]
162 test httpold-4.1 {httpEvent} {
163 set token [http_get $url]
165 array set meta $data(meta)
166 expr ($data(totalsize) == $meta(Content-Length))
169 test httpold-4.2 {httpEvent} {
170 set token [http_get $url]
172 array set meta $data(meta)
173 string compare $data(type) [string trim $meta(Content-Type)]
176 test httpold-4.3 {httpEvent} {
177 set token [http_get $url]
179 } {HTTP/1.0 200 Data follows}
181 test httpold-4.4 {httpEvent} {
182 set testfile [makeFile "" testfile]
183 set out [open $testfile w]
184 set token [http_get $url -channel $out]
186 set in [open $testfile]
191 } "<html><head><title>HTTP/1.0 TEST</title></head><body>
192 <h1>Hello, World!</h1>
196 test httpold-4.5 {httpEvent} {
197 set testfile [makeFile "" testfile]
198 set out [open $testfile w]
199 set token [http_get $url -channel $out]
203 expr $data(currentsize) == $data(totalsize)
206 test httpold-4.6 {httpEvent} {
207 set testfile [makeFile "" testfile]
208 set out [open $testfile w]
209 set token [http_get $binurl -channel $out]
211 set in [open $testfile]
212 fconfigure $in -translation binary
219 proc myProgress {token total current} {
220 global progress httpLog
221 if {[info exists httpLog] && $httpLog} {
222 puts "progress $total $current"
224 set progress [list $total $current]
227 # This test hangs on Windows95 because the client never gets EOF
229 test httpold-4.6 {httpEvent} {
230 set token [http_get $url -blocksize 50 -progress myProgress]
234 test httpold-4.7 {httpEvent} {
235 set token [http_get $url -progress myProgress]
238 test httpold-4.8 {httpEvent} {
239 set token [http_get $url]
242 test httpold-4.9 {httpEvent} {
243 set token [http_get $url -progress myProgress]
245 } {HTTP/1.0 200 Data follows}
246 test httpold-4.10 {httpEvent} {
247 set token [http_get $url -progress myProgress]
250 test httpold-4.11 {httpEvent} {
251 set token [http_get $url -timeout 1 -command {#}]
255 test httpold-4.12 {httpEvent} {
258 after 500 {lappend x ok}
259 set token [http_get $url -timeout 1 -command {lappend x fail}]
261 list [http_status $token] $x
264 test httpold-5.1 {http_formatQuery} {
265 http_formatQuery name1 value1 name2 "value two"
266 } {name1=value1&name2=value+two}
268 test httpold-5.2 {http_formatQuery} {
269 http_formatQuery name1 ~bwelch name2 \xa1\xa2\xa2
270 } {name1=%7ebwelch&name2=%a1%a2%a2}
272 test httpold-5.3 {http_formatQuery} {
273 http_formatQuery lines "line1\nline2\nline3"
274 } {lines=line1%0d%0aline2%0d%0aline3}
276 test httpold-6.1 {httpProxyRequired} {
278 http_config -proxyhost [info hostname] -proxyport $port
279 set token [http_get $url]
281 http_config -proxyhost {} -proxyport {}
284 } "<html><head><title>HTTP/1.0 TEST</title></head><body>
285 <h1>Hello, World!</h1>
286 <h2>GET http://$url</h2>
294 ::tcltest::cleanupTests