# xmlrpc.test - Copyright (C) 2001 Pat Thoyts # # Provide a set of tests to excercise the XMLRPC package. # # @(#)$Id: xmlrpc.test,v 1.2 2001/08/03 21:44:23 patthoyts Exp $ # Initialize the required packages if {[lsearch [namespace children] ::tcltest] == -1} { package require tcltest namespace import ::tcltest::* #source [file join [pwd] [file dirname [info script]] defs.tcl] } if {[catch {package require XMLRPC}]} { catch {puts stderr "Cannot load the XMLRPC package"} return } # ------------------------------------------------------------------------- # Test transport method returns the query. Should result in invoke # returning the parameters to the method. proc ::XMLRPC::transport_test { procName url xml } { set ::XMLRPC::testXML $xml return $xml } # ------------------------------------------------------------------------- # XMLRPC method creation and configuration test. test xmlrpc-1.1 {XMLRPC Method creation} { XMLRPC::create xmlrpcTest \ -uri urn:xmlrpc-Test \ -proxy http://localhost:8015/rpc/test \ -params { "arg" "string" } \ -name "tests.xmlrpcTest" \ -transport ::XMLRPC::transport_test } {::xmlrpcTest} test xmlrpc-1.2 {XMLRPC cget URI value} { catch {XMLRPC::cget ::xmlrpcTest -uri} result set result } {urn:xmlrpc-Test} test xmlrpc-1.3 {Reset the URI value} { catch {XMLRPC::configure ::xmlrpcTest -uri urn:new-xmlrpc-Test} result set result } {::xmlrpcTest} test xmlrpc-1.4 {XMLRPC cget the new URI value} { catch {XMLRPC::cget ::xmlrpcTest -uri} result set result } {urn:new-xmlrpc-Test} # ------------------------------------------------------------------------- test xmlrpc-2.1 {XML generation with no arguments} { catch {::xmlrpcTest} result set result } {wrong # args: should be "xmlrpcTest arg"} test xmlrpc-2.2 {XML generation with one argument} { if { ! [catch {::xmlrpcTest testParameter} result] } { set result $::XMLRPC::testXML } set result } { tests.xmlrpcTesttestParameter} test xmlrpc-2.3 {XML generation with two arguments} { set failed [catch {::XMLRPC::configure ::xmlrpcTest \ -params { "text" "string" "number" "double" }} result] if { ! $failed } { set failed [catch {::xmlrpcTest textParam 1.3} result] } if { ! $failed } { set result $::XMLRPC::testXML } set result } { tests.xmlrpcTesttextParam1.3} test xmlrpc-2.4 {XML generation with array argument} { set failed [catch {::XMLRPC::configure ::xmlrpcTest \ -params {nums int()} } result] if { ! $failed } { set failed [catch {::xmlrpcTest {1 2 3}} result] } if { ! $failed } { set result $::XMLRPC::testXML } set result } { tests.xmlrpcTest123} test xmlrpc-2.5 {XML generation with struct argument} { set failed [catch {::XMLRPC::configure ::xmlrpcTest \ -params {point struct} } result] if { ! $failed } { set failed [catch {::xmlrpcTest {x 1 y 2}} result] } if { ! $failed } { set result $::XMLRPC::testXML } set result } { tests.xmlrpcTestx1y2} # ------------------------------------------------------------------------- test xmlrpc-3.1 {XMLRPC reply processing} { proc replyProc {methodName xml} { set xml "FIXED" append xml "" return $xml } set failed [catch {::XMLRPC::configure ::xmlrpcTest \ -params {text string num double} \ -replyProc [namespace current]::replyProc} result] if { ! $failed } { set failed [catch {::xmlrpcTest textParam 1.3} result] } set result } {FIXED} test xmlrpc-3.2 {reply post processing via -postProc} { proc replyProc {methodName xml} { set xml "" append xml "FIXED" append xml "1.3" append xml "" return $xml } proc postProc { methodName reply } { return [lindex $reply 1] } set failed [catch {::XMLRPC::configure ::xmlrpcTest \ -replyProc [namespace current]::replyProc \ -postProc [namespace current]::postProc} result] if { ! $failed } { set failed [catch {::xmlrpcTest textParam 1.3} result] } set result } {1.3} # ------------------------------------------------------------------------- # Clean up the tests ::tcltest::cleanupTests return # Local variables: # mode: tcl # indent-tabs-mode: nil # End: