1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

This commit was manufactured by cvs2svn to create branch 'ruby_1_8'.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@7302 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
(no author) 2004-11-17 14:49:07 +00:00
parent 7ce7c614c5
commit 970ce679ff
12 changed files with 396 additions and 0 deletions

1
lib/xmlrpc/.document Normal file
View file

@ -0,0 +1 @@
README.rdoc

View file

@ -0,0 +1,26 @@
require 'test/unit'
class TestSetTraceFunc < Test::Unit::TestCase
def foo; end
def test_event
events = []
set_trace_func(Proc.new { |event, file, lineno|
events << [event, lineno]
})
a = 1
foo
a
set_trace_func nil
assert_equal(["line", 11], events.shift) # line "a = 1"
assert_equal(["line", 12], events.shift) # line "foo"
assert_equal(["call", 4], events.shift) # call foo
event, lineno = events.shift # return
assert_equal("return", event)
assert_equal(4, lineno) # [history] it could not be expected in 1.8
assert_equal(["line", 13], events.shift) # line "a"
assert_equal(["line", 14], events.shift) # line "set_trace_func nil"
assert_equal(["c-call", 14], events.shift) # c-call set_trace_func
end
end

View file

@ -0,0 +1,8 @@
<?xml version="1.0"?>
<methodResponse>
<params>
<param>
<value><boolean>0</boolean></value>
</param>
</params>
</methodResponse>

View file

@ -0,0 +1,8 @@
<?xml version="1.0"?>
<methodResponse>
<params>
<param>
<value><string><![CDATA[test]]></string></value>
</param>
</params>
</methodResponse>

View file

@ -0,0 +1,6 @@
<?xml version="1.0"
encoding="ISO-8859-1"?><methodResponse><params><param><value>Site,SANs,Array
Configured Capacity,Array Reserved Capacity,Array Ava
ilable Capacity,Array % Reserved,Host Allocated,Host Used,Host Free,Host %
Used
</value></param></params></methodResponse>

View file

@ -0,0 +1,8 @@
<?xml version="1.0"?>
<methodResponse>
<params>
<param>
<value><dateTime.iso8601>20041105T01:15:23Z</dateTime.iso8601></value>
</param>
</params>
</methodResponse>

View file

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<methodResponse>
<fault>
<value><struct>
<member>
<name>faultCode</name>
<value><int>4</int></value>
</member>
<member>
<name>faultString</name>
<value>an error message</value>
</member>
</struct></value>
</fault>
</methodResponse>

View file

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<methodCall>
<methodName>Test</methodName>
<params>
<param>
<value>Hallo Leute</value>
</param>
<param>
<value> Hallo </value>
</param>
<param>
<value></value>
</param>
<param>
<value> </value>
</param>
</params>
</methodCall>

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,159 @@
require 'test/unit'
require "xmlrpc/datetime"
class Test_DateTime < Test::Unit::TestCase
def test_new
dt = createDateTime()
assert_instance_of(XMLRPC::DateTime, dt)
end
def test_new_exception
assert_raises(ArgumentError) { XMLRPC::DateTime.new(4.5, 13, 32, 25, 60, 60) }
assert_raises(ArgumentError) { XMLRPC::DateTime.new(2001, 12, 32, 25, 60, 60) }
assert_raises(ArgumentError) { XMLRPC::DateTime.new(2001, 12, 31, 25, 60, 60) }
assert_raises(ArgumentError) { XMLRPC::DateTime.new(2001, 12, 31, 24, 60, 60) }
assert_raises(ArgumentError) { XMLRPC::DateTime.new(2001, 12, 31, 24, 59, 60) }
assert_nothing_raised(ArgumentError) { XMLRPC::DateTime.new(2001, 12, 31, 24, 59, 59) }
assert_raises(ArgumentError) { XMLRPC::DateTime.new(2001, 0, 0, -1, -1, -1) }
assert_raises(ArgumentError) { XMLRPC::DateTime.new(2001, 1, 0, -1, -1, -1) }
assert_raises(ArgumentError) { XMLRPC::DateTime.new(2001, 1, 1, -1, -1, -1) }
assert_raises(ArgumentError) { XMLRPC::DateTime.new(2001, 1, 1, 0, -1, -1) }
assert_raises(ArgumentError) { XMLRPC::DateTime.new(2001, 1, 1, 0, 0, -1) }
assert_nothing_raised(ArgumentError) { XMLRPC::DateTime.new(2001, 1, 1, 0, 0, 0) }
end
def test_get_values
y, m, d, h, mi, s = 1970, 3, 24, 12, 0, 5
dt = XMLRPC::DateTime.new(y, m, d, h, mi, s)
assert_equal(y, dt.year)
assert_equal(m, dt.month)
assert_equal(m, dt.mon)
assert_equal(d, dt.day)
assert_equal(h, dt.hour)
assert_equal(mi,dt.min)
assert_equal(s, dt.sec)
end
def test_set_values
dt = createDateTime()
y, m, d, h, mi, s = 1950, 12, 9, 8, 52, 30
dt.year = y
dt.month = m
dt.day = d
dt.hour = h
dt.min = mi
dt.sec = s
assert_equal(y, dt.year)
assert_equal(m, dt.month)
assert_equal(m, dt.mon)
assert_equal(d, dt.day)
assert_equal(h, dt.hour)
assert_equal(mi,dt.min)
assert_equal(s, dt.sec)
dt.mon = 5
assert_equal(5, dt.month)
assert_equal(5, dt.mon)
end
def test_set_exception
dt = createDateTime()
assert_raises(ArgumentError) { dt.year = 4.5 }
assert_nothing_raised(ArgumentError) { dt.year = -2000 }
assert_raises(ArgumentError) { dt.month = 0 }
assert_raises(ArgumentError) { dt.month = 13 }
assert_nothing_raised(ArgumentError) { dt.month = 7 }
assert_raises(ArgumentError) { dt.mon = 0 }
assert_raises(ArgumentError) { dt.mon = 13 }
assert_nothing_raised(ArgumentError) { dt.mon = 7 }
assert_raises(ArgumentError) { dt.day = 0 }
assert_raises(ArgumentError) { dt.day = 32 }
assert_nothing_raised(ArgumentError) { dt.day = 16 }
assert_raises(ArgumentError) { dt.hour = -1 }
assert_raises(ArgumentError) { dt.hour = 25 }
assert_nothing_raised(ArgumentError) { dt.hour = 12 }
assert_raises(ArgumentError) { dt.min = -1 }
assert_raises(ArgumentError) { dt.min = 60 }
assert_nothing_raised(ArgumentError) { dt.min = 30 }
assert_raises(ArgumentError) { dt.sec = -1 }
assert_raises(ArgumentError) { dt.sec = 60 }
assert_nothing_raised(ArgumentError) { dt.sec = 30 }
end
def test_to_a
y, m, d, h, mi, s = 1970, 3, 24, 12, 0, 5
dt = XMLRPC::DateTime.new(y, m, d, h, mi, s)
a = dt.to_a
assert_instance_of(Array, a)
assert_equal(6, a.size, "Returned array has wrong size")
assert_equal(y, a[0])
assert_equal(m, a[1])
assert_equal(d, a[2])
assert_equal(h, a[3])
assert_equal(mi, a[4])
assert_equal(s, a[5])
end
def test_to_time1
y, m, d, h, mi, s = 1970, 3, 24, 12, 0, 5
dt = XMLRPC::DateTime.new(y, m, d, h, mi, s)
time = dt.to_time
assert_not_nil(time)
assert_equal(y, time.year)
assert_equal(m, time.month)
assert_equal(d, time.day)
assert_equal(h, time.hour)
assert_equal(mi, time.min)
assert_equal(s, time.sec)
end
def test_to_time2
dt = createDateTime()
dt.year = 1969
assert_nil(dt.to_time)
end
def test_to_date1
y, m, d, h, mi, s = 1970, 3, 24, 12, 0, 5
dt = XMLRPC::DateTime.new(y, m, d, h, mi, s)
date = dt.to_date
assert_equal(y, date.year)
assert_equal(m, date.month)
assert_equal(d, date.day)
end
def test_to_date2
dt = createDateTime()
dt.year = 666
assert_equal(666, dt.to_date.year)
end
def createDateTime
XMLRPC::DateTime.new(1970, 3, 24, 12, 0, 5)
end
end

View file

@ -0,0 +1,48 @@
require 'test/unit'
require "xmlrpc/create"
require "xmlrpc/parser"
require "xmlrpc/config"
class Test_Features < Test::Unit::TestCase
def setup
@params = [nil, {"test" => nil}, [nil, 1, nil]]
end
def test_nil_create
XMLRPC::XMLWriter.each_installed_writer do |writer|
c = XMLRPC::Create.new(writer)
XMLRPC::Config.module_eval {remove_const(:ENABLE_NIL_CREATE)}
XMLRPC::Config.const_set(:ENABLE_NIL_CREATE, false)
assert_raises(RuntimeError) { str = c.methodCall("test", *@params) }
XMLRPC::Config.module_eval {remove_const(:ENABLE_NIL_CREATE)}
XMLRPC::Config.const_set(:ENABLE_NIL_CREATE, true)
assert_nothing_raised { str = c.methodCall("test", *@params) }
end
end
def test_nil_parse
XMLRPC::Config.module_eval {remove_const(:ENABLE_NIL_CREATE)}
XMLRPC::Config.const_set(:ENABLE_NIL_CREATE, true)
XMLRPC::XMLWriter.each_installed_writer do |writer|
c = XMLRPC::Create.new(writer)
str = c.methodCall("test", *@params)
XMLRPC::XMLParser.each_installed_parser do |parser|
para = nil
XMLRPC::Config.module_eval {remove_const(:ENABLE_NIL_PARSER)}
XMLRPC::Config.const_set(:ENABLE_NIL_PARSER, false)
assert_raises(RuntimeError) { para = parser.parseMethodCall(str) }
XMLRPC::Config.module_eval {remove_const(:ENABLE_NIL_PARSER)}
XMLRPC::Config.const_set(:ENABLE_NIL_PARSER, true)
assert_nothing_raised { para = parser.parseMethodCall(str) }
assert_equal(para[1], @params)
end
end
end
end

View file

@ -0,0 +1,93 @@
require 'test/unit'
require "xmlrpc/marshal"
class Test_Marshal < Test::Unit::TestCase
# for test_parser_values
class Person
include XMLRPC::Marshallable
attr_reader :name
def initialize(name)
@name = name
end
end
def test1_dump_response
assert_nothing_raised(NameError) {
XMLRPC::Marshal.dump_response('arg')
}
end
def test1_dump_call
assert_nothing_raised(NameError) {
XMLRPC::Marshal.dump_call('methodName', 'arg')
}
end
def test2_dump_load_response
value = [1, 2, 3, {"test" => true}, 3.4]
res = XMLRPC::Marshal.dump_response(value)
assert_equal(value, XMLRPC::Marshal.load_response(res))
end
def test2_dump_load_call
methodName = "testMethod"
value = [1, 2, 3, {"test" => true}, 3.4]
exp = [methodName, [value, value]]
res = XMLRPC::Marshal.dump_call(methodName, value, value)
assert_equal(exp, XMLRPC::Marshal.load_call(res))
end
def test_parser_values
v1 = [
1, -7778, # integers
1.0, 0.0, -333.0, 2343434343.0, # floats
false, true, true, false, # booleans
"Hallo", "with < and >", "" # strings
]
v2 = [
[v1, v1, v1],
{"a" => v1}
]
v3 = [
XMLRPC::Base64.new("\001"*1000), # base64
:aSymbol, :anotherSym # symbols (-> string)
]
v3_exp = [
"\001"*1000,
"aSymbol", "anotherSym"
]
person = Person.new("Michael")
XMLRPC::XMLParser.each_installed_parser do |parser|
m = XMLRPC::Marshal.new(parser)
assert_equal( v1, m.load_response(m.dump_response(v1)) )
assert_equal( v2, m.load_response(m.dump_response(v2)) )
assert_equal( v3_exp, m.load_response(m.dump_response(v3)) )
pers = m.load_response(m.dump_response(person))
assert( pers.is_a?(Person) )
assert( person.name == pers.name )
end
# missing, Date, Time, DateTime
# Struct
end
def test_no_params_tag
# bug found by Idan Sofer
expect = %{<?xml version="1.0" ?><methodCall><methodName>myMethod</methodName><params/></methodCall>\n}
str = XMLRPC::Marshal.dump_call("myMethod")
assert_equal(expect, str)
end
end