mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/soap/* (29 files): SOAP4R added.
* lib/wsdl/* (42 files): WSDL4R added. * lib/xsd/* (12 files): XSD4R added. * test/soap/* (16 files): added. * test/wsdl/* (2 files): added. * test/xsd/* (3 files): added. * sample/soap/* (27 files): added. * sample/wsdl/* (13 files): added. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4591 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
8c2fb77787
commit
db9445103c
145 changed files with 20938 additions and 0 deletions
17
test/soap/calc/calc.rb
Normal file
17
test/soap/calc/calc.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
module CalcService
|
||||
def self.add(lhs, rhs)
|
||||
lhs + rhs
|
||||
end
|
||||
|
||||
def self.sub(lhs, rhs)
|
||||
lhs - rhs
|
||||
end
|
||||
|
||||
def self.multi(lhs, rhs)
|
||||
lhs * rhs
|
||||
end
|
||||
|
||||
def self.div(lhs, rhs)
|
||||
lhs / rhs
|
||||
end
|
||||
end
|
29
test/soap/calc/calc2.rb
Normal file
29
test/soap/calc/calc2.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
class CalcService2
|
||||
def initialize(value = 0)
|
||||
@value = value
|
||||
end
|
||||
|
||||
def set(value)
|
||||
@value = value
|
||||
end
|
||||
|
||||
def get
|
||||
@value
|
||||
end
|
||||
|
||||
def +(rhs)
|
||||
@value + rhs
|
||||
end
|
||||
|
||||
def -(rhs)
|
||||
@value - rhs
|
||||
end
|
||||
|
||||
def *(rhs)
|
||||
@value * rhs
|
||||
end
|
||||
|
||||
def /(rhs)
|
||||
@value / rhs
|
||||
end
|
||||
end
|
15
test/soap/calc/server.cgi
Normal file
15
test/soap/calc/server.cgi
Normal file
|
@ -0,0 +1,15 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
require 'soap/rpc/cgistub'
|
||||
|
||||
class CalcServer < SOAP::RPC::CGIStub
|
||||
def initialize(*arg)
|
||||
super
|
||||
|
||||
require 'calc'
|
||||
servant = CalcService
|
||||
add_servant(servant, 'http://tempuri.org/calcService')
|
||||
end
|
||||
end
|
||||
|
||||
status = CalcServer.new('CalcServer', nil).start
|
17
test/soap/calc/server.rb
Normal file
17
test/soap/calc/server.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
require 'soap/rpc/standaloneServer'
|
||||
require 'calc'
|
||||
|
||||
class CalcServer < SOAP::RPC::StandaloneServer
|
||||
def initialize(*arg)
|
||||
super
|
||||
|
||||
servant = CalcService
|
||||
add_servant(servant, 'http://tempuri.org/calcService')
|
||||
end
|
||||
end
|
||||
|
||||
if $0 == __FILE__
|
||||
status = CalcServer.new('CalcServer', nil, '0.0.0.0', 7000).start
|
||||
end
|
20
test/soap/calc/server2.rb
Normal file
20
test/soap/calc/server2.rb
Normal file
|
@ -0,0 +1,20 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
require 'soap/rpc/standaloneServer'
|
||||
require 'calc2'
|
||||
|
||||
class CalcServer2 < SOAP::RPC::StandaloneServer
|
||||
def on_init
|
||||
servant = CalcService2.new
|
||||
add_method(servant, 'set', 'newValue')
|
||||
add_method(servant, 'get')
|
||||
add_method_as(servant, '+', 'add', 'lhs')
|
||||
add_method_as(servant, '-', 'sub', 'lhs')
|
||||
add_method_as(servant, '*', 'multi', 'lhs')
|
||||
add_method_as(servant, '/', 'div', 'lhs')
|
||||
end
|
||||
end
|
||||
|
||||
if $0 == __FILE__
|
||||
status = CalcServer2.new('CalcServer', 'http://tempuri.org/calcService', '0.0.0.0', 7000).start
|
||||
end
|
41
test/soap/calc/test_calc.rb
Normal file
41
test/soap/calc/test_calc.rb
Normal file
|
@ -0,0 +1,41 @@
|
|||
require 'test/unit'
|
||||
require 'soap/rpc/driver'
|
||||
|
||||
dir = File.dirname(__FILE__)
|
||||
$:.push(dir)
|
||||
require 'server.rb'
|
||||
$:.delete(dir)
|
||||
|
||||
class TestCalc < Test::Unit::TestCase
|
||||
def setup
|
||||
@server = CalcServer.new(self.class.name, nil, '0.0.0.0', 7000)
|
||||
@t = Thread.new {
|
||||
@server.start
|
||||
}
|
||||
while @server.server.status != :Running
|
||||
sleep 0.1
|
||||
end
|
||||
@calc = SOAP::RPC::Driver.new('http://localhost:7000/', 'http://tempuri.org/calcService')
|
||||
@calc.add_method('add', 'lhs', 'rhs')
|
||||
@calc.add_method('sub', 'lhs', 'rhs')
|
||||
@calc.add_method('multi', 'lhs', 'rhs')
|
||||
@calc.add_method('div', 'lhs', 'rhs')
|
||||
end
|
||||
|
||||
def teardown
|
||||
@server.server.shutdown
|
||||
@t.kill
|
||||
end
|
||||
|
||||
def test_calc
|
||||
assert_equal(3, @calc.add(1, 2))
|
||||
assert_equal(-1.1, @calc.sub(1.1, 2.2))
|
||||
assert_equal(2.42, @calc.multi(1.1, 2.2))
|
||||
assert_equal(2, @calc.div(5, 2))
|
||||
assert_equal(2.5, @calc.div(5.0, 2))
|
||||
assert_equal(1.0/0.0, @calc.div(1.1, 0))
|
||||
assert_raises(ZeroDivisionError) do
|
||||
@calc.div(1, 0)
|
||||
end
|
||||
end
|
||||
end
|
43
test/soap/calc/test_calc2.rb
Normal file
43
test/soap/calc/test_calc2.rb
Normal file
|
@ -0,0 +1,43 @@
|
|||
require 'test/unit'
|
||||
require 'soap/rpc/driver'
|
||||
|
||||
dir = File.dirname(__FILE__)
|
||||
$:.push(dir)
|
||||
require 'server2.rb'
|
||||
$:.delete(dir)
|
||||
|
||||
class TestCalc2 < Test::Unit::TestCase
|
||||
def setup
|
||||
@server = CalcServer2.new('CalcServer', 'http://tempuri.org/calcService', '0.0.0.0', 7000)
|
||||
@t = Thread.new {
|
||||
@server.start
|
||||
}
|
||||
while @server.server.status != :Running
|
||||
sleep 0.1
|
||||
end
|
||||
@var = SOAP::RPC::Driver.new('http://localhost:7000/', 'http://tempuri.org/calcService')
|
||||
@var.add_method('set', 'newValue')
|
||||
@var.add_method('get')
|
||||
@var.add_method_as('+', 'add', 'rhs')
|
||||
@var.add_method_as('-', 'sub', 'rhs')
|
||||
@var.add_method_as('*', 'multi', 'rhs')
|
||||
@var.add_method_as('/', 'div', 'rhs')
|
||||
end
|
||||
|
||||
def teardown
|
||||
@server.server.shutdown
|
||||
@t.kill
|
||||
end
|
||||
|
||||
def test_calc2
|
||||
assert_equal(1, @var.set(1))
|
||||
assert_equal(3, @var + 2)
|
||||
assert_equal(-1.2, @var - 2.2)
|
||||
assert_equal(2.2, @var * 2.2)
|
||||
assert_equal(0, @var / 2)
|
||||
assert_equal(0.5, @var / 2.0)
|
||||
assert_raises(ZeroDivisionError) do
|
||||
@var / 0
|
||||
end
|
||||
end
|
||||
end
|
42
test/soap/calc/test_calc_cgi.rb
Normal file
42
test/soap/calc/test_calc_cgi.rb
Normal file
|
@ -0,0 +1,42 @@
|
|||
require 'test/unit'
|
||||
require 'soap/rpc/driver'
|
||||
require 'webrick'
|
||||
|
||||
class TestCalcCGI < Test::Unit::TestCase
|
||||
def setup
|
||||
@server = WEBrick::HTTPServer.new(
|
||||
:BindAddress => "0.0.0.0",
|
||||
:Port => 8808,
|
||||
:DocumentRoot => File.dirname(File.expand_path(__FILE__)),
|
||||
:CGIPathEnv => ENV['PATH']
|
||||
)
|
||||
@t = Thread.new {
|
||||
@server.start
|
||||
}
|
||||
while @server.status != :Running
|
||||
sleep 0.1
|
||||
end
|
||||
@calc = SOAP::RPC::Driver.new('http://localhost:8808/server.cgi', 'http://tempuri.org/calcService')
|
||||
@calc.add_method('add', 'lhs', 'rhs')
|
||||
@calc.add_method('sub', 'lhs', 'rhs')
|
||||
@calc.add_method('multi', 'lhs', 'rhs')
|
||||
@calc.add_method('div', 'lhs', 'rhs')
|
||||
end
|
||||
|
||||
def teardown
|
||||
@server.shutdown
|
||||
@t.kill
|
||||
end
|
||||
|
||||
def test_calc
|
||||
assert_equal(3, @calc.add(1, 2))
|
||||
assert_equal(-1.1, @calc.sub(1.1, 2.2))
|
||||
assert_equal(2.42, @calc.multi(1.1, 2.2))
|
||||
assert_equal(2, @calc.div(5, 2))
|
||||
assert_equal(2.5, @calc.div(5.0, 2))
|
||||
assert_equal(1.0/0.0, @calc.div(1.1, 0))
|
||||
assert_raises(ZeroDivisionError) do
|
||||
@calc.div(1, 0)
|
||||
end
|
||||
end
|
||||
end
|
17
test/soap/helloworld/hw_s.rb
Normal file
17
test/soap/helloworld/hw_s.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
require 'soap/rpc/standaloneServer'
|
||||
|
||||
class HelloWorldServer < SOAP::RPC::StandaloneServer
|
||||
def on_init
|
||||
@log.level = Logger::Severity::DEBUG
|
||||
add_method(self, 'hello_world', 'from')
|
||||
end
|
||||
|
||||
def hello_world(from)
|
||||
"Hello World, from #{ from }"
|
||||
end
|
||||
end
|
||||
|
||||
if $0 == __FILE__
|
||||
server = HelloWorldServer.new('hws', 'urn:hws', '0.0.0.0', 2000)
|
||||
server.start
|
||||
end
|
31
test/soap/helloworld/test_helloworld.rb
Normal file
31
test/soap/helloworld/test_helloworld.rb
Normal file
|
@ -0,0 +1,31 @@
|
|||
require 'test/unit'
|
||||
require 'soap/rpc/driver'
|
||||
|
||||
dir = File.dirname(__FILE__)
|
||||
$:.push(dir)
|
||||
require 'hw_s.rb'
|
||||
$:.delete(dir)
|
||||
|
||||
class TestHelloWorld < Test::Unit::TestCase
|
||||
def setup
|
||||
@server = HelloWorldServer.new('hws', 'urn:hws', '0.0.0.0', 2000)
|
||||
@t = Thread.new {
|
||||
@server.start
|
||||
}
|
||||
while @server.server.status != :Running
|
||||
sleep 0.1
|
||||
end
|
||||
@client = SOAP::RPC::Driver.new('http://localhost:2000/', 'urn:hws')
|
||||
@client.add_method("hello_world", "from")
|
||||
end
|
||||
|
||||
def teardown
|
||||
@server.server.shutdown
|
||||
@t.kill
|
||||
end
|
||||
|
||||
def test_hello_world
|
||||
assert_equal("Hello World, from NaHi", @client.hello_world("NaHi"))
|
||||
assert_equal("Hello World, from <&>", @client.hello_world("<&>"))
|
||||
end
|
||||
end
|
142
test/soap/marshal/cmarshal.rb
Normal file
142
test/soap/marshal/cmarshal.rb
Normal file
|
@ -0,0 +1,142 @@
|
|||
module CMarshal
|
||||
class << self
|
||||
public
|
||||
def ruby
|
||||
class << self
|
||||
def dump(o)
|
||||
Marshal.dump(o)
|
||||
end
|
||||
|
||||
def load(o)
|
||||
Marshal.load(o)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def amarshal
|
||||
require 'amarshal'
|
||||
class << self
|
||||
def dump(o)
|
||||
AMarshal.dump(o)
|
||||
end
|
||||
|
||||
def load(o)
|
||||
AMarshal.load(o)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def to_src
|
||||
require 'to_src'
|
||||
ToSrc.independent(false)
|
||||
class << self
|
||||
def dump(o)
|
||||
ToSrc.reset
|
||||
o.to_src
|
||||
end
|
||||
|
||||
def load(o)
|
||||
eval(o)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def to_source
|
||||
require 'ToSource'
|
||||
class << self
|
||||
def dump(o)
|
||||
o.to_source
|
||||
end
|
||||
|
||||
def load(o)
|
||||
eval(o)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class ClXmlSerialContainer
|
||||
attr_accessor :var
|
||||
end
|
||||
|
||||
def clxmlserial
|
||||
require 'cl/xmlserial'
|
||||
ClXmlSerialContainer.instance_eval { include XmlSerialization }
|
||||
class << self
|
||||
def dump(o)
|
||||
c = ClXmlSerialContainer.new
|
||||
c.var = o
|
||||
c.to_xml
|
||||
end
|
||||
|
||||
def load(o)
|
||||
ClXmlSerialContainer.from_xml(o).var
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def soap4r
|
||||
require 'soap/marshal'
|
||||
class << self
|
||||
def dump(o)
|
||||
SOAP::Marshal.dump(o)
|
||||
end
|
||||
|
||||
def load(o)
|
||||
SOAP::Marshal.load(o)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def xmarshal
|
||||
require 'xmarshal'
|
||||
class << self
|
||||
def dump(o)
|
||||
XMarshal.dump(o)
|
||||
end
|
||||
|
||||
def load(o)
|
||||
XMarshal.load(o)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def xmlrpc
|
||||
require 'xmlrpc/marshal'
|
||||
class << self
|
||||
def dump(o)
|
||||
XMLRPC::Marshal.dump(o)
|
||||
end
|
||||
|
||||
def load(o)
|
||||
XMLRPC::Marshal.load(o)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def tmarshal
|
||||
require 'tmarshal'
|
||||
class << self
|
||||
def dump(o)
|
||||
TMarshal.dump(o)
|
||||
end
|
||||
|
||||
def load(o)
|
||||
TMarshal.restore(o)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def yaml
|
||||
require 'yaml'
|
||||
class << self
|
||||
def dump(o)
|
||||
o.to_yaml
|
||||
end
|
||||
|
||||
def load(o)
|
||||
YAML.load(o)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
45
test/soap/marshal/test_digraph.rb
Normal file
45
test/soap/marshal/test_digraph.rb
Normal file
|
@ -0,0 +1,45 @@
|
|||
require 'test/unit'
|
||||
require 'soap/marshal'
|
||||
|
||||
class Node; include SOAP::Marshallable
|
||||
attr_reader :first, :second, :str
|
||||
|
||||
def initialize(*init_next)
|
||||
@first = init_next[0]
|
||||
@second = init_next[1]
|
||||
end
|
||||
end
|
||||
|
||||
class TestDigraph < Test::Unit::TestCase
|
||||
def setup
|
||||
@n9 = Node.new
|
||||
@n81 = Node.new(@n9)
|
||||
@n82 = Node.new(@n9)
|
||||
@n7 = Node.new(@n81, @n82)
|
||||
@n61 = Node.new(@n7)
|
||||
@n62 = Node.new(@n7)
|
||||
@n5 = Node.new(@n61, @n62)
|
||||
@n41 = Node.new(@n5)
|
||||
@n42 = Node.new(@n5)
|
||||
@n3 = Node.new(@n41, @n42)
|
||||
@n21 = Node.new(@n3)
|
||||
@n22 = Node.new(@n3)
|
||||
@n1 = Node.new(@n21, @n22)
|
||||
end
|
||||
|
||||
def test_marshal
|
||||
f = File.open("digraph_marshalled_string.soap", "wb")
|
||||
SOAP::Marshal.dump(@n1, f)
|
||||
f.close
|
||||
str = File.open("digraph_marshalled_string.soap").read
|
||||
newnode = SOAP::Marshal.unmarshal(str)
|
||||
assert_equal(newnode.first.first.__id__, newnode.second.first.__id__)
|
||||
assert_equal(newnode.first.first.first.first.__id__, newnode.second.first.second.first.__id__)
|
||||
end
|
||||
|
||||
def teardown
|
||||
if File.exist?("digraph_marshalled_string.soap")
|
||||
File.unlink("digraph_marshalled_string.soap")
|
||||
end
|
||||
end
|
||||
end
|
301
test/soap/marshal/test_marshal.rb
Normal file
301
test/soap/marshal/test_marshal.rb
Normal file
|
@ -0,0 +1,301 @@
|
|||
require 'test/unit'
|
||||
|
||||
dir = File.dirname(__FILE__)
|
||||
$:.push(dir)
|
||||
require 'cmarshal'
|
||||
$:.delete(dir)
|
||||
|
||||
CMarshal.soap4r
|
||||
|
||||
|
||||
module MarshalTestLib
|
||||
def encode(o)
|
||||
#self.class::MarshalClass.dump(o)
|
||||
CMarshal.dump(o)
|
||||
end
|
||||
|
||||
def decode(s)
|
||||
#self.class::MarshalClass.load(s)
|
||||
CMarshal.load(s)
|
||||
end
|
||||
|
||||
def marshaltest(o1)
|
||||
#o1.instance_eval { remove_instance_variable '@v' if defined? @v }
|
||||
str = encode(o1)
|
||||
print str, "\n" if $DEBUG
|
||||
o2 = decode(str)
|
||||
o2
|
||||
end
|
||||
|
||||
def marshal_equal(o1)
|
||||
o2 = marshaltest(o1)
|
||||
assert_equal(o1.class, o2.class, caller[0])
|
||||
iv1 = o1.instance_variables.sort
|
||||
iv2 = o2.instance_variables.sort
|
||||
assert_equal(iv1, iv2)
|
||||
val1 = iv1.map {|var| o1.instance_eval {eval var}}
|
||||
val2 = iv1.map {|var| o2.instance_eval {eval var}}
|
||||
assert_equal(val1, val2, caller[0])
|
||||
if block_given?
|
||||
assert_equal(yield(o1), yield(o2), caller[0])
|
||||
else
|
||||
assert_equal(o1, o2, caller[0])
|
||||
end
|
||||
end
|
||||
|
||||
class MyObject; def initialize(v) @v = v end; attr_reader :v; end
|
||||
def test_object
|
||||
o1 = Object.new
|
||||
o1.instance_eval { @iv = 1 }
|
||||
marshal_equal(o1) {|o| o.instance_eval { @iv }}
|
||||
end
|
||||
|
||||
def test_object_subclass
|
||||
marshal_equal(MyObject.new(2)) {|o| o.v}
|
||||
end
|
||||
|
||||
class MyArray < Array; def initialize(v, *args) super args; @v = v; end end
|
||||
def test_array
|
||||
marshal_equal([1,2,3])
|
||||
end
|
||||
|
||||
def test_array_subclass
|
||||
marshal_equal(MyArray.new(0, 1,2,3))
|
||||
end
|
||||
|
||||
class MyException < Exception; def initialize(v, *args) super(*args); @v = v; end; attr_reader :v; end
|
||||
def test_exception
|
||||
marshal_equal(Exception.new('foo')) {|o| o.message}
|
||||
end
|
||||
|
||||
def test_exception_subclass
|
||||
marshal_equal(MyException.new(20, "bar")) {|o| [o.message, o.v]}
|
||||
end
|
||||
|
||||
def test_false
|
||||
marshal_equal(false)
|
||||
end
|
||||
|
||||
class MyHash < Hash; def initialize(v, *args) super(*args); @v = v; end end
|
||||
def test_hash
|
||||
marshal_equal({1=>2, 3=>4})
|
||||
end
|
||||
|
||||
def test_hash_default
|
||||
h = Hash.new(:default)
|
||||
h[5] = 6
|
||||
marshal_equal(h)
|
||||
end
|
||||
|
||||
def test_hash_subclass
|
||||
h = MyHash.new(7, 8)
|
||||
h[4] = 5
|
||||
marshal_equal(h)
|
||||
end
|
||||
|
||||
def test_hash_default_proc
|
||||
h = Hash.new {}
|
||||
assert_raises(TypeError) { marshaltest(h) }
|
||||
end
|
||||
|
||||
def test_bignum
|
||||
marshal_equal(-0x4000_0000_0000_0001)
|
||||
marshal_equal(-0x4000_0001)
|
||||
marshal_equal(0x4000_0000)
|
||||
marshal_equal(0x4000_0000_0000_0000)
|
||||
end
|
||||
|
||||
def test_fixnum
|
||||
marshal_equal(-0x4000_0000)
|
||||
marshal_equal(-1)
|
||||
marshal_equal(0)
|
||||
marshal_equal(1)
|
||||
marshal_equal(0x3fff_ffff)
|
||||
end
|
||||
|
||||
def test_float
|
||||
marshal_equal(-1.0)
|
||||
marshal_equal(0.0)
|
||||
marshal_equal(1.0)
|
||||
end
|
||||
|
||||
def test_float_inf_nan
|
||||
marshal_equal(1.0/0.0)
|
||||
marshal_equal(-1.0/0.0)
|
||||
marshal_equal(0.0/0.0) {|o| o.nan?}
|
||||
marshal_equal(-0.0) {|o| 1.0/o}
|
||||
end
|
||||
|
||||
class MyRange < Range; def initialize(v, *args) super(*args); @v = v; end end
|
||||
def test_range
|
||||
marshal_equal(1..2)
|
||||
marshal_equal(1...3)
|
||||
end
|
||||
|
||||
def test_range_subclass
|
||||
STDERR.puts("test_range_subclass: known bug should be fixed.")
|
||||
return
|
||||
marshal_equal(MyRange.new(4,5,8, false))
|
||||
end
|
||||
|
||||
class MyRegexp < Regexp; def initialize(v, *args) super(*args); @v = v; end end
|
||||
def test_regexp
|
||||
marshal_equal(/a/)
|
||||
end
|
||||
|
||||
def test_regexp_subclass
|
||||
STDERR.puts("test_regexp_subclass: known bug should be fixed.")
|
||||
return
|
||||
marshal_equal(MyRegexp.new(10, "a"))
|
||||
end
|
||||
|
||||
class MyString < String; def initialize(v, *args) super(*args); @v = v; end end
|
||||
def test_string
|
||||
marshal_equal("abc")
|
||||
end
|
||||
|
||||
def test_string_subclass
|
||||
marshal_equal(MyString.new(10, "a"))
|
||||
end
|
||||
|
||||
MyStruct = Struct.new("MyStruct", :a, :b)
|
||||
class MySubStruct < MyStruct; def initialize(v, *args) super(*args); @v = v; end end
|
||||
def test_struct
|
||||
marshal_equal(MyStruct.new(1,2))
|
||||
end
|
||||
|
||||
def test_struct_subclass
|
||||
marshal_equal(MySubStruct.new(10,1,2))
|
||||
end
|
||||
|
||||
def test_symbol
|
||||
marshal_equal(:a)
|
||||
marshal_equal(:a?)
|
||||
marshal_equal(:a!)
|
||||
marshal_equal(:a=)
|
||||
marshal_equal(:|)
|
||||
marshal_equal(:^)
|
||||
marshal_equal(:&)
|
||||
marshal_equal(:<=>)
|
||||
marshal_equal(:==)
|
||||
marshal_equal(:===)
|
||||
marshal_equal(:=~)
|
||||
marshal_equal(:>)
|
||||
marshal_equal(:>=)
|
||||
marshal_equal(:<)
|
||||
marshal_equal(:<=)
|
||||
marshal_equal(:<<)
|
||||
marshal_equal(:>>)
|
||||
marshal_equal(:+)
|
||||
marshal_equal(:-)
|
||||
marshal_equal(:*)
|
||||
marshal_equal(:/)
|
||||
marshal_equal(:%)
|
||||
marshal_equal(:**)
|
||||
marshal_equal(:~)
|
||||
marshal_equal(:+@)
|
||||
marshal_equal(:-@)
|
||||
marshal_equal(:[])
|
||||
marshal_equal(:[]=)
|
||||
marshal_equal(:`) #`
|
||||
marshal_equal("a b".intern)
|
||||
end
|
||||
|
||||
class MyTime < Time; def initialize(v, *args) super(*args); @v = v; end end
|
||||
def test_time
|
||||
marshal_equal(Time.now)
|
||||
end
|
||||
|
||||
def test_time_subclass
|
||||
STDERR.puts("test_time_subclass: known bug should be fixed.")
|
||||
return
|
||||
marshal_equal(MyTime.new(10))
|
||||
end
|
||||
|
||||
def test_true
|
||||
marshal_equal(true)
|
||||
end
|
||||
|
||||
def test_nil
|
||||
marshal_equal(nil)
|
||||
end
|
||||
|
||||
def test_share
|
||||
o = [:share]
|
||||
o1 = [o, o]
|
||||
o2 = marshaltest(o1)
|
||||
assert_same(o2.first, o2.last)
|
||||
end
|
||||
|
||||
class CyclicRange < Range
|
||||
def <=>(other); true; end
|
||||
end
|
||||
def test_range_cyclic
|
||||
o1 = CyclicRange.allocate
|
||||
o1.instance_eval { initialize(o1, o1) }
|
||||
o2 = marshaltest(o1)
|
||||
assert_same(o2, o2.begin)
|
||||
assert_same(o2, o2.end)
|
||||
end
|
||||
|
||||
def test_singleton
|
||||
o = Object.new
|
||||
def o.m() end
|
||||
assert_raises(TypeError) { marshaltest(o) }
|
||||
o = Object.new
|
||||
class << o
|
||||
@v = 1
|
||||
end
|
||||
assert_raises(TypeError) { marshaltest(o) }
|
||||
assert_raises(TypeError) { marshaltest(ARGF) }
|
||||
assert_raises(TypeError) { marshaltest(ENV) }
|
||||
end
|
||||
|
||||
module Mod1 end
|
||||
module Mod2 end
|
||||
def test_extend
|
||||
o = Object.new
|
||||
o.extend Module.new
|
||||
assert_raises(TypeError) { marshaltest(o) }
|
||||
|
||||
STDERR.puts("test_range_subclass: known bug should be fixed.")
|
||||
return
|
||||
o = Object.new
|
||||
o.extend Mod1
|
||||
marshal_equal(o) { |obj| obj.kind_of? Mod1 }
|
||||
o = Object.new
|
||||
o.extend Mod1
|
||||
o.extend Mod2
|
||||
marshal_equal(o) {|obj| class << obj; ancestors end}
|
||||
end
|
||||
|
||||
def test_anonymous
|
||||
c = Class.new
|
||||
assert_raises(TypeError) { marshaltest(c) }
|
||||
o = c.new
|
||||
assert_raises(TypeError) { marshaltest(o) }
|
||||
m = Module.new
|
||||
assert_raises(TypeError) { marshaltest(m) }
|
||||
end
|
||||
|
||||
def test_string_empty
|
||||
marshal_equal("")
|
||||
end
|
||||
|
||||
def test_string_crlf
|
||||
marshal_equal("\r\n")
|
||||
end
|
||||
|
||||
def test_string_escape
|
||||
marshal_equal("\0<;;>\1;;")
|
||||
end
|
||||
|
||||
MyStruct2 = Struct.new(:a, :b)
|
||||
def test_struct_toplevel
|
||||
marshal_equal(MyStruct2.new(1,2))
|
||||
end
|
||||
end
|
||||
|
||||
class TestMarshal < Test::Unit::TestCase
|
||||
include MarshalTestLib
|
||||
end
|
38
test/soap/marshal/test_struct.rb
Normal file
38
test/soap/marshal/test_struct.rb
Normal file
|
@ -0,0 +1,38 @@
|
|||
require 'test/unit'
|
||||
require 'soap/marshal'
|
||||
|
||||
Foo1 = Struct.new("Foo1", :m)
|
||||
Foo2 = Struct.new(:m)
|
||||
class Foo3
|
||||
attr_accessor :m
|
||||
end
|
||||
|
||||
class TestStruct < Test::Unit::TestCase
|
||||
def test_foo1
|
||||
org = Foo1.new
|
||||
org.m = org
|
||||
obj = convert(org)
|
||||
assert_equal(Foo1, obj.class)
|
||||
assert_equal(obj.m, obj)
|
||||
end
|
||||
|
||||
def test_foo2
|
||||
org = Foo2.new
|
||||
org.m = org
|
||||
obj = convert(org)
|
||||
assert_equal(Foo2, obj.class)
|
||||
assert_equal(obj.m, obj)
|
||||
end
|
||||
|
||||
def test_foo3
|
||||
org = Foo3.new
|
||||
org.m = org
|
||||
obj = convert(org)
|
||||
assert_equal(Foo3, obj.class)
|
||||
assert_equal(obj.m, obj)
|
||||
end
|
||||
|
||||
def convert(obj)
|
||||
SOAP::Marshal.unmarshal(SOAP::Marshal.marshal(obj))
|
||||
end
|
||||
end
|
951
test/soap/test_basetype.rb
Normal file
951
test/soap/test_basetype.rb
Normal file
|
@ -0,0 +1,951 @@
|
|||
require 'test/unit'
|
||||
require 'soap/baseData'
|
||||
|
||||
class TestSOAP < Test::Unit::TestCase
|
||||
def setup
|
||||
# Nothing to do.
|
||||
end
|
||||
|
||||
def teardown
|
||||
# Nothing to do.
|
||||
end
|
||||
|
||||
def assert_parsed_result(klass, str)
|
||||
o = klass.new(str)
|
||||
assert_equal(str, o.to_s)
|
||||
end
|
||||
|
||||
def test_SOAPNil
|
||||
o = SOAP::SOAPNil.new
|
||||
assert_equal(XSD::Namespace, o.type.namespace)
|
||||
assert_equal(XSD::NilLiteral, o.type.name)
|
||||
assert_equal(nil, o.data)
|
||||
assert_equal(true, o.is_nil)
|
||||
|
||||
o = SOAP::SOAPNil.new(nil)
|
||||
assert_equal(true, o.is_nil)
|
||||
assert_equal(nil, o.data)
|
||||
assert_equal("", o.to_s)
|
||||
o = SOAP::SOAPNil.new('var')
|
||||
assert_equal(false, o.is_nil)
|
||||
assert_equal('var', o.data)
|
||||
assert_equal('var', o.to_s)
|
||||
end
|
||||
|
||||
def test_SOAPString
|
||||
o = SOAP::SOAPString.new
|
||||
assert_equal(XSD::Namespace, o.type.namespace)
|
||||
assert_equal(XSD::StringLiteral, o.type.name)
|
||||
assert_equal(nil, o.data)
|
||||
assert_equal(true, o.is_nil)
|
||||
|
||||
str = "abc"
|
||||
assert_equal(str, SOAP::SOAPString.new(str).data)
|
||||
assert_equal(str, SOAP::SOAPString.new(str).to_s)
|
||||
assert_raises(XSD::ValueSpaceError) do
|
||||
SOAP::SOAPString.new("\0")
|
||||
end
|
||||
assert_raises(XSD::ValueSpaceError) do
|
||||
p SOAP::SOAPString.new("\xC0\xC0").to_s
|
||||
end
|
||||
end
|
||||
|
||||
def test_SOAPBoolean
|
||||
o = SOAP::SOAPBoolean.new
|
||||
assert_equal(XSD::Namespace, o.type.namespace)
|
||||
assert_equal(XSD::BooleanLiteral, o.type.name)
|
||||
assert_equal(nil, o.data)
|
||||
assert_equal(true, o.is_nil)
|
||||
|
||||
targets = [
|
||||
["true", true],
|
||||
["1", true],
|
||||
["false", false],
|
||||
["0", false],
|
||||
]
|
||||
targets.each do |data, expected|
|
||||
assert_equal(expected, SOAP::SOAPBoolean.new(data).data)
|
||||
assert_equal(expected.to_s, SOAP::SOAPBoolean.new(data).to_s)
|
||||
end
|
||||
|
||||
assert_raises(XSD::ValueSpaceError) do
|
||||
SOAP::SOAPBoolean.new("nil").to_s
|
||||
end
|
||||
end
|
||||
|
||||
def test_SOAPDecimal
|
||||
o = SOAP::SOAPDecimal.new
|
||||
assert_equal(XSD::Namespace, o.type.namespace)
|
||||
assert_equal(XSD::DecimalLiteral, o.type.name)
|
||||
assert_equal(nil, o.data)
|
||||
assert_equal(true, o.is_nil)
|
||||
|
||||
targets = [
|
||||
0,
|
||||
1000000000,
|
||||
-9999999999,
|
||||
12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890,
|
||||
12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890,
|
||||
-1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789,
|
||||
]
|
||||
targets.each do |dec|
|
||||
assert_equal(dec.to_s, SOAP::SOAPDecimal.new(dec).data)
|
||||
end
|
||||
|
||||
targets = [
|
||||
"0",
|
||||
"0.00000001",
|
||||
"1000000000",
|
||||
"12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890",
|
||||
"-12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123.45678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789",
|
||||
]
|
||||
targets.each do |str|
|
||||
assert_equal(str, SOAP::SOAPDecimal.new(str).to_s)
|
||||
end
|
||||
|
||||
targets = [
|
||||
["-0", "0"],
|
||||
["+0", "0"],
|
||||
["0.0", "0"],
|
||||
["-0.0", "0"],
|
||||
["+0.0", "0"],
|
||||
["0.", "0"],
|
||||
[".0", "0"],
|
||||
[
|
||||
"+0.12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890",
|
||||
"0.1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"
|
||||
],
|
||||
[
|
||||
".0000012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890",
|
||||
"0.000001234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"
|
||||
],
|
||||
[
|
||||
"-12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890.",
|
||||
"-12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
|
||||
],
|
||||
]
|
||||
targets.each do |data, expected|
|
||||
assert_equal(expected, SOAP::SOAPDecimal.new(data).to_s)
|
||||
end
|
||||
|
||||
targets = [
|
||||
"0.000000000000a",
|
||||
"00a.0000000000001",
|
||||
"+-5",
|
||||
]
|
||||
targets.each do |d|
|
||||
assert_raises(XSD::ValueSpaceError) do
|
||||
SOAP::SOAPDecimal.new(d)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_SOAPFloat
|
||||
o = SOAP::SOAPFloat.new
|
||||
assert_equal(XSD::Namespace, o.type.namespace)
|
||||
assert_equal(XSD::FloatLiteral, o.type.name)
|
||||
assert_equal(nil, o.data)
|
||||
assert_equal(true, o.is_nil)
|
||||
|
||||
targets = [
|
||||
3.14159265358979,
|
||||
12.34e36,
|
||||
1.4e-45,
|
||||
-1.4e-45,
|
||||
]
|
||||
targets.each do |f|
|
||||
assert_equal(f, SOAP::SOAPFloat.new(f).data)
|
||||
end
|
||||
|
||||
targets = [
|
||||
"3.141592654",
|
||||
"1.234e+37",
|
||||
"1.4e-45",
|
||||
"-1.4e-45",
|
||||
]
|
||||
targets.each do |f|
|
||||
assert_equal(f, SOAP::SOAPFloat.new(f).to_s)
|
||||
end
|
||||
|
||||
targets = [
|
||||
[3, "3"], # should be 3.0?
|
||||
[-2, "-2"], # ditto
|
||||
[3.14159265358979, "3.141592654"],
|
||||
[12.34e36, "1.234e+37"],
|
||||
[1.4e-45, "1.4e-45"],
|
||||
[-1.4e-45, "-1.4e-45"],
|
||||
["1.4e", "1.4"],
|
||||
["12.34E36", "1.234e+37"],
|
||||
["1.4E-45", "1.4e-45"],
|
||||
["-1.4E-45", "-1.4e-45"],
|
||||
["1.4E", "1.4"],
|
||||
]
|
||||
targets.each do |f, str|
|
||||
assert_equal(str, SOAP::SOAPFloat.new(f).to_s)
|
||||
end
|
||||
|
||||
assert_equal("0", SOAP::SOAPFloat.new(+0.0).to_s)
|
||||
assert_equal("-0", SOAP::SOAPFloat.new(-0.0).to_s)
|
||||
assert(SOAP::SOAPFloat.new(0.0/0.0).data.nan?)
|
||||
assert_equal("INF", SOAP::SOAPFloat.new(1.0/0.0).to_s)
|
||||
assert_equal(1, SOAP::SOAPFloat.new(1.0/0.0).data.infinite?)
|
||||
assert_equal("-INF", SOAP::SOAPFloat.new(-1.0/0.0).to_s)
|
||||
assert_equal(-1, SOAP::SOAPFloat.new(-1.0/0.0).data.infinite?)
|
||||
|
||||
targets = [
|
||||
"0.000000000000a",
|
||||
"00a.0000000000001",
|
||||
"+-5",
|
||||
"5_0",
|
||||
]
|
||||
targets.each do |d|
|
||||
assert_raises(XSD::ValueSpaceError) do
|
||||
SOAP::SOAPFloat.new(d)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_SOAPDouble
|
||||
o = SOAP::SOAPDouble.new
|
||||
assert_equal(XSD::Namespace, o.type.namespace)
|
||||
assert_equal(XSD::DoubleLiteral, o.type.name)
|
||||
assert_equal(nil, o.data)
|
||||
assert_equal(true, o.is_nil)
|
||||
|
||||
targets = [
|
||||
3.14159265358979,
|
||||
12.34e36,
|
||||
1.4e-45,
|
||||
-1.4e-45,
|
||||
]
|
||||
targets.each do |f|
|
||||
assert_equal(f, SOAP::SOAPDouble.new(f).data)
|
||||
end
|
||||
|
||||
targets = [
|
||||
"3.14159265358979",
|
||||
"1.234e+37",
|
||||
"1.4e-45",
|
||||
"-1.4e-45",
|
||||
]
|
||||
targets.each do |f|
|
||||
assert_equal(f, SOAP::SOAPDouble.new(f).to_s)
|
||||
end
|
||||
|
||||
targets = [
|
||||
[3, "3"], # should be 3.0?
|
||||
[-2, "-2"], # ditto.
|
||||
[3.14159265358979, "3.14159265358979"],
|
||||
[12.34e36, "1.234e+37"],
|
||||
[1.4e-45, "1.4e-45"],
|
||||
[-1.4e-45, "-1.4e-45"],
|
||||
["1.4e", "1.4"],
|
||||
["12.34E36", "1.234e+37"],
|
||||
["1.4E-45", "1.4e-45"],
|
||||
["-1.4E-45", "-1.4e-45"],
|
||||
["1.4E", "1.4"],
|
||||
]
|
||||
targets.each do |f, str|
|
||||
assert_equal(str, SOAP::SOAPDouble.new(f).to_s)
|
||||
end
|
||||
|
||||
assert_equal("0", SOAP::SOAPFloat.new(+0.0).to_s)
|
||||
assert_equal("-0", SOAP::SOAPFloat.new(-0.0).to_s)
|
||||
assert_equal("NaN", SOAP::SOAPDouble.new(0.0/0.0).to_s)
|
||||
assert(SOAP::SOAPDouble.new(0.0/0.0).data.nan?)
|
||||
assert_equal("INF", SOAP::SOAPDouble.new(1.0/0.0).to_s)
|
||||
assert_equal(1, SOAP::SOAPDouble.new(1.0/0.0).data.infinite?)
|
||||
assert_equal("-INF", SOAP::SOAPDouble.new(-1.0/0.0).to_s)
|
||||
assert_equal(-1, SOAP::SOAPDouble.new(-1.0/0.0).data.infinite?)
|
||||
|
||||
targets = [
|
||||
"0.000000000000a",
|
||||
"00a.0000000000001",
|
||||
"+-5",
|
||||
]
|
||||
targets.each do |d|
|
||||
assert_raises(XSD::ValueSpaceError) do
|
||||
SOAP::SOAPDouble.new(d)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_SOAPDuration
|
||||
o = SOAP::SOAPDuration.new
|
||||
assert_equal(XSD::Namespace, o.type.namespace)
|
||||
assert_equal(XSD::DurationLiteral, o.type.name)
|
||||
assert_equal(nil, o.data)
|
||||
assert_equal(true, o.is_nil)
|
||||
|
||||
targets = [
|
||||
"P1Y2M3DT4H5M6S",
|
||||
"P1234Y5678M9012DT3456H7890M1234.5678S",
|
||||
"P0DT3456H7890M1234.5678S",
|
||||
"P1234Y5678M9012D",
|
||||
"-P1234Y5678M9012DT3456H7890M1234.5678S",
|
||||
"P5678M9012DT3456H7890M1234.5678S",
|
||||
"-P1234Y9012DT3456H7890M1234.5678S",
|
||||
"+P1234Y5678MT3456H7890M1234.5678S",
|
||||
"P1234Y5678M9012DT7890M1234.5678S",
|
||||
"-P1234Y5678M9012DT3456H1234.5678S",
|
||||
"+P1234Y5678M9012DT3456H7890M",
|
||||
"P123400000000000Y",
|
||||
"-P567800000000000M",
|
||||
"+P901200000000000D",
|
||||
"P0DT345600000000000H",
|
||||
"-P0DT789000000000000M",
|
||||
"+P0DT123400000000000.000000000005678S",
|
||||
"P1234YT1234.5678S",
|
||||
"-P5678MT7890M",
|
||||
"+P9012DT3456H",
|
||||
]
|
||||
targets.each do |str|
|
||||
assert_parsed_result(SOAP::SOAPDuration, str)
|
||||
end
|
||||
|
||||
targets = [
|
||||
["P0Y0M0DT0H0M0S",
|
||||
"P0D"],
|
||||
["-P0DT0S",
|
||||
"-P0D"],
|
||||
["P01234Y5678M9012DT3456H7890M1234.5678S",
|
||||
"P1234Y5678M9012DT3456H7890M1234.5678S"],
|
||||
["P1234Y005678M9012DT3456H7890M1234.5678S",
|
||||
"P1234Y5678M9012DT3456H7890M1234.5678S"],
|
||||
["P1234Y5678M0009012DT3456H7890M1234.5678S",
|
||||
"P1234Y5678M9012DT3456H7890M1234.5678S"],
|
||||
["P1234Y5678M9012DT00003456H7890M1234.5678S",
|
||||
"P1234Y5678M9012DT3456H7890M1234.5678S"],
|
||||
["P1234Y5678M9012DT3456H000007890M1234.5678S",
|
||||
"P1234Y5678M9012DT3456H7890M1234.5678S"],
|
||||
["P1234Y5678M9012DT3456H7890M0000001234.5678S",
|
||||
"P1234Y5678M9012DT3456H7890M1234.5678S"],
|
||||
]
|
||||
targets.each do |data, expected|
|
||||
assert_equal(expected, SOAP::SOAPDuration.new(data).to_s)
|
||||
end
|
||||
end
|
||||
|
||||
def test_SOAPDateTime
|
||||
o = SOAP::SOAPDateTime.new
|
||||
assert_equal(XSD::Namespace, o.type.namespace)
|
||||
assert_equal(XSD::DateTimeLiteral, o.type.name)
|
||||
assert_equal(nil, o.data)
|
||||
assert_equal(true, o.is_nil)
|
||||
|
||||
targets = [
|
||||
"2002-05-18T16:52:20Z",
|
||||
"0001-01-01T00:00:00Z",
|
||||
"9999-12-31T23:59:59Z",
|
||||
"19999-12-31T23:59:59Z",
|
||||
"2002-12-31T23:59:59.999Z",
|
||||
"2002-12-31T23:59:59.001Z",
|
||||
"2002-12-31T23:59:59.99999999999999999999Z",
|
||||
"2002-12-31T23:59:59.00000000000000000001Z",
|
||||
"2002-12-31T23:59:59+09:00",
|
||||
"2002-12-31T23:59:59+00:01",
|
||||
"2002-12-31T23:59:59-00:01",
|
||||
"2002-12-31T23:59:59-23:59",
|
||||
"2002-12-31T23:59:59.00000000000000000001+13:30",
|
||||
"-2002-05-18T16:52:20Z",
|
||||
"-4711-12-31T23:59:59Z",
|
||||
"-4713-01-01T12:00:00Z",
|
||||
"-19999-12-31T23:59:59Z",
|
||||
"-2002-12-31T23:59:59+00:01",
|
||||
"-0001-12-31T23:59:59.00000000000000000001+13:30",
|
||||
]
|
||||
targets.each do |str|
|
||||
assert_parsed_result(SOAP::SOAPDateTime, str)
|
||||
end
|
||||
|
||||
targets = [
|
||||
["2002-12-31T23:59:59.00",
|
||||
"2002-12-31T23:59:59Z"],
|
||||
["2002-12-31T23:59:59+00:00",
|
||||
"2002-12-31T23:59:59Z"],
|
||||
["2002-12-31T23:59:59-00:00",
|
||||
"2002-12-31T23:59:59Z"],
|
||||
["-2002-12-31T23:59:59.00",
|
||||
"-2002-12-31T23:59:59Z"],
|
||||
["-2002-12-31T23:59:59+00:00",
|
||||
"-2002-12-31T23:59:59Z"],
|
||||
["-2002-12-31T23:59:59-00:00",
|
||||
"-2002-12-31T23:59:59Z"],
|
||||
]
|
||||
targets.each do |data, expected|
|
||||
assert_equal(expected, SOAP::SOAPDateTime.new(data).to_s)
|
||||
end
|
||||
|
||||
targets = [
|
||||
"1-05-18T16:52:20Z",
|
||||
"05-18T16:52:20Z",
|
||||
"2002-05T16:52:20Z",
|
||||
"2002-05-18T16:52Z",
|
||||
"",
|
||||
]
|
||||
targets.each do |d|
|
||||
assert_raises(XSD::ValueSpaceError, d.to_s) do
|
||||
SOAP::SOAPDateTime.new(d)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_SOAPTime
|
||||
o = SOAP::SOAPTime.new
|
||||
assert_equal(XSD::Namespace, o.type.namespace)
|
||||
assert_equal(XSD::TimeLiteral, o.type.name)
|
||||
assert_equal(nil, o.data)
|
||||
assert_equal(true, o.is_nil)
|
||||
|
||||
targets = [
|
||||
"16:52:20Z",
|
||||
"00:00:00Z",
|
||||
"23:59:59Z",
|
||||
"23:59:59.999Z",
|
||||
"23:59:59.001Z",
|
||||
"23:59:59.99999999999999999999Z",
|
||||
"23:59:59.00000000000000000001Z",
|
||||
"23:59:59+09:00",
|
||||
"23:59:59+00:01",
|
||||
"23:59:59-00:01",
|
||||
"23:59:59-23:59",
|
||||
"23:59:59.00000000000000000001+13:30",
|
||||
"23:59:59+00:01",
|
||||
]
|
||||
targets.each do |str|
|
||||
assert_parsed_result(SOAP::SOAPTime, str)
|
||||
end
|
||||
|
||||
targets = [
|
||||
["23:59:59.00",
|
||||
"23:59:59Z"],
|
||||
["23:59:59+00:00",
|
||||
"23:59:59Z"],
|
||||
["23:59:59-00:00",
|
||||
"23:59:59Z"],
|
||||
]
|
||||
targets.each do |data, expected|
|
||||
assert_equal(expected, SOAP::SOAPTime.new(data).to_s)
|
||||
end
|
||||
end
|
||||
|
||||
def test_SOAPDate
|
||||
o = SOAP::SOAPDate.new
|
||||
assert_equal(XSD::Namespace, o.type.namespace)
|
||||
assert_equal(XSD::DateLiteral, o.type.name)
|
||||
assert_equal(nil, o.data)
|
||||
assert_equal(true, o.is_nil)
|
||||
|
||||
targets = [
|
||||
"2002-05-18Z",
|
||||
"0001-01-01Z",
|
||||
"9999-12-31Z",
|
||||
"19999-12-31Z",
|
||||
"2002-12-31+09:00",
|
||||
"2002-12-31+00:01",
|
||||
"2002-12-31-00:01",
|
||||
"2002-12-31-23:59",
|
||||
"2002-12-31+13:30",
|
||||
"-2002-05-18Z",
|
||||
"-19999-12-31Z",
|
||||
"-2002-12-31+00:01",
|
||||
"-0001-12-31+13:30",
|
||||
]
|
||||
targets.each do |str|
|
||||
assert_parsed_result(SOAP::SOAPDate, str)
|
||||
end
|
||||
|
||||
targets = [
|
||||
["2002-12-31",
|
||||
"2002-12-31Z"],
|
||||
["2002-12-31+00:00",
|
||||
"2002-12-31Z"],
|
||||
["2002-12-31-00:00",
|
||||
"2002-12-31Z"],
|
||||
["-2002-12-31",
|
||||
"-2002-12-31Z"],
|
||||
["-2002-12-31+00:00",
|
||||
"-2002-12-31Z"],
|
||||
["-2002-12-31-00:00",
|
||||
"-2002-12-31Z"],
|
||||
]
|
||||
targets.each do |data, expected|
|
||||
assert_equal(expected, SOAP::SOAPDate.new(data).to_s)
|
||||
end
|
||||
end
|
||||
|
||||
def test_SOAPGYearMonth
|
||||
o = SOAP::SOAPGYearMonth.new
|
||||
assert_equal(XSD::Namespace, o.type.namespace)
|
||||
assert_equal(XSD::GYearMonthLiteral, o.type.name)
|
||||
assert_equal(nil, o.data)
|
||||
assert_equal(true, o.is_nil)
|
||||
|
||||
targets = [
|
||||
"2002-05Z",
|
||||
"0001-01Z",
|
||||
"9999-12Z",
|
||||
"19999-12Z",
|
||||
"2002-12+09:00",
|
||||
"2002-12+00:01",
|
||||
"2002-12-00:01",
|
||||
"2002-12-23:59",
|
||||
"2002-12+13:30",
|
||||
"-2002-05Z",
|
||||
"-19999-12Z",
|
||||
"-2002-12+00:01",
|
||||
"-0001-12+13:30",
|
||||
]
|
||||
targets.each do |str|
|
||||
assert_parsed_result(SOAP::SOAPGYearMonth, str)
|
||||
end
|
||||
|
||||
targets = [
|
||||
["2002-12",
|
||||
"2002-12Z"],
|
||||
["2002-12+00:00",
|
||||
"2002-12Z"],
|
||||
["2002-12-00:00",
|
||||
"2002-12Z"],
|
||||
["-2002-12",
|
||||
"-2002-12Z"],
|
||||
["-2002-12+00:00",
|
||||
"-2002-12Z"],
|
||||
["-2002-12-00:00",
|
||||
"-2002-12Z"],
|
||||
]
|
||||
targets.each do |data, expected|
|
||||
assert_equal(expected, SOAP::SOAPGYearMonth.new(data).to_s)
|
||||
end
|
||||
end
|
||||
|
||||
def test_SOAPGYear
|
||||
o = SOAP::SOAPGYear.new
|
||||
assert_equal(XSD::Namespace, o.type.namespace)
|
||||
assert_equal(XSD::GYearLiteral, o.type.name)
|
||||
assert_equal(nil, o.data)
|
||||
assert_equal(true, o.is_nil)
|
||||
|
||||
targets = [
|
||||
"2002Z",
|
||||
"0001Z",
|
||||
"9999Z",
|
||||
"19999Z",
|
||||
"2002+09:00",
|
||||
"2002+00:01",
|
||||
"2002-00:01",
|
||||
"2002-23:59",
|
||||
"2002+13:30",
|
||||
"-2002Z",
|
||||
"-19999Z",
|
||||
"-2002+00:01",
|
||||
"-0001+13:30",
|
||||
]
|
||||
targets.each do |str|
|
||||
assert_parsed_result(SOAP::SOAPGYear, str)
|
||||
end
|
||||
|
||||
targets = [
|
||||
["2002",
|
||||
"2002Z"],
|
||||
["2002+00:00",
|
||||
"2002Z"],
|
||||
["2002-00:00",
|
||||
"2002Z"],
|
||||
["-2002",
|
||||
"-2002Z"],
|
||||
["-2002+00:00",
|
||||
"-2002Z"],
|
||||
["-2002-00:00",
|
||||
"-2002Z"],
|
||||
]
|
||||
targets.each do |data, expected|
|
||||
assert_equal(expected, SOAP::SOAPGYear.new(data).to_s)
|
||||
end
|
||||
end
|
||||
|
||||
def test_SOAPGMonthDay
|
||||
o = SOAP::SOAPGMonthDay.new
|
||||
assert_equal(XSD::Namespace, o.type.namespace)
|
||||
assert_equal(XSD::GMonthDayLiteral, o.type.name)
|
||||
assert_equal(nil, o.data)
|
||||
assert_equal(true, o.is_nil)
|
||||
|
||||
targets = [
|
||||
"05-18Z",
|
||||
"01-01Z",
|
||||
"12-31Z",
|
||||
"12-31+09:00",
|
||||
"12-31+00:01",
|
||||
"12-31-00:01",
|
||||
"12-31-23:59",
|
||||
"12-31+13:30",
|
||||
]
|
||||
targets.each do |str|
|
||||
assert_parsed_result(SOAP::SOAPGMonthDay, str)
|
||||
end
|
||||
|
||||
targets = [
|
||||
["12-31",
|
||||
"12-31Z"],
|
||||
["12-31+00:00",
|
||||
"12-31Z"],
|
||||
["12-31-00:00",
|
||||
"12-31Z"],
|
||||
]
|
||||
targets.each do |data, expected|
|
||||
assert_equal(expected, SOAP::SOAPGMonthDay.new(data).to_s)
|
||||
end
|
||||
end
|
||||
|
||||
def test_SOAPGDay
|
||||
o = SOAP::SOAPGDay.new
|
||||
assert_equal(XSD::Namespace, o.type.namespace)
|
||||
assert_equal(XSD::GDayLiteral, o.type.name)
|
||||
assert_equal(nil, o.data)
|
||||
assert_equal(true, o.is_nil)
|
||||
|
||||
targets = [
|
||||
"18Z",
|
||||
"01Z",
|
||||
"31Z",
|
||||
"31+09:00",
|
||||
"31+00:01",
|
||||
"31-00:01",
|
||||
"31-23:59",
|
||||
"31+13:30",
|
||||
]
|
||||
targets.each do |str|
|
||||
assert_parsed_result(SOAP::SOAPGDay, str)
|
||||
end
|
||||
|
||||
targets = [
|
||||
["31",
|
||||
"31Z"],
|
||||
["31+00:00",
|
||||
"31Z"],
|
||||
["31-00:00",
|
||||
"31Z"],
|
||||
]
|
||||
targets.each do |data, expected|
|
||||
assert_equal(expected, SOAP::SOAPGDay.new(data).to_s)
|
||||
end
|
||||
end
|
||||
|
||||
def test_SOAPGMonth
|
||||
o = SOAP::SOAPGMonth.new
|
||||
assert_equal(XSD::Namespace, o.type.namespace)
|
||||
assert_equal(XSD::GMonthLiteral, o.type.name)
|
||||
assert_equal(nil, o.data)
|
||||
assert_equal(true, o.is_nil)
|
||||
|
||||
targets = [
|
||||
"05Z",
|
||||
"01Z",
|
||||
"12Z",
|
||||
"12+09:00",
|
||||
"12+00:01",
|
||||
"12-00:01",
|
||||
"12-23:59",
|
||||
"12+13:30",
|
||||
]
|
||||
targets.each do |str|
|
||||
assert_parsed_result(SOAP::SOAPGMonth, str)
|
||||
end
|
||||
|
||||
targets = [
|
||||
["12",
|
||||
"12Z"],
|
||||
["12+00:00",
|
||||
"12Z"],
|
||||
["12-00:00",
|
||||
"12Z"],
|
||||
]
|
||||
targets.each do |data, expected|
|
||||
assert_equal(expected, SOAP::SOAPGMonth.new(data).to_s)
|
||||
end
|
||||
end
|
||||
|
||||
def test_SOAPHexBinary
|
||||
o = SOAP::SOAPHexBinary.new
|
||||
assert_equal(XSD::Namespace, o.type.namespace)
|
||||
assert_equal(XSD::HexBinaryLiteral, o.type.name)
|
||||
assert_equal(nil, o.data)
|
||||
assert_equal(true, o.is_nil)
|
||||
|
||||
targets = [
|
||||
"abcdef",
|
||||
"\xe3\x81\xaa\xe3\x81\xb2",
|
||||
"\0",
|
||||
"",
|
||||
]
|
||||
targets.each do |str|
|
||||
assert_equal(str, SOAP::SOAPHexBinary.new(str).string)
|
||||
assert_equal(str.unpack("H*")[0].tr('a-f', 'A-F'),
|
||||
SOAP::SOAPHexBinary.new(str).data)
|
||||
o = SOAP::SOAPHexBinary.new
|
||||
o.set_encoded(str.unpack("H*")[0].tr('a-f', 'A-F'))
|
||||
assert_equal(str, o.string)
|
||||
o.set_encoded(str.unpack("H*")[0].tr('A-F', 'a-f'))
|
||||
assert_equal(str, o.string)
|
||||
end
|
||||
|
||||
targets = [
|
||||
"0FG7",
|
||||
"0fg7",
|
||||
]
|
||||
targets.each do |d|
|
||||
assert_raises(XSD::ValueSpaceError, d.to_s) do
|
||||
o = SOAP::SOAPHexBinary.new
|
||||
o.set_encoded(d)
|
||||
p o.string
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_SOAPBase64Binary
|
||||
o = SOAP::SOAPBase64.new
|
||||
assert_equal(SOAP::EncodingNamespace, o.type.namespace)
|
||||
assert_equal(SOAP::Base64Literal, o.type.name)
|
||||
assert_equal(nil, o.data)
|
||||
assert_equal(true, o.is_nil)
|
||||
|
||||
targets = [
|
||||
"abcdef",
|
||||
"\xe3\x81\xaa\xe3\x81\xb2",
|
||||
"\0",
|
||||
"",
|
||||
]
|
||||
targets.each do |str|
|
||||
assert_equal(str, SOAP::SOAPBase64.new(str).string)
|
||||
assert_equal([str].pack("m").chomp, SOAP::SOAPBase64.new(str).data)
|
||||
o = SOAP::SOAPBase64.new
|
||||
o.set_encoded([str].pack("m").chomp)
|
||||
assert_equal(str, o.string)
|
||||
end
|
||||
|
||||
targets = [
|
||||
"-",
|
||||
"*",
|
||||
]
|
||||
targets.each do |d|
|
||||
assert_raises(XSD::ValueSpaceError, d.to_s) do
|
||||
o = SOAP::SOAPBase64.new
|
||||
o.set_encoded(d)
|
||||
p o.string
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_SOAPAnyURI
|
||||
o = SOAP::SOAPAnyURI.new
|
||||
assert_equal(XSD::Namespace, o.type.namespace)
|
||||
assert_equal(XSD::AnyURILiteral, o.type.name)
|
||||
assert_equal(nil, o.data)
|
||||
assert_equal(true, o.is_nil)
|
||||
|
||||
# Too few tests here I know. Believe uri module. :)
|
||||
targets = [
|
||||
"foo",
|
||||
"http://foo",
|
||||
"http://foo/bar/baz",
|
||||
"http://foo/bar#baz",
|
||||
"http://foo/bar%20%20?a+b",
|
||||
"HTTP://FOO/BAR%20%20?A+B",
|
||||
]
|
||||
targets.each do |str|
|
||||
assert_parsed_result(SOAP::SOAPAnyURI, str)
|
||||
end
|
||||
end
|
||||
|
||||
def test_SOAPQName
|
||||
o = SOAP::SOAPQName.new
|
||||
assert_equal(XSD::Namespace, o.type.namespace)
|
||||
assert_equal(XSD::QNameLiteral, o.type.name)
|
||||
assert_equal(nil, o.data)
|
||||
assert_equal(true, o.is_nil)
|
||||
|
||||
# More strict test is needed but current implementation allows all non-':'
|
||||
# chars like ' ', C0 or C1...
|
||||
targets = [
|
||||
"foo",
|
||||
"foo:bar",
|
||||
"a:b",
|
||||
]
|
||||
targets.each do |str|
|
||||
assert_parsed_result(SOAP::SOAPQName, str)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
###
|
||||
## Derived types
|
||||
#
|
||||
|
||||
def test_SOAPInteger
|
||||
o = SOAP::SOAPInteger.new
|
||||
assert_equal(XSD::Namespace, o.type.namespace)
|
||||
assert_equal(XSD::IntegerLiteral, o.type.name)
|
||||
assert_equal(nil, o.data)
|
||||
assert_equal(true, o.is_nil)
|
||||
|
||||
targets = [
|
||||
0,
|
||||
1000000000,
|
||||
-9999999999,
|
||||
12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890,
|
||||
12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890,
|
||||
-1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789,
|
||||
]
|
||||
targets.each do |int|
|
||||
assert_equal(int, SOAP::SOAPInteger.new(int).data)
|
||||
end
|
||||
|
||||
targets = [
|
||||
"0",
|
||||
"1000000000",
|
||||
"-9999999999",
|
||||
"12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890",
|
||||
"12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890",
|
||||
"-1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789",
|
||||
]
|
||||
targets.each do |str|
|
||||
assert_equal(str, SOAP::SOAPInteger.new(str).to_s)
|
||||
end
|
||||
|
||||
targets = [
|
||||
["-0", "0"],
|
||||
["+0", "0"],
|
||||
["000123", "123"],
|
||||
["-000123", "-123"],
|
||||
[
|
||||
"+12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890",
|
||||
"12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
|
||||
],
|
||||
]
|
||||
targets.each do |data, expected|
|
||||
assert_equal(expected, SOAP::SOAPInteger.new(data).to_s)
|
||||
end
|
||||
|
||||
targets = [
|
||||
"0.0",
|
||||
"-5.2",
|
||||
"0.000000000000a",
|
||||
"+-5",
|
||||
"12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890."
|
||||
]
|
||||
targets.each do |d|
|
||||
assert_raises(XSD::ValueSpaceError) do
|
||||
SOAP::SOAPInteger.new(d)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_SOAPLong
|
||||
o = SOAP::SOAPLong.new
|
||||
assert_equal(XSD::Namespace, o.type.namespace)
|
||||
assert_equal(XSD::LongLiteral, o.type.name)
|
||||
assert_equal(nil, o.data)
|
||||
assert_equal(true, o.is_nil)
|
||||
|
||||
targets = [
|
||||
0,
|
||||
123,
|
||||
-123,
|
||||
9223372036854775807,
|
||||
-9223372036854775808,
|
||||
]
|
||||
targets.each do |lng|
|
||||
assert_equal(lng, SOAP::SOAPLong.new(lng).data)
|
||||
end
|
||||
|
||||
targets = [
|
||||
"0",
|
||||
"123",
|
||||
"-123",
|
||||
"9223372036854775807",
|
||||
"-9223372036854775808",
|
||||
]
|
||||
targets.each do |str|
|
||||
assert_equal(str, SOAP::SOAPLong.new(str).to_s)
|
||||
end
|
||||
|
||||
targets = [
|
||||
["-0", "0"],
|
||||
["+0", "0"],
|
||||
["000123", "123"],
|
||||
["-000123", "-123"],
|
||||
]
|
||||
targets.each do |data, expected|
|
||||
assert_equal(expected, SOAP::SOAPLong.new(data).to_s)
|
||||
end
|
||||
|
||||
targets = [
|
||||
9223372036854775808,
|
||||
-9223372036854775809,
|
||||
"0.0",
|
||||
"-5.2",
|
||||
"0.000000000000a",
|
||||
"+-5",
|
||||
]
|
||||
targets.each do |d|
|
||||
assert_raises(XSD::ValueSpaceError) do
|
||||
SOAP::SOAPLong.new(d)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_SOAPInt
|
||||
o = SOAP::SOAPInt.new
|
||||
assert_equal(XSD::Namespace, o.type.namespace)
|
||||
assert_equal(XSD::IntLiteral, o.type.name)
|
||||
assert_equal(nil, o.data)
|
||||
assert_equal(true, o.is_nil)
|
||||
|
||||
targets = [
|
||||
0,
|
||||
123,
|
||||
-123,
|
||||
2147483647,
|
||||
-2147483648,
|
||||
]
|
||||
targets.each do |lng|
|
||||
assert_equal(lng, SOAP::SOAPInt.new(lng).data)
|
||||
end
|
||||
|
||||
targets = [
|
||||
"0",
|
||||
"123",
|
||||
"-123",
|
||||
"2147483647",
|
||||
"-2147483648",
|
||||
]
|
||||
targets.each do |str|
|
||||
assert_equal(str, SOAP::SOAPInt.new(str).to_s)
|
||||
end
|
||||
|
||||
targets = [
|
||||
["-0", "0"],
|
||||
["+0", "0"],
|
||||
["000123", "123"],
|
||||
["-000123", "-123"],
|
||||
]
|
||||
targets.each do |data, expected|
|
||||
assert_equal(expected, SOAP::SOAPInt.new(data).to_s)
|
||||
end
|
||||
|
||||
targets = [
|
||||
2147483648,
|
||||
-2147483649,
|
||||
"0.0",
|
||||
"-5.2",
|
||||
"0.000000000000a",
|
||||
"+-5",
|
||||
]
|
||||
targets.each do |d|
|
||||
assert_raises(XSD::ValueSpaceError) do
|
||||
SOAP::SOAPInt.new(d)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
114
test/soap/test_soapelement.rb
Normal file
114
test/soap/test_soapelement.rb
Normal file
|
@ -0,0 +1,114 @@
|
|||
require 'test/unit'
|
||||
require '../lib/soap/baseData'
|
||||
|
||||
class TestSOAPElement < Test::Unit::TestCase
|
||||
include SOAP
|
||||
|
||||
def setup
|
||||
# Nothing to do.
|
||||
end
|
||||
|
||||
def teardown
|
||||
# Nothing to do.
|
||||
end
|
||||
|
||||
def d(elename = nil, text = nil)
|
||||
elename ||= n(nil, nil)
|
||||
if text
|
||||
SOAPElement.new(elename, text)
|
||||
else
|
||||
SOAPElement.new(elename) # do not merge.
|
||||
end
|
||||
end
|
||||
|
||||
def n(namespace, name)
|
||||
XSD::QName.new(namespace, name)
|
||||
end
|
||||
|
||||
def test_initialize
|
||||
elename = n(nil, nil)
|
||||
obj = d(elename)
|
||||
assert_equal(elename, obj.elename)
|
||||
assert_equal(LiteralNamespace, obj.encodingstyle)
|
||||
assert_equal({}, obj.extraattr)
|
||||
assert_equal([], obj.precedents)
|
||||
assert_equal(false, obj.qualified)
|
||||
assert_equal(nil, obj.text)
|
||||
assert(obj.members.empty?)
|
||||
|
||||
obj = d("foo", "text")
|
||||
assert_equal(n(nil, "foo"), obj.elename)
|
||||
assert_equal("text", obj.text)
|
||||
end
|
||||
|
||||
def test_add
|
||||
obj = d()
|
||||
child = d("abc")
|
||||
obj.add(child)
|
||||
assert(obj.key?("abc"))
|
||||
assert_same(child, obj["abc"])
|
||||
assert_same(child, obj.abc)
|
||||
def obj.foo; 1; end
|
||||
child = d("foo")
|
||||
obj.add(child)
|
||||
assert_equal(1, obj.foo)
|
||||
assert_equal(child, obj.var_foo)
|
||||
child = d("_?a?b_")
|
||||
obj.add(child)
|
||||
assert_equal(child, obj.var__ab_)
|
||||
end
|
||||
|
||||
def test_member
|
||||
obj = d()
|
||||
c1 = d("c1")
|
||||
obj.add(c1)
|
||||
c2 = d("c2")
|
||||
obj.add(c2)
|
||||
assert(obj.key?("c1"))
|
||||
assert(obj.key?("c2"))
|
||||
assert_equal(c1, obj["c1"])
|
||||
assert_equal(c2, obj["c2"])
|
||||
c22 = d("c22")
|
||||
obj["c2"] = c22
|
||||
assert(obj.key?("c2"))
|
||||
assert_equal(c22, obj["c2"])
|
||||
assert_equal(["c1", "c2"], obj.members.sort)
|
||||
#
|
||||
k_expect = ["c1", "c2"]
|
||||
v_expect = [c1, c22]
|
||||
obj.each do |k, v|
|
||||
assert(k_expect.include?(k))
|
||||
assert(v_expect.include?(v))
|
||||
k_expect.delete(k)
|
||||
v_expect.delete(v)
|
||||
end
|
||||
assert(k_expect.empty?)
|
||||
assert(v_expect.empty?)
|
||||
end
|
||||
|
||||
def test_to_obj
|
||||
obj = d("root")
|
||||
ct1 = d("ct1", "t1")
|
||||
obj.add(ct1)
|
||||
c2 = d("c2")
|
||||
ct2 = d("ct2", "t2")
|
||||
c2.add(ct2)
|
||||
obj.add(c2)
|
||||
assert_equal({ "ct1" => "t1", "c2" => { "ct2" => "t2" }}, obj.to_obj)
|
||||
#
|
||||
assert_equal(nil, d().to_obj)
|
||||
assert_equal("abc", d(nil, "abc").to_obj)
|
||||
assert_equal(nil, d("abc", nil).to_obj)
|
||||
end
|
||||
|
||||
def test_from_obj
|
||||
source = { "ct1" => "t1", "c2" => { "ct2" => "t2" }}
|
||||
assert_equal(source, SOAPElement.from_obj(source).to_obj)
|
||||
source = { "1" => nil }
|
||||
assert_equal(source, SOAPElement.from_obj(source).to_obj)
|
||||
source = {}
|
||||
assert_equal(nil, SOAPElement.from_obj(source).to_obj) # not {}
|
||||
source = nil
|
||||
assert_equal(nil, SOAPElement.from_obj(source).to_obj)
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue