~ubuntu-branches/ubuntu/hardy/ruby1.8/hardy-updates

« back to all changes in this revision

Viewing changes to test/xmlrpc/test_marshal.rb

  • Committer: Bazaar Package Importer
  • Author(s): akira yamada
  • Date: 2007-03-13 22:11:58 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20070313221158-h3oql37brlaf2go2
Tags: 1.8.6-1
* new upstream version, 1.8.6.
* libruby1.8 conflicts with libopenssl-ruby1.8 (< 1.8.6) (closes: #410018)
* changed packaging style to cdbs from dbs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
require 'test/unit'
 
2
require "xmlrpc/marshal"
 
3
 
 
4
class Test_Marshal < Test::Unit::TestCase
 
5
  # for test_parser_values
 
6
  class Person
 
7
    include XMLRPC::Marshallable
 
8
    attr_reader :name
 
9
    def initialize(name)
 
10
      @name = name
 
11
    end
 
12
  end
 
13
 
 
14
 
 
15
  def test1_dump_response
 
16
    assert_nothing_raised(NameError) {
 
17
      XMLRPC::Marshal.dump_response('arg')
 
18
    }
 
19
  end
 
20
 
 
21
  def test1_dump_call
 
22
    assert_nothing_raised(NameError) {
 
23
      XMLRPC::Marshal.dump_call('methodName', 'arg')
 
24
    }
 
25
  end
 
26
 
 
27
  def test2_dump_load_response
 
28
    value = [1, 2, 3, {"test" => true}, 3.4]
 
29
    res   = XMLRPC::Marshal.dump_response(value)
 
30
 
 
31
    assert_equal(value, XMLRPC::Marshal.load_response(res))
 
32
  end
 
33
 
 
34
  def test2_dump_load_call
 
35
    methodName = "testMethod"
 
36
    value      = [1, 2, 3, {"test" => true}, 3.4]
 
37
    exp        = [methodName, [value, value]]
 
38
 
 
39
    res   = XMLRPC::Marshal.dump_call(methodName, value, value)
 
40
 
 
41
    assert_equal(exp, XMLRPC::Marshal.load_call(res))
 
42
  end
 
43
 
 
44
  def test_parser_values
 
45
    v1 = [ 
 
46
      1, -7778,                        # integers
 
47
      1.0, 0.0, -333.0, 2343434343.0,  # floats
 
48
      false, true, true, false,        # booleans
 
49
      "Hallo", "with < and >", ""      # strings
 
50
    ]
 
51
 
 
52
    v2 = [
 
53
      [v1, v1, v1],
 
54
      {"a" => v1}
 
55
    ]
 
56
 
 
57
    v3 = [
 
58
      XMLRPC::Base64.new("\001"*1000), # base64
 
59
      :aSymbol, :anotherSym            # symbols (-> string)
 
60
    ]
 
61
    v3_exp = [
 
62
      "\001"*1000,
 
63
      "aSymbol", "anotherSym"
 
64
    ]
 
65
    person = Person.new("Michael")
 
66
 
 
67
    XMLRPC::XMLParser.each_installed_parser do |parser|
 
68
      m = XMLRPC::Marshal.new(parser)
 
69
 
 
70
      assert_equal( v1, m.load_response(m.dump_response(v1)) )
 
71
      assert_equal( v2, m.load_response(m.dump_response(v2)) )
 
72
      assert_equal( v3_exp, m.load_response(m.dump_response(v3)) )
 
73
 
 
74
      pers = m.load_response(m.dump_response(person))
 
75
      
 
76
      assert( pers.is_a?(Person) )
 
77
      assert( person.name == pers.name ) 
 
78
    end
 
79
 
 
80
    # missing, Date, Time, DateTime
 
81
    # Struct
 
82
  end
 
83
 
 
84
  def test_no_params_tag
 
85
    # bug found by Idan Sofer
 
86
 
 
87
    expect = %{<?xml version="1.0" ?><methodCall><methodName>myMethod</methodName><params/></methodCall>\n}
 
88
 
 
89
    str = XMLRPC::Marshal.dump_call("myMethod")
 
90
    assert_equal(expect, str)
 
91
  end
 
92
 
 
93
end