1#!/usr/bin/env tclsh
2package require XOTcl; namespace import -force xotcl::*
3
4package require xotcl::comm::httpAccess
5package require xotcl::trace
6
7persistentCache clear
8
9proc assert {f r} {
10  set got [eval $f]
11  if {$got ne $r } {
12    puts stderr "assertion failed: \[$f\] == $r (got $got)" 
13    quit
14  } else {
15    puts stderr "OK $r = $f"
16  }
17}
18proc head msg {
19  puts stderr ""
20  puts stderr "---------------------------- $msg"
21}
22
23proc test {msg cmd} {
24  set r [Object autoname r]
25  head $msg
26  if {[catch {eval $cmd} msg]} {
27    puts stderr "ERROR: $::errorInfo"
28    quit
29  }
30  $r destroy
31}
32
33Object userPwd 
34userPwd proc user {u} { 
35  my set user $u
36}
37userPwd proc show {realm userVar pwVar} {
38  upvar $userVar u $pwVar pw
39  set u [my set user]
40  set pw jogl
41  return 1
42}
43
44
45
46
47# test "simple request" {
48#   SimpleRequest $r -caching 0 \
49#       -url http://localhost/index.html
50#   assert "$r getContentLength" 81
51# }
52# test "simple request" {
53#   SimpleRequest $r -caching 1 \
54#       -url http://localhost/index.html
55#   assert "$r getContentLength" 81
56# }
57# test "simple request" {
58#   SimpleRequest $r -caching 1 \
59#       -url http://localhost/index.html
60#   assert "$r getContentLength" 81
61# }
62# test "simple request" {
63#   persistentCache invalidate \
64#       http://localhost/index.html
65#   SimpleRequest $r -caching 1 \
66#       -url http://localhost/index.html
67#   assert "$r getContentLength" 81
68# }
69
70# test "simple request" {
71#   SimpleRequest $r -caching 0 \
72#        -url http://localhost/muster-d1klausur.ps
73#   assert "$r getContentLength" 163840
74# }
75
76proc parallelRequests {urls} {
77  JoinSink joinsink -requests [llength $urls]
78  set i 0
79  foreach url $urls {
80    TimedMemorySink sink$i
81    set t$i [Access [Access autoname a] -url $url \
82		 -informObject [list joinsink sink$i] \
83		 -caching 0]
84    incr i
85  }
86  set i 0
87  foreach url $urls { sink$i reportTimes;incr i}
88  joinsink destroy
89}
90
91# parallelRequests {
92#     http://localhost/muster-d1klausur.ps
93#     http://localhost/muster-d1klausur2.ps
94#   }
95# quit
96
97foreach c {0 1 2 2} {
98  test "caching $c" {
99    SimpleRequest $r -caching $::c \
100	-url http://nestroy.wi-inf.uni-essen.de/Lv/muster-d1klausur.ps
101    assert "$r getContentLength" 349970
102  }
103}
104
105
106
107test "simple request" {
108  SimpleRequest $r -caching 0 \
109      -url http://nestroy.wi-inf.uni-essen.de/Raumplan.html
110  assert "$r getContentLength" 662
111}
112
113
114test "simple request, larger file" {
115  SimpleRequest $r -caching 0 \
116      -url http://nestroy.wi-inf.uni-essen.de/Lv/muster-d1klausur.ps
117  assert "$r getContentLength" 349970
118}
119
120
121test "use cache" {
122  SimpleRequest $r -caching 1 \
123      -url http://nestroy.wi-inf.uni-essen.de/Lv/muster-d1klausur.ps
124  assert "$r getContentLength" 349970
125}
126
127
128test "specify filename, use cache and validate request" {
129  persistentCache invalidate \
130      http://nestroy.wi-inf.uni-essen.de/Lv/muster-d1klausur.ps
131  exec rm -f test.ps
132  SimpleRequest $r -caching 1 -fileName test.ps \
133      -url http://nestroy.wi-inf.uni-essen.de/Lv/muster-d1klausur.ps
134  assert "$r getContentLength" 349970
135  assert "file size test.ps" 349970
136  assert {lindex [exec md5sum  test.ps] 0} c6029c987e841430f3ca9bab157da12f
137}
138
139
140test  "specify filename, and use cache and a validated file" {
141  exec rm -f test.ps
142  SimpleRequest $r -caching 1 -fileName test.ps \
143      -url http://nestroy.wi-inf.uni-essen.de/Lv/muster-d1klausur.ps
144  assert "$r getContentLength" 349970
145  assert "file size test.ps" 349970
146  assert {lindex [exec md5sum  test.ps] 0} c6029c987e841430f3ca9bab157da12f
147}
148
149test "specify filename, and do not use cache" {
150  exec rm -f test.ps
151  SimpleRequest $r -fileName test.ps -caching 0 \
152      -url http://nestroy.wi-inf.uni-essen.de/Lv/muster-d1klausur.ps
153  assert "$r getContentLength" 349970
154  assert "file size test.ps" 349970
155  assert {lindex [exec md5sum  test.ps] 0} c6029c987e841430f3ca9bab157da12f
156}
157
158test "specify filesink and use cache; no copying neccesary" {
159  persistentCache invalidate \
160      http://nestroy.wi-inf.uni-essen.de/Lv/muster-d1klausur.ps
161  SimpleRequest $r -useFileSink 1 -caching 1 \
162      -url http://nestroy.wi-inf.uni-essen.de/Lv/muster-d1klausur.ps
163  assert "$r getContentLength" 349970
164  assert "file size test.ps" 349970
165}
166
167
168
169test "load a large file to the cache" {
170  persistentCache clearEntry http://swt.wi-inf.uni-essen.de/lx2.1.55
171  SimpleRequest $r -caching 1 \
172      -url http://swt.wi-inf.uni-essen.de/lx2.1.55
173  assert "$r getContentLength" 522411
174}
175
176
177
178test  "load a validated large file" {
179  SimpleRequest $r -caching 1 \
180      -url http://swt.wi-inf.uni-essen.de/lx2.1.55
181  assert "$r getContentLength" 522411
182}
183
184test "pure loading test without cache" {
185  SimpleRequest $r -caching 0 \
186      -url http://swt.wi-inf.uni-essen.de/lx2.1.55
187  assert "$r getContentLength" 522411
188}
189
190
191test  "redirect" {
192  SimpleRequest $r -caching 1 \
193      -url http://mohegan.wi-inf.uni-essen.de/Lv/muster-d1klausur.ps
194  assert "$r getContentLength" 349970
195}
196
197
198test  "authentication" {
199  SimpleRequest $r -caching 1 \
200      -url http://nestroy.wi-inf.uni-essen.de/cgi-bin/w3-msql/Forschung/Publikationen/protected/index.html
201  assert "$r getContentLength" 1164
202}
203
204puts stderr after
205quit
206
207
208### request joining
209### load to file depending on content type
210