#!../../src/xotclsh
# -*- Mode: tcl -*-
# $Id: actiweb.test,v 1.6 2001/03/09 13:27:01 neumann Exp $
# regression test for actiweb examples

#set auto_path "../../packages ../../src $auto_path"

set xotclsh "../../src/xotclsh"

set PIPE1 [open "| $xotclsh ./Counter.xotcl"]
set PIPE2 [open "| $xotclsh ./Counter2.xotcl"]
set PIPE3 [open "| $xotclsh ./Counter3.xotcl"]
set PIPE4 [open "| $xotclsh ./Counter4.xotcl"]
set PIPE5 [open "| $xotclsh ./MC.xotcl"]

#package require xotcl::package; package verbose 1
package require xotcl::comm::httpAccess
#package require xotcl::trace

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

Class Test -parameter {msg request test failureTest}
Test proc run {} {
  foreach t [lsort [[self] info instances]] {$t run }
  exit
}
Test proc new args {
   eval Test create [[self] autoname t%03d] $args 
}
Test instproc report {test} {
  if {[eval $test]} {
    puts "\tsuceeded! $test"
  } else {
    #if {[[self] exists failureTest]} {eval [[self] set failureTest]}
    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'"
  } else {
    if {[r0 success]} {
      [self] report [[self] set test]
    } else {
      if {[[self] exists failureTest]} {
	[self] report [[self] set failureTest]
      } else {
	puts "retrieval of [r0 set url] failed"
      }
    }
  }
}


Test new -msg "Trying Counter.xotcl ... " \
  -test {expr [regexp {^<HTML>The value in counter-1.html is now: 0} \
		   [r0::sink set d]] == 1} \
    -request http://localhost:8090/counter-1.html
Test new -msg "terminate Counter" -test {set x 1} \
    -request http://localhost:8090/receiver::exit

Test new -msg "Trying Counter2.xotcl (a) ... " \
    -test {expr [r0 getContentLength] == 29} \
    -request http://localhost:8091/c1

Test new -msg "Trying Counter2.xotcl (b) ... " \
    -test {expr [r0 getContentLength] == 285} \
    -request http://localhost:8091/web-c1
Test new -msg "terminate Counter1" -test {set x 1} \
    -request http://localhost:8091/receiver::exit


Test new -msg "Trying Counter3.xotcl  ... " \
    -test {expr [r0 getContentLength] == 122} \
    -request http://localhost:8093/c1
Test new -msg "terminate Counter3" -test {set x 1} \
    -request http://localhost:8093/receiver::exit


Test new -msg "Trying Counter4.xotcl (a) ... " \
    -test {expr [r0 getContentLength] == 126} \
    -request http://localhost:8094/wc1
Test new -msg "terminate Counter4" -test {set x 1} \
    -request http://localhost:8094/receiver::exit

Test new -msg "Trying MC.xotcl ... " \
    -test {expr [r0 getContentLength] == 1779} \
    -request http://localhost:8092/Gustaf.html 
Test new -msg "terminate MC" -test {set x 1} \
    -request http://localhost:8092/receiver::exit


after 2000 {
  Test run
}

catch {vwait forever}
