summaryrefslogtreecommitdiff
path: root/test/xmlrpc/test_parser.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_parser.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_parser.rb')
-rw-r--r--test/xmlrpc/test_parser.rb77
1 files changed, 77 insertions, 0 deletions
diff --git a/test/xmlrpc/test_parser.rb b/test/xmlrpc/test_parser.rb
new file mode 100644
index 00000000000..3e55cdb35a2
--- /dev/null
+++ b/test/xmlrpc/test_parser.rb
@@ -0,0 +1,77 @@
+$LOAD_PATH.unshift '../../lib'
+require 'test/unit'
+require "xmlrpc/parser"
+
+module GenericParserTest
+ def setup
+ @xml1 = File.readlines("data/xml1.xml").to_s
+ @expected1 = File.readlines("data/xml1.expected").to_s.chomp
+
+ @xml2 = File.readlines("data/bug_covert.xml").to_s
+ @expected2 = File.readlines("data/bug_covert.expected").to_s.chomp
+
+ @xml3 = File.readlines("data/bug_bool.xml").to_s
+ @expected3 = File.readlines("data/bug_bool.expected").to_s.chomp
+
+ @xml4 = File.readlines("data/value.xml").to_s
+ @expected4 = File.readlines("data/value.expected").to_s.chomp
+
+ @cdata_xml = File.readlines("data/bug_cdata.xml").to_s.chomp
+ @cdata_expected = File.readlines("data/bug_cdata.expected").to_s.chomp
+
+ @fault_doc = File.readlines("data/fault.xml").to_s
+ end
+
+ # test parseMethodResponse --------------------------------------------------
+
+ def test_parseMethodResponse1
+ assert_equal(@expected1, @p.parseMethodResponse(@xml1).inspect)
+ end
+
+ def test_parseMethodResponse2
+ assert_equal(@expected2, @p.parseMethodResponse(@xml2).inspect)
+ end
+
+ def test_parseMethodResponse3
+ assert_equal(@expected3, @p.parseMethodResponse(@xml3).inspect)
+ end
+
+ def test_cdata
+ assert_equal(@cdata_expected, @p.parseMethodResponse(@cdata_xml).inspect)
+ end
+
+ # test parseMethodCall ------------------------------------------------------
+
+ def test_parseMethodCall
+ assert_equal(@expected4, @p.parseMethodCall(@xml4).inspect)
+ 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
+end
+
+# create test class for each installed parser
+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