summaryrefslogtreecommitdiff
path: root/test/soap/marshal
diff options
context:
space:
mode:
authornahi <nahi@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-09-24 15:18:44 +0000
committernahi <nahi@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-09-24 15:18:44 +0000
commitdb9445103c082a306ba085f7677da02ea94b8841 (patch)
treea311d59f031ae5def87f68be71ed1f58abadc031 /test/soap/marshal
parent8c2fb77787d1f20b4c19c9c52552856c339b86e9 (diff)
* 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
Diffstat (limited to 'test/soap/marshal')
-rw-r--r--test/soap/marshal/cmarshal.rb142
-rw-r--r--test/soap/marshal/test_digraph.rb45
-rw-r--r--test/soap/marshal/test_marshal.rb301
-rw-r--r--test/soap/marshal/test_struct.rb38
4 files changed, 526 insertions, 0 deletions
diff --git a/test/soap/marshal/cmarshal.rb b/test/soap/marshal/cmarshal.rb
new file mode 100644
index 0000000000..d1f66b5b1e
--- /dev/null
+++ b/test/soap/marshal/cmarshal.rb
@@ -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
diff --git a/test/soap/marshal/test_digraph.rb b/test/soap/marshal/test_digraph.rb
new file mode 100644
index 0000000000..93f555ffc1
--- /dev/null
+++ b/test/soap/marshal/test_digraph.rb
@@ -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
diff --git a/test/soap/marshal/test_marshal.rb b/test/soap/marshal/test_marshal.rb
new file mode 100644
index 0000000000..8a1b82946f
--- /dev/null
+++ b/test/soap/marshal/test_marshal.rb
@@ -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
diff --git a/test/soap/marshal/test_struct.rb b/test/soap/marshal/test_struct.rb
new file mode 100644
index 0000000000..6596fb7a33
--- /dev/null
+++ b/test/soap/marshal/test_struct.rb
@@ -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