## -*-Tcl-*- # ################################################################### # TclAE - AppleEvent extension for Tcl # # FILE: "tclAEHandler.test" # created: 9/10/2000 {3:48:20 PM} # last update: 11/17/02 {7:20:41 PM} # Author: Jonathan Guyer # E-mail: jguyer@his.com # mail: POMODORO no seisan # www: http://www.his.com/jguyer/ # # ======================================================================== # Copyright 2000 Jonathan Guyer # All rights reserved # ======================================================================== # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose and without fee is hereby granted, # provided that the above copyright notice appear in all copies and that # both that the copyright notice and warranty disclaimer appear in # supporting documentation. # # Jonathan Guyer disclaims all warranties with regard to this software, # including all implied warranties of merchantability and fitness. In # no event shall Jonathan Guyer be liable for any special, indirect or # consequential damages or any damages whatsoever resulting from loss of # use, data or profits, whether in an action of contract, negligence or # other tortuous action, arising out of or in connection with the use or # performance of this software. # ======================================================================== # Description: # # This file contains a collection of tests for one or more of # the TclAE commands. Sourcing this file into Tcl runs the # tests and generates output for errors. No output means no # errors were found. # # History # # modified by rev reason # ---------- --- --- ----------- # 2000-09-10 JEG 1.0 original # ################################################################### ## if {[info tclversion] < 8.0} { alpha::package require alphatest if {[catch {alpha::package require tclAE}]} { catch {puts "Cannot load TclAE"} } # Only run the test if we can load the TclAE package set alphatest::testConfig(tclAE) [expr {[info commands tclAE::send] != ""}] set alphatest::testConfig(tclAEalphaTcl) [set alphatest::testConfig(tclAE)] set alphatest::testConfig(tclAEshlb) 0 # No env variable in Alpha 7.x # Path must terminate with ':' or it won't convert properly to a folder alias set testPath [file join $HOME {}] set testProgram 'ALFA' } else { if {[lsearch [namespace children] ::tcltest] == -1} { package require tcltest namespace import ::tcltest::* } if {[catch {package require tclAE}]} { catch {puts "Cannot load TclAE"} } # Only run the test if we can load the TclAE package set ::tcltest::testConstraints(tclAE) [expr {[info commands tclAE::send] != ""}] set ::tcltest::testConstraints(tclAEshlb) [set ::tcltest::testConstraints(tclAE)] set ::tcltest::testConstraints(tclAEalphaTcl) 0 if {$tcl_platform(platform) == "macintosh"} { set testPath $env(SYS_FOLDER) set testProgram [file tail [info nameofexecutable]] } if {$tcl_platform(platform) == "unix" && $tcl_platform(os) == "Darwin"} { set ::tcltest::testConstraints(macOnly) 1 if {[info exists alpha::platform] && ${alpha::platform} == "alpha"} { set testProgram "'ALFA'" } else { set testProgram "-s" } } } test tclAEHandler-1.1 {tclAE::installCoercionHandler noargs} {macOnly tclAEshlb} { set err [catch {tclAE::installCoercionHandler} msg] list $err $msg } {1 {wrong # args: should be "tclAE::installCoercionHandler "}} test tclAEHandler-1.2 {tclAE::installCoercionHandler} {macOnly tclAE tclAE} { proc testHandler {typeCode data toType resultDesc} { binary scan $data a* text tclAE::replaceDescData $resultDesc $toType [binary format I [expr {2 * $text}]] } catch {tclAE::installCoercionHandler TEXT YoYo testHandler} catch {tclAE::coerceData TEXT "4" YoYo} tempAEDesc catch {tclAE::print $tempAEDesc} gizmo list $gizmo } {YoYo(00000008)} catch {tclAE::disposeDesc $tempAEDesc} catch {tclAE::removeCoercionHandler TEXT YoYo testHandler} catch {rename testHandler ""} test tclAEHandler-1.3 {tclAE::installCoercionHandler text data} {macOnly tclAE} { proc testHandler {typeCode data toType resultDesc} { if {$data} { tclAE::replaceDescData $resultDesc $toType [binary format c 1] } else { tclAE::replaceDescData $resultDesc $toType [binary format c 0] } } catch {tclAE::installCoercionHandler TEXT bool testHandler} catch {tclAE::coerceData TEXT "true" bool} tempAEDesc catch {tclAE::print $tempAEDesc} gizmo regsub {bool\(0(.)\)} $gizmo {\1} gizmo list $gizmo } {1} catch {tclAE::disposeDesc $tempAEDesc} catch {tclAE::removeCoercionHandler TEXT bool testHandler} catch {rename testHandler ""} test tclAEHandler-1.4 {tclAE::installCoercionHandler binary data} {macOnly tclAE} { proc testHandler {typeCode data toType resultDesc} { binary scan $data c bool if {$bool} { tclAE::replaceDescData $resultDesc $toType "rue" } else { tclAE::replaceDescData $resultDesc $toType "alse" } } catch {tclAE::installCoercionHandler bool TEXT testHandler} catch {tclAE::coerceData bool [binary format c 0] TEXT} tempAEDesc catch {tclAE::print $tempAEDesc} gizmo list $gizmo } {alse} catch {tclAE::disposeDesc $tempAEDesc} catch {tclAE::removeCoercionHandler bool TEXT testHandler} catch {rename testHandler ""} test tclAEHandler-1.5.1 {tclAE::installCoercionHandler error from handler} {macOnly tclAE tclAEshlb} { proc testHandler {typeCode data toType resultDesc} { error "this is an error" } catch {tclAE::installCoercionHandler Bool TEXT testHandler} catch {tclAE::coerceData Bool "bool" TEXT} msg regsub {(Couldn't coerce |bool| from 'Bool' to 'TEXT': )(Bad parameter data or unable to coerce the data supplied|OSErr -1700)} $msg {\1Bad parameter data or unable to coerce the data supplied} msg set msg } {Couldn't coerce |bool| from 'Bool' to 'TEXT': Bad parameter data or unable to coerce the data supplied} test tclAEHandler-1.5.2 {tclAE::installCoercionHandler error from handler} {macOnly tclAE tclAEalphaTcl} { proc testHandler {typeCode data toType resultDesc} { error "this is an error" } catch {tclAE::installCoercionHandler Bool TEXT testHandler} catch {tclAE::coerceData Bool "bool" TEXT} msg list $msg } {{Can't make some data into the expected type.}} catch {tclAE::disposeDesc $tempAEDesc} catch {tclAE::removeCoercionHandler Bool TEXT testHandler} catch {rename testHandler ""} test tclAEHandler-1.6.1 {tclAE::installCoercionHandler no proc} {macOnly tclAEshlb} { catch {rename testHandler ""} catch {tclAE::installCoercionHandler TEXT bool testHandler} catch {tclAE::coerceData TEXT "true" bool} msg regsub {(Couldn't coerce |true| from 'TEXT' to 'bool': )(No handler in the dispatch tables fits the parameters to AEGetEventHandler or AEGetCoercionHandler|OSErr -1717)} $msg {\1No handler in the dispatch tables fits the parameters to AEGetEventHandler or AEGetCoercionHandler} msg set msg } {Couldn't coerce |true| from 'TEXT' to 'bool': No handler in the dispatch tables fits the parameters to AEGetEventHandler or AEGetCoercionHandler} test tclAEHandler-1.6.2 {tclAE::installCoercionHandler no proc} {macOnly tclAEalphaTcl} { catch {rename testHandler ""} catch {tclAE::installCoercionHandler TEXT bool testHandler} catch {tclAE::coerceData TEXT "true" bool} msg list $msg } {{Can't make some data into the expected type.}} catch {tclAE::disposeDesc $tempAEDesc} catch {tclAE::removeCoercionHandler TEXT bool testHandler} test tclAEHandler-2.1 {tclAE::getCoercionHandler noargs} {macOnly tclAEshlb} { set err [catch {tclAE::getCoercionHandler} msg] list $err $msg } {1 {wrong # args: should be "tclAE::getCoercionHandler "}} test tclAEHandler-2.2 {tclAE::getCoercionHandler} {macOnly tclAE tclAE} { proc testHandler {typeCode data toType resultDesc} { if {$data} { tclAE::replaceDescData $resultDesc $toType [binary format c 1] } else { tclAE::replaceDescData $resultDesc $toType [binary format c 0] } } catch {tclAE::installCoercionHandler TEXT bool testHandler} catch {tclAE::getCoercionHandler TEXT bool} handler list $handler } {testHandler} catch {tclAE::removeCoercionHandler TEXT bool testHandler} test tclAEHandler-2.3.1 {tclAE::getCoercionHandler no handler} {macOnly tclAE tclAEshlb} { catch {tclAE::removeCoercionHandler TEXT bool testHandler} catch {tclAE::getCoercionHandler TEXT bool} msg regsub {(Couldn't find coercion handler: )(No handler in the dispatch tables fits the parameters to AEGetEventHandler or AEGetCoercionHandler|OSErr -1717)} $msg {\1No handler in the dispatch tables fits the parameters to AEGetEventHandler or AEGetCoercionHandler} msg set msg } {Couldn't find coercion handler: No handler in the dispatch tables fits the parameters to AEGetEventHandler or AEGetCoercionHandler} test tclAEHandler-2.3.2 {tclAE::getCoercionHandler no handler} {macOnly tclAE tclAEalphaTcl} { catch {tclAE::removeCoercionHandler TEXT bool testHandler} catch {tclAE::getCoercionHandler TEXT bool} msg list $msg } {{The handler is not defined.}} test tclAEHandler-3.1 {tclAE::removeCoercionHandler noargs} {macOnly tclAEshlb} { set err [catch {tclAE::removeCoercionHandler} msg] list $err $msg } {1 {wrong # args: should be "tclAE::removeCoercionHandler "}} test tclAEHandler-3.2.1 {tclAE::removeCoercionHandler} {macOnly tclAE tclAEshlb} { catch {tclAE::installCoercionHandler TEXT bool testHandler} catch {tclAE::getCoercionHandler TEXT bool} handler catch {tclAE::removeCoercionHandler TEXT bool testHandler} msg1 catch {tclAE::getCoercionHandler TEXT bool} msg2 regsub {(Couldn't find coercion handler: )(No handler in the dispatch tables fits the parameters to AEGetEventHandler or AEGetCoercionHandler|OSErr -1717)} $msg2 {\1No handler in the dispatch tables fits the parameters to AEGetEventHandler or AEGetCoercionHandler} msg2 list $handler $msg1 $msg2 } {testHandler {} {Couldn't find coercion handler: No handler in the dispatch tables fits the parameters to AEGetEventHandler or AEGetCoercionHandler}} test tclAEHandler-3.2.2 {tclAE::removeCoercionHandler} {macOnly tclAE tclAEalphaTcl} { catch {tclAE::installCoercionHandler TEXT bool testHandler} catch {tclAE::getCoercionHandler TEXT bool} handler catch {tclAE::removeCoercionHandler TEXT bool testHandler} msg1 catch {tclAE::getCoercionHandler TEXT bool} msg2 list $handler $msg1 $msg2 } {testHandler {} {The handler is not defined.}} test tclAEHandler-3.3.1 {tclAE::removeCoercionHandler no handler} {macOnly tclAE tclAEshlb} { catch {tclAE::removeCoercionHandler TEXT bool testHandler} catch {tclAE::removeCoercionHandler TEXT bool testHandler} msg regsub {(Couldn't remove coercion handler: )(No handler in the dispatch tables fits the parameters to AEGetEventHandler or AEGetCoercionHandler|OSErr -1717)} $msg {\1No handler in the dispatch tables fits the parameters to AEGetEventHandler or AEGetCoercionHandler} msg set msg } {Couldn't remove coercion handler: No handler in the dispatch tables fits the parameters to AEGetEventHandler or AEGetCoercionHandler} test tclAEHandler-3.3.2 {tclAE::removeCoercionHandler no handler} {macOnly tclAE tclAEalphaTcl} { catch {tclAE::removeCoercionHandler TEXT bool testHandler} catch {tclAE::removeCoercionHandler TEXT bool testHandler} msg list $msg } {{The handler is not defined.}} test tclAEHandler-4.1 {tclAE::installEventHandler noargs} {macOnly tclAEshlb} { set err [catch {tclAE::installEventHandler} msg] list $err $msg } {1 {wrong # args: should be "tclAE::installEventHandler "}} test tclAEHandler-4.2 {tclAE::installEventHandler} {macOnly tclAE tclAE} { proc testHandler {theAppleEvent theReplyAE} { catch {tclAE::getKeyData $theAppleEvent ----} text return [string toupper $text] } catch {tclAE::installEventHandler Tcl test testHandler} catch {tclAE::send -r -p $testProgram Tcl test ---- {some text}} gizmo regsub {(aevt\\ansr\{'----':SOME TEXT).*\}} $gizmo "\\1\}" gizmo set gizmo } {aevt\ansr{'----':SOME TEXT}} catch {tclAE::removeEventHandler Tcl test testHandler} catch {rename testHandler ""} test tclAEHandler-4.3 {tclAE::installEventHandler} {macOnly tclAE tclAEshlb} { proc testHandler {theAppleEvent theReplyAE} { catch {tclAE::getKeyData $theAppleEvent ----} text catch {tclAE::putKeyData $theReplyAE ---- TEXT [string toupper $text]} # we specifically assigned the direct object, so # implicit [return 0] should be ignored } catch {tclAE::installEventHandler Tcl test testHandler} catch {tclAE::send -r -p $testProgram Tcl test ---- {some text}} gizmo regsub {(aevt\\ansr\{'----':SOME TEXT).*\}} $gizmo "\\1\}" gizmo set gizmo } {aevt\ansr{'----':SOME TEXT}} catch {tclAE::removeEventHandler Tcl test testHandler} catch {rename testHandler ""} test tclAEHandler-4.4 {tclAE::installEventHandler} {macOnly tclAE tclAEshlb} { proc testHandler {theAppleEvent theReplyAE} { catch {tclAE::getKeyData $theAppleEvent ----} text catch {tclAE::putKeyData $theReplyAE lowc TEXT $text} catch {tclAE::putKeyData $theReplyAE uppc TEXT [string toupper $text]} # prevent any direct object from being assigned return } catch {tclAE::installEventHandler Tcl test testHandler} catch {tclAE::send -r -p $testProgram Tcl test ---- {some text}} gizmo regsub {(aevt\\ansr\{lowc:some text, uppc:SOME TEXT).*\}} $gizmo "\\1\}" gizmo set gizmo } {aevt\ansr{lowc:some text, uppc:SOME TEXT}} catch {tclAE::removeEventHandler Tcl test testHandler} catch {rename testHandler ""} test tclAEHandler-4.5 {tclAE::installEventHandler error from handler} {macOnly tclAE tclAEshlb} { proc testHandler {theAppleEvent theReplyAE} { error "this is an error" } catch {tclAE::installEventHandler Tcl test testHandler} catch {tclAE::send -r -p $testProgram Tcl test ---- {some text}} gizmo regsub {(aevt\\ansr\{errs:this is an error).*\}} $gizmo "\\1\}" gizmo set gizmo } {aevt\ansr{errs:this is an error}} catch {tclAE::removeEventHandler Tcl test testHandler} catch {rename testHandler ""} test tclAEHandler-4.6 {tclAE::installEventHandler error from handler} {macOnly tclAE tclAEshlb} { proc testHandler {theAppleEvent theReplyAE} { error -1703 } catch {tclAE::installEventHandler Tcl test testHandler} catch {tclAE::send -r -p $testProgram Tcl test ---- {some text}} gizmo regsub {(aevt\\ansr\{errs:-1703, errn:-1703).*\}} $gizmo "\\1\}" gizmo set gizmo } {aevt\ansr{errs:-1703, errn:-1703}} catch {tclAE::removeEventHandler Tcl test testHandler} catch {rename testHandler ""} test tclAEHandler-4.7 {tclAE::installEventHandler error from handler} {macOnly tclAE tclAEshlb} { proc testHandler {theAppleEvent theReplyAE} { error "rror essage" "" -1703 } catch {tclAE::installEventHandler Tcl test testHandler} catch {tclAE::send -r -p $testProgram Tcl test ---- {some text}} gizmo regsub {(aevt\\ansr\{errs:Ґrror essage, errn:-1703).*\}} $gizmo "\\1\}" gizmo set gizmo } {aevt\ansr{errs:Ґrror essage, errn:-1703}} catch {tclAE::removeEventHandler Tcl test testHandler} catch {rename testHandler ""} test tclAEHandler-4.8 {tclAE::installEventHandler error from handler} {macOnly tclAE tclAEshlb} { proc testHandler {theAppleEvent theReplyAE} { error::throwOSErr -1703 } catch {tclAE::installEventHandler Tcl test testHandler} catch {tclAE::send -r -p $testProgram Tcl test ---- {some text}} gizmo regsub {(aevt\\ansr\{errs:Some data was the wrong type., errn:-1703).*\}} $gizmo "\\1\}" gizmo set gizmo } {aevt\ansr{errs:Some data was the wrong type., errn:-1703}} catch {tclAE::removeEventHandler Tcl test testHandler} catch {rename testHandler ""} test tclAEHandler-4.9.1 {tclAE::installEventHandler no proc} {macOnly tclAE tclAEshlb} { catch {tclAE::removeEventHandler Tcl test testHandler} catch {tclAE::installEventHandler Tcl test testHandler} catch {tclAE::send -r -p $testProgram Tcl test ---- {some text}} msg regsub {(AESend failed: OSErr -1717|aevt\\ansr\{errn:-1717.*\})} $msg "aevt\\ansr{errn:-1717}" msg set msg } {aevt\ansr{errn:-1717}} test tclAEHandler-4.9.2 {tclAE::installEventHandler no proc} {macOnly tclAE tclAEalphaTcl} { catch {tclAE::removeEventHandler Tcl test testHandler} catch {tclAE::installEventHandler Tcl test testHandler} catch {tclAE::send -r -p $testProgram Tcl test ---- {some text}} msg list $msg } {{aevt\ansr{'----':invalid command name "testHandler"}}} catch {tclAE::removeEventHandler Tcl test testHandler} catch {rename testHandler ""} test tclAEHandler-5.1 {tclAE::getEventHandler noargs} {macOnly tclAEshlb} { set err [catch {tclAE::getEventHandler} msg] list $err $msg } {1 {wrong # args: should be "tclAE::getEventHandler "}} test tclAEHandler-5.2 {tclAE::getEventHandler} {macOnly tclAE tclAE} { proc testHandler {theAppleEvent theReplyAE} { } catch {tclAE::installEventHandler Tcl test testHandler} catch {tclAE::getEventHandler Tcl test} handler list $handler } {testHandler} catch {tclAE::removeEventHandler Tcl test testHandler} test tclAEHandler-5.3.1 {tclAE::getEventHandler no handler} {macOnly tclAE tclAEshlb} { catch {tclAE::removeEventHandler Tcl test testHandler} catch {tclAE::getEventHandler Tcl test} msg regsub {(Couldn't find event handler: )(No handler in the dispatch tables fits the parameters to AEGetEventHandler or AEGetCoercionHandler|OSErr -1717)} $msg {\1No handler in the dispatch tables fits the parameters to AEGetEventHandler or AEGetCoercionHandler} msg list $msg } {{Couldn't find event handler: No handler in the dispatch tables fits the parameters to AEGetEventHandler or AEGetCoercionHandler}} test tclAEHandler-5.3.2 {tclAE::getEventHandler no handler} {macOnly tclAE tclAEalphaTcl} { catch {tclAE::removeEventHandler Tcl test testHandler} catch {tclAE::getEventHandler Tcl test} msg list $msg } {{The handler is not defined.}} test tclAEHandler-6.1 {tclAE::removeEventHandler noargs} {macOnly tclAEshlb} { set err [catch {tclAE::removeEventHandler} msg] list $err $msg } {1 {wrong # args: should be "tclAE::removeEventHandler "}} test tclAEHandler-6.2.1 {tclAE::removeEventHandler} {macOnly tclAE tclAEshlb} { catch {tclAE::installEventHandler Tcl test testHandler} catch {tclAE::getEventHandler Tcl test} handler catch {tclAE::removeEventHandler Tcl test testHandler} msg1 catch {tclAE::getEventHandler Tcl test} msg2 regsub {(Couldn't find event handler: )(No handler in the dispatch tables fits the parameters to AEGetEventHandler or AEGetCoercionHandler|OSErr -1717)} $msg2 {\1No handler in the dispatch tables fits the parameters to AEGetEventHandler or AEGetCoercionHandler} msg2 list $handler $msg1 $msg2 } {testHandler {} {Couldn't find event handler: No handler in the dispatch tables fits the parameters to AEGetEventHandler or AEGetCoercionHandler}} test tclAEHandler-6.2.2 {tclAE::removeEventHandler} {macOnly tclAE tclAEalphaTcl} { catch {tclAE::installEventHandler Tcl test testHandler} catch {tclAE::getEventHandler Tcl test} handler catch {tclAE::removeEventHandler Tcl test testHandler} msg1 catch {tclAE::getEventHandler Tcl test} msg2 list $handler $msg1 $msg2 } {testHandler {} {The handler is not defined.}} test tclAEHandler-6.3.1 {tclAE::removeEventHandler no handler} {macOnly tclAE tclAEshlb} { catch {tclAE::removeEventHandler Tcl test testHandler} catch {tclAE::removeEventHandler Tcl test testHandler} msg regsub {(Couldn't remove event handler: )(No handler in the dispatch tables fits the parameters to AEGetEventHandler or AEGetCoercionHandler|OSErr -1717)} $msg {\1No handler in the dispatch tables fits the parameters to AEGetEventHandler or AEGetCoercionHandler} msg set msg } {Couldn't remove event handler: No handler in the dispatch tables fits the parameters to AEGetEventHandler or AEGetCoercionHandler} test tclAEHandler-6.3.2 {tclAE::removeEventHandler no handler} {macOnly tclAE tclAEalphaTcl} { catch {tclAE::removeEventHandler Tcl test testHandler} catch {tclAE::removeEventHandler Tcl test testHandler} msg list $msg } {{The handler is not defined.}} ::tcltest::cleanupTests return