2004-11-15 18:26:20 -05:00
|
|
|
require 'test/unit'
|
2004-11-15 20:11:49 -05:00
|
|
|
require 'xmlrpc/datetime'
|
2004-11-15 18:26:20 -05:00
|
|
|
require "xmlrpc/parser"
|
2004-12-02 10:22:23 -05:00
|
|
|
require 'yaml'
|
2004-11-15 18:26:20 -05:00
|
|
|
|
|
|
|
module GenericParserTest
|
2004-11-16 05:55:47 -05:00
|
|
|
def datafile(base)
|
|
|
|
File.join(File.dirname(__FILE__), "data", base)
|
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-11-16 05:55:47 -05:00
|
|
|
def load_data(name)
|
2004-12-02 10:22:23 -05:00
|
|
|
[File.read(datafile(name) + ".xml"), YAML.load(File.read(datafile(name) + ".expected"))]
|
2004-11-16 05:55:47 -05:00
|
|
|
end
|
2004-11-15 18:26:20 -05:00
|
|
|
|
2004-11-16 05:55:47 -05:00
|
|
|
def setup
|
|
|
|
@xml1, @expected1 = load_data('xml1')
|
2009-03-05 22:56:38 -05:00
|
|
|
@xml2, @expected2 = load_data('bug_covert')
|
|
|
|
@xml3, @expected3 = load_data('bug_bool')
|
|
|
|
@xml4, @expected4 = load_data('value')
|
2004-11-15 18:26:20 -05:00
|
|
|
|
2004-11-16 05:55:47 -05:00
|
|
|
@cdata_xml, @cdata_expected = load_data('bug_cdata')
|
2004-11-15 18:26:20 -05:00
|
|
|
|
2004-11-16 05:55:47 -05:00
|
|
|
@datetime_xml = File.read(datafile('datetime_iso8601.xml'))
|
2004-11-15 20:11:49 -05:00
|
|
|
@datetime_expected = XMLRPC::DateTime.new(2004, 11, 5, 1, 15, 23)
|
|
|
|
|
2004-11-16 05:55:47 -05:00
|
|
|
@fault_doc = File.read(datafile('fault.xml'))
|
2004-11-15 18:26:20 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
# test parseMethodResponse --------------------------------------------------
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-11-15 18:26:20 -05:00
|
|
|
def test_parseMethodResponse1
|
2004-12-02 10:22:23 -05:00
|
|
|
assert_equal(@expected1, @p.parseMethodResponse(@xml1))
|
2004-11-15 18:26:20 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_parseMethodResponse2
|
2004-12-02 10:22:23 -05:00
|
|
|
assert_equal(@expected2, @p.parseMethodResponse(@xml2))
|
2004-11-15 18:26:20 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_parseMethodResponse3
|
2004-12-02 10:22:23 -05:00
|
|
|
assert_equal(@expected3, @p.parseMethodResponse(@xml3))
|
2004-11-15 18:26:20 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_cdata
|
2004-12-02 10:22:23 -05:00
|
|
|
assert_equal(@cdata_expected, @p.parseMethodResponse(@cdata_xml))
|
2004-11-15 18:26:20 -05:00
|
|
|
end
|
|
|
|
|
2004-11-15 20:11:49 -05:00
|
|
|
def test_dateTime
|
|
|
|
assert_equal(@datetime_expected, @p.parseMethodResponse(@datetime_xml)[1])
|
|
|
|
end
|
|
|
|
|
2004-11-15 18:26:20 -05:00
|
|
|
# test parseMethodCall ------------------------------------------------------
|
|
|
|
|
|
|
|
def test_parseMethodCall
|
2004-12-02 10:22:23 -05:00
|
|
|
assert_equal(@expected4, @p.parseMethodCall(@xml4))
|
2004-11-15 18:26:20 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
# test fault ----------------------------------------------------------------
|
|
|
|
|
|
|
|
def test_fault
|
|
|
|
flag, fault = @p.parseMethodResponse(@fault_doc)
|
|
|
|
assert_equal(flag, false)
|
|
|
|
unless fault.is_a? XMLRPC::FaultException
|
|
|
|
assert(false, "must be an instance of class XMLRPC::FaultException")
|
|
|
|
end
|
|
|
|
assert_equal(fault.faultCode, 4)
|
|
|
|
assert_equal(fault.faultString, "an error message")
|
|
|
|
end
|
2011-05-26 02:44:48 -04:00
|
|
|
|
|
|
|
def test_fault_message
|
|
|
|
fault = XMLRPC::FaultException.new(1234, 'an error message')
|
|
|
|
assert_equal('an error message', fault.to_s)
|
|
|
|
assert_equal('#<XMLRPC::FaultException: an error message>', fault.inspect)
|
|
|
|
end
|
2004-11-15 18:26:20 -05:00
|
|
|
end
|
|
|
|
|
2009-03-05 22:56:38 -05:00
|
|
|
# create test class for each installed parser
|
2004-11-15 18:26:20 -05:00
|
|
|
XMLRPC::XMLParser.each_installed_parser do |parser|
|
|
|
|
klass = parser.class
|
|
|
|
name = klass.to_s.split("::").last
|
|
|
|
|
|
|
|
eval %{
|
|
|
|
class Test_#{name} < Test::Unit::TestCase
|
|
|
|
include GenericParserTest
|
|
|
|
|
|
|
|
def setup
|
|
|
|
super
|
|
|
|
@p = #{klass}.new
|
|
|
|
end
|
|
|
|
end
|
|
|
|
}
|
|
|
|
end
|