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

« back to all changes in this revision

Viewing changes to test/xmlrpc/test_parser.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/datetime'
 
3
require "xmlrpc/parser"
 
4
require 'yaml'
 
5
 
 
6
module GenericParserTest
 
7
  def datafile(base)
 
8
    File.join(File.dirname(__FILE__), "data", base)
 
9
  end
 
10
 
 
11
  def load_data(name)
 
12
    [File.read(datafile(name) + ".xml"), YAML.load(File.read(datafile(name) + ".expected"))]
 
13
  end
 
14
 
 
15
  def setup
 
16
    @xml1, @expected1 = load_data('xml1')
 
17
    @xml2, @expected2 = load_data('bug_covert') 
 
18
    @xml3, @expected3 = load_data('bug_bool') 
 
19
    @xml4, @expected4 = load_data('value') 
 
20
 
 
21
    @cdata_xml, @cdata_expected = load_data('bug_cdata')
 
22
 
 
23
    @datetime_xml = File.read(datafile('datetime_iso8601.xml'))
 
24
    @datetime_expected = XMLRPC::DateTime.new(2004, 11, 5, 1, 15, 23)
 
25
 
 
26
    @fault_doc = File.read(datafile('fault.xml'))
 
27
  end
 
28
 
 
29
  # test parseMethodResponse --------------------------------------------------
 
30
  
 
31
  def test_parseMethodResponse1
 
32
    assert_equal(@expected1, @p.parseMethodResponse(@xml1))
 
33
  end
 
34
 
 
35
  def test_parseMethodResponse2
 
36
    assert_equal(@expected2, @p.parseMethodResponse(@xml2))
 
37
  end
 
38
 
 
39
  def test_parseMethodResponse3
 
40
    assert_equal(@expected3, @p.parseMethodResponse(@xml3))
 
41
  end
 
42
 
 
43
  def test_cdata
 
44
    assert_equal(@cdata_expected, @p.parseMethodResponse(@cdata_xml))
 
45
  end
 
46
 
 
47
  def test_dateTime
 
48
    assert_equal(@datetime_expected, @p.parseMethodResponse(@datetime_xml)[1])
 
49
  end
 
50
 
 
51
  # test parseMethodCall ------------------------------------------------------
 
52
 
 
53
  def test_parseMethodCall
 
54
    assert_equal(@expected4, @p.parseMethodCall(@xml4))
 
55
  end
 
56
 
 
57
  # test fault ----------------------------------------------------------------
 
58
 
 
59
  def test_fault
 
60
    flag, fault = @p.parseMethodResponse(@fault_doc)
 
61
     assert_equal(flag, false)
 
62
     unless fault.is_a? XMLRPC::FaultException
 
63
       assert(false, "must be an instance of class XMLRPC::FaultException")
 
64
     end
 
65
     assert_equal(fault.faultCode, 4)
 
66
     assert_equal(fault.faultString, "an error message")
 
67
  end
 
68
end
 
69
 
 
70
# create test class for each installed parser 
 
71
XMLRPC::XMLParser.each_installed_parser do |parser|
 
72
  klass = parser.class
 
73
  name = klass.to_s.split("::").last
 
74
 
 
75
  eval %{
 
76
    class Test_#{name} < Test::Unit::TestCase
 
77
      include GenericParserTest
 
78
 
 
79
      def setup
 
80
        super
 
81
        @p = #{klass}.new
 
82
      end
 
83
    end
 
84
  }
 
85
end