summaryrefslogtreecommitdiff
path: root/test/xmlrpc/test_marshal.rb
diff options
context:
space:
mode:
authormneumann <mneumann@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-11-15 23:26:20 +0000
committermneumann <mneumann@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-11-15 23:26:20 +0000
commit396b1f27ca1581aa676c235a5d021828eef6257f (patch)
tree96f95f56b0a5b3cfa508a3b669b068c0705a644c /test/xmlrpc/test_marshal.rb
parent67d54f209d28019cc5d8b332706dd9950b56bdc7 (diff)
* imported and refactored original test cases
* added methods XMLRPC::XMLParser.each_installed_parser and XMLRPC::XMLWriter.each_installed_writer to simply original test cases * use Object#allocate instead of defining an empty #initialize * module XMLRPC::Marshallable is now only used for tagging git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7274 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/xmlrpc/test_marshal.rb')
-rw-r--r--test/xmlrpc/test_marshal.rb94
1 files changed, 94 insertions, 0 deletions
diff --git a/test/xmlrpc/test_marshal.rb b/test/xmlrpc/test_marshal.rb
new file mode 100644
index 00000000000..5424628d9a0
--- /dev/null
+++ b/test/xmlrpc/test_marshal.rb
@@ -0,0 +1,94 @@
+$LOAD_PATH.unshift '../../lib'
+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