archie/tcl-dp/tests/email.test
2024-05-27 16:13:40 +02:00

359 lines
7.3 KiB
Plaintext

# email.test
#
# This file tests the correct functioning of the email channels.
#
#
# For unix systems: if this test fails, delete all files of the
# form ~/.email*, and check the status of your ~/.forward file.
#
# Windows does not have an email channel
#
if {$win == 1} {
return
}
# Set this to 1 if you want to test the email channel
# and see the note below...
set testEmail 0
if {$testEmail == 0} {
puts stdout "*** Skipping email tests..."
return
}
#
# The user should define here his/her email address as the system defines it.
# This version will work only if $USER@hostname is a valid email address for
# the system DP is running on now.
#
if {[catch {set myEmailAddress $env(USER)@cs.cornell.edu}]} {
puts stdout "USER env. variable not set. Skipping email tests..."
return;
}
if {[string compare test [info procs test]] == 1} then {source ../tests/defs}
# set VERBOSE 1
test email-1.1.1 {dp_connect command} {
list [catch {
dp_connect email -bar
} msg] $msg
} {1 {unknown option "-bar", must be -address or -identifier}}
test email-1.1.2 {dp_connect command} {
list [catch {
dp_connect email -bar foo
} msg] $msg
} {1 {unknown option "-bar", must be -address or -identifier}}
#
# Test argument missing checks.
#
test email-1.2.1 {dp_connect command} {
list [catch {
dp_connect email -address
} msg] $msg
} {1 {value for "-address" missing}}
test email-1.2.2 {dp_connect command} {
list [catch {
dp_connect email -identifier
} msg] $msg
} {1 {value for "-identifier" missing}}
test email-1.2.3 {dp_connect command} {
list [catch {
dp_connect email
} msg] $msg
} {1 {address and/or identifier not defined for email channel}}
test email-1.2.4 {dp_connect command} {
list [catch {
dp_connect email -address $myEmailAddress
} msg] $msg
} {1 {address and/or identifier not defined for email channel}}
test email-1.2.5 {dp_connect command} {
list [catch {
dp_connect email -identifier 100
} msg] $msg
} {1 {address and/or identifier not defined for email channel}}
#
# Test type checking of arguments.
#
test email-1.3.1 {dp_connect command} {
list [catch {
dp_connect email -address ""
} msg] $msg
} {1 {the address for an email channel can not be empty or start with a '*'}}
test email-1.3.2 {dp_connect command} {
list [catch {
dp_connect email -address "*dp_list"
} msg] $msg
} {1 {the address for an email channel can not be empty or start with a '*'}}
test email-1.3.3 {dp_connect command} {
list [catch {
dp_connect email -identifier 0
} msg] $msg
} {1 {the identifier for an email channel can not be zero, negative, or a string}}
test email-1.3.4 {dp_connect command} {
list [catch {
dp_connect email -identifier -45
} msg] $msg
} {1 {the identifier for an email channel can not be zero, negative, or a string}}
test email-1.3.5 {dp_connect command} {
list [catch {
dp_connect email -identifier "just a string"
} msg] $msg
} {1 {expected integer but got "just a string"}}
#
#
#
#
set eChannel {}
test email-1.4.1 {dp_connect command} {
list [catch {
set eChannel [dp_connect email -address $myEmailAddress -identifier 100]
string range $eChannel 0 4
} msg] $msg
} {0 email}
if {$eChannel != ""} {
#
# fconfigure tests
#
test email-1.4.2 {fconfigure email} {
list [catch {
fconfigure $eChannel
} msg] $msg
} {0 {-blocking 1 -buffering full -buffersize 4096 -eofchar {{} {}} -translation {auto lf} -address mperham@cs.cornell.edu -identifier 100 -peek 0 -sequence 0}}
test email-1.4.3 {fconfigure email} {
list [catch {
fconfigure $eChannel -badopt
} msg] $msg
} {1 {bad option "-badopt": must be -blocking, -buffering, -buffersize, -eofchar, -translation, or a channel type specific option}}
test email-1.4.4 {fconfigure email} {
list [catch {
fconfigure $eChannel -address something
} msg] $msg
} {1 {can't set address after email channel is opened}}
test email-1.4.5 {fconfigure email} {
list [catch {
fconfigure $eChannel -identifier 999
} msg] $msg
} {1 {can't set identifier after email channel is opened}}
test email-1.4.6 {fconfigure email} {
list [catch {
fconfigure $eChannel -blocking no
} msg] $msg
} {0 {}}
test email-1.4.7 {fconfigure email} {
list [catch {
fconfigure $eChannel -blocking
} msg] $msg
} {0 0}
test email-1.4.8 {fconfigure email} {
list [catch {
fconfigure $eChannel -peek yes
} msg] $msg
} {0 {}}
test email-1.4.9 {fconfigure email} {
list [catch {
fconfigure $eChannel -peek
} msg] $msg
} {0 1}
test email-1.4.10 {fconfigure email} {
list [catch {
fconfigure $eChannel -peek wrong
} msg] $msg
} {1 {expected boolean value but got "wrong"}}
test email-1.4.11 {fconfigure email} {
list [catch {
fconfigure $eChannel -peek 0
} msg] $msg
} {0 {}}
test email-1.4.12 {fconfigure email} {
list [catch {
fconfigure $eChannel -buffering no
} msg] $msg
} {0 {}}
#
# Test send/receive
#
test udp-1.5.1 {send email} {
list [catch {
puts -nonewline $eChannel "Test1\n"
} msg] $msg
} {0 {}}
proc SetTo1 {} {
global flag
set flag 1
}
set flag 0
proc SetTo2 {} {
global flag
set flag 2
}
test email-1.5.2 {fileevent writeable email} {
list [catch {
fileevent $eChannel writable SetTo2
vwait flag
set flag
} msg] $msg
} {0 2}
# Try out the peek option.
test email-1.5.3 {peek & fileevent readable email} {
list [catch {
fconfigure $eChannel -peek yes
fileevent $eChannel writable {}
fileevent $eChannel readable SetTo1
# wait for the first message to arrive
while {$flag != 1} {
vwait flag
}
set x [list $flag [read $eChannel] [read $eChannel]]
} msg] $msg
} [list 0 [list 1 "Test1\n" "Test1\n"]]
# Read the two messages that were sent after resetting the peek option.
test email-1.5.4 {peek & fileevent & readable email} {
list [catch {
puts -nonewline $eChannel "Test2\n"
fconfigure $eChannel -peek no
set flag 0
set x [list [read $eChannel]]
# wait for the second message to arrive
while {$flag != 1} {
vwait flag
}
set x [lappend x [read $eChannel]]
} msg] $msg
} [list 0 [list "Test1\n" "Test2\n"]]
test email-1.5.5 {close email} {
list [catch {
close $eChannel
} msg] $msg
} {0 {}}
test email-1.5.6 {close email} {
list [catch {
close $eChannel
} msg] $msg
} {1 {can not find channel named "email0"}}
test email-1.5.7 {test send/receive email} {
list [catch {
set x "0123456789abcdef"
set y "qqwertyuiopasdfg"
for {set i 0} {$i < 6} {set i [expr $i + 1]} {
set x $x$x
set y $y$y
}
set eChannel [dp_connect email -address $myEmailAddress -identifier 100]
fconfigure $eChannel -buffering none
puts -nonewline $eChannel $x
puts -nonewline $eChannel $y
set flag 0
fileevent $eChannel readable SetTo1
vwait flag
set readX [read $eChannel 1024]
set flag 0
vwait flag
set readY [read $eChannel 1024]
close $eChannel
if {([string compare $x$y $readX$readY] == 0)||
([string compare $x$y $readY$readX] == 0)} {
set rez ok
} else {
set rez failed
}
set rez
} msg] $msg
} {0 ok}
# The following close brace matches the line above:
# if {$eChannel != ""}
}