#!../../../src/xotclsh
# $Id $

set X ../../..
set xotclsh $X/src/xotclsh

#set auto_path "$X/packages $X/src $auto_path"
set PIPE [open "|${xotclsh} ./UNIVERSAL.xotcl"]
puts "started pipe: ${xotclsh} ./UNIVERSAL.xotcl"

package require xotcl::comm::httpAccess

proc printError msg {puts stderr !!!$msg!!!}


Class Test -parameter {msg request test failureTest}
Test proc new args {
   eval Test create [[self] autoname t%03d] $args 
}
Test proc run {} {
  foreach t [lsort [[self] info instances]] {$t run }
  exit
}
Test instproc report {test} {
  if {[r0 getContentLength]>0} {
    if {[regexp text [[r0 set token] set contentType]]} {
    }
  }
  if {[eval $test]} {
    puts "\tsuceeded! $test"
  } else {
    puts stderr [r0 getContent]
    [r0 set token] showVars
    puts "\tfailure! $test"
  }
}
Test instproc run {} {
  puts "[self] [[self] set msg]"
  if {[catch {eval SimpleRequest r0 -url [[self] set request]} errMsg]} {
    puts "Error catched: '$errMsg'"
  } elseif {[r0 success]} {
    [self] report [[self] set test]
  } elseif {[[self] exists failureTest]} {
    [self] report [[self] set failureTest]
  } else {
    puts "retrieval of [r0 set url] failed"
  }
}


Test new -msg "Load homepage frame von univ ... " \
    -test {expr [r0::sink set contentLength] == 358} \
    -request http://localhost:8095/
Test new -msg "Load Catalog ... " \
    -test {expr [r0::sink set contentLength] == 1744} \
    -request http://localhost:8095/univ+catalog
Test new -msg "Detail Page ... " \
    -test {expr [r0::sink set contentLength] == 2327} \
    -request http://localhost:8095/univ+details+http://nm.wu-wien.ac.at/Lehre/oo1/
Test new -msg "terminate" -request http://localhost:8095/receiver::exit \
    -test {set x 1}

after 1000 {
    Test run
    catch {close $PIPE} msg
    exit
}
vwait forever


