#
# The contents of this file are subject to the AOLserver Public License
# Version 1.1 (the "License"); you may not use this file except in
# compliance with the License. You may obtain a copy of the License at
# http://aolserver.com/.
#
# Software distributed under the License is distributed on an "AS IS"
# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
# the License for the specific language governing rights and limitations
# under the License.
#
# The Original Code is AOLserver Code and related documentation
# distributed by AOL.
#
# The Initial Developer of the Original Code is America Online,
# Inc. Portions created by AOL are Copyright (C) 1999 America Online,
# Inc. All Rights Reserved.
#
# Alternatively, the contents of this file may be used under the terms
# of the GNU General Public License (the "GPL"), in which case the
# provisions of GPL are applicable instead of those above. If you wish
# to allow use of your version of this file only under the terms of the
# GPL and not to allow others to use your version of this file under the
# License, indicate your decision by deleting the provisions above and
# replace them with the notice and other provisions required by the GPL.
# If you do not delete the provisions above, a recipient may use your
# version of this file under either the License or the GPL.
#
#
# $Header$
#
#
# xmlrpc.test --
#
# Test cases for ns_xmlrpc.
#
package require tcltest 2.0
namespace import -force ::tcltest::*
source xmlrpc.tcl
proc ns_log args {}
# ============================================================
set N 0
test ns_xmlrpc-wait-1.[incr N] {parse simple methodResponse w/o type} -setup {
proc ns_http {verb id &var args} {
upvar ${&var} var
set var {
hello world
}
return 1
}
} -body {
ns_xmlrpc wait dummy
} -cleanup {
rename ns_http {}
} -result {{hello world}}
test ns_xmlrpc-wait-1.[incr N] {parse simple methodResponse w/ type} -setup {
proc ns_http {verb id &var args} {
upvar ${&var} var
set var {
hello world
42
}
return 1
}
} -body {
ns_xmlrpc wait dummy
} -cleanup {
rename ns_http {}
} -result {{hello world} 42}
test ns_xmlrpc-wait-1.[incr N] {parse array methodResponse} -setup {
proc ns_http {verb id &var args} {
upvar ${&var} var
set var {
4.12
13.68
1.93
0.78
}
return 1
}
} -body {
ns_xmlrpc wait dummy
} -cleanup {
rename ns_http {}
} -result {{4.12 13.68 1.93 0.78}}
test ns_xmlrpc-wait-1.[incr N] {parse struct methodResponse} -setup {
proc ns_http {verb id &var args} {
upvar ${&var} var
set var {
symbol
RHAT
limit
2.25
}
return 1
}
} -body {
ns_xmlrpc wait dummy
} -cleanup {
rename ns_http {}
} -result {{{symbol RHAT} {limit 2.25}}}
test ns_xmlrpc-wait-2.[incr N] {simulate timeout condition} -setup {
proc ns_http {verb id &var args} {
upvar ${&var} var
set var timeout
return 0
}
} -body {
ns_xmlrpc wait dummy
} -cleanup {
rename ns_http {}
} -result {}
# ============================================================
set N 0
test ns_xmlrpc-queue-1.[incr N] {simple call w/ no args} -setup {
proc ns_set {args} {}
proc ns_http {verb url method body hdrs args} {
set ::request $body
}
set ::request {}
} -body {
ns_xmlrpc queue http://rpc.domain.com/rpc methodName
set ::request
} -cleanup {
rename ns_set {}
rename ns_http {}
unset ::request
} -result {
methodName
}
test ns_xmlrpc-queue-1.[incr N] {simple call w/ args} -setup {
proc ns_set {args} {}
proc ns_http {verb url method body hdrs args} {
set ::request $body
}
set ::request {}
} -body {
ns_xmlrpc queue http://rpc.domain.com/rpc methodName arg1 arg2 arg3
set ::request
} -cleanup {
rename ns_set {}
rename ns_http {}
unset ::request
} -result {
methodNamearg1arg2arg3
}
# ============================================================
set N 0
test ns_xmlrpc-fault-1.[incr N] {fault response formatter} -body {
ns_xmlrpc fault 123 "fault string"
} -result {
faultCode123faultStringfault string
}
test ns_xmlrpc-fault-1.[incr N] {test -indent 4} -body {
ns_xmlrpc fault -indent 4 123 "fault string"
} -result {
faultCode
123
faultString
fault string
}
# ============================================================
set N 0
test ns_xmlrpc-format-1.[incr N] {single param} -body {
ns_xmlrpc format {string {hello world}}
} -result {
hello world
}
test ns_xmlrpc-format-1.[incr N] {multiple params} -body {
ns_xmlrpc format {string {hello world}} {i4 42}
} -result {
hello world42
}
test ns_xmlrpc-format-1.[incr N] {response w/ array} -body {
ns_xmlrpc format {array {{string {hello world}} {i4 42}}}
} -result {
hello world42
}
test ns_xmlrpc-format-1.[incr N] {response w/ struct} -body {
ns_xmlrpc format {struct {foo {string {hello world}} bar {i4 42}}}
} -result {
foohello worldbar42
}
test ns_xmlrpc-format-1.[incr N] {complex response} -body {
ns_xmlrpc format -indent 4 \
{string {simple scalar}} \
{array {{struct {foo {string {hello world}} bar {i4 42}}} {string {second element}}}} \
{struct {thing {array {{double 3.14} {boolean 0}}}}}
} -result {
simple scalar
foo
hello world
bar
42
second element
thing
3.14
0
}
## w.bloggar doesn't expect datatypes for Blogger API responses for
## simple types, but array and struct are special.
test ns_xmlrpc-format-1.[incr N] {no datatypes} -body {
ns_xmlrpc format -types no {string {hello world}}
} -result {
hello world
}
test ns_xmlrpc-format-1.[incr N] {no datatypes, response w/ array} -body {
ns_xmlrpc format -types no {array {{string {hello world}} {i4 42}}}
} -result {
hello world42
}
test ns_xmlrpc-format-1.[incr N] {no datatypes, response w/ struct} -body {
ns_xmlrpc format -types no {struct {foo {string {hello world}} bar {i4 42}}}
} -result {
foohello worldbar42
}
# ============================================================
set N 0
test ns_xmlrpc-listen-1.[incr N] {parse incoming methodCall, no args} -body {
ns_xmlrpc listen {
test.methodName}
} -result {test.methodName}
test ns_xmlrpc-listen-1.[incr N] {methodCall w/simple args} -body {
ns_xmlrpc listen {
test.methodNamefirstsecond arg}
} -result {test.methodName first {second arg}}
test ns_xmlrpc-listen-1.[incr N] {methodCall w/complex args} -body {
ns_xmlrpc listen {
test.methodName
simple scalar
foo
hello world
bar
42
second element
thing
3.14
0
}
} -result {test.methodName {simple scalar} {{{foo {hello world}} {bar 42}} {second element}} {{thing {3.14 0}}}}
# ============================================================
cleanupTests
#
# Example usage:
#
# ns_xmlrpc call http://ping.blo.gs/ weblogUpdates.ping {Dossy's Blog} http://dossy.org/index.rdf
#