2003-09-24 11:18:44 -04:00
|
|
|
require 'test/unit'
|
|
|
|
require 'soap/rpc/driver'
|
2003-09-27 03:03:29 -04:00
|
|
|
require 'logger'
|
2003-09-24 11:18:44 -04:00
|
|
|
require 'webrick'
|
2003-10-01 11:29:43 -04:00
|
|
|
require 'rbconfig'
|
2003-09-24 11:18:44 -04:00
|
|
|
|
2003-09-26 14:34:41 -04:00
|
|
|
|
|
|
|
module SOAP
|
|
|
|
module Calc
|
|
|
|
|
|
|
|
|
2003-09-24 11:18:44 -04:00
|
|
|
class TestCalcCGI < Test::Unit::TestCase
|
2003-10-01 11:29:43 -04:00
|
|
|
# This test shuld be run after installing ruby.
|
|
|
|
RUBYBIN = File.join(Config::CONFIG["bindir"], Config::CONFIG["ruby_install_name"])
|
2003-09-24 11:18:44 -04:00
|
|
|
def setup
|
2003-09-27 03:03:29 -04:00
|
|
|
logger = Logger.new(STDERR)
|
|
|
|
logger.level = Logger::Severity::FATAL
|
2003-09-24 11:18:44 -04:00
|
|
|
@server = WEBrick::HTTPServer.new(
|
|
|
|
:BindAddress => "0.0.0.0",
|
2003-09-27 03:03:29 -04:00
|
|
|
:Logger => logger,
|
2003-09-24 11:18:44 -04:00
|
|
|
:Port => 8808,
|
2003-09-27 03:03:29 -04:00
|
|
|
:AccessLog => [],
|
2003-09-24 11:18:44 -04:00
|
|
|
:DocumentRoot => File.dirname(File.expand_path(__FILE__)),
|
2003-10-01 11:29:43 -04:00
|
|
|
:CGIPathEnv => ENV['PATH'],
|
|
|
|
:CGIInterpreter => RUBYBIN
|
2003-09-24 11:18:44 -04:00
|
|
|
)
|
|
|
|
@t = Thread.new {
|
|
|
|
@server.start
|
|
|
|
}
|
|
|
|
while @server.status != :Running
|
|
|
|
sleep 0.1
|
|
|
|
end
|
|
|
|
@calc = SOAP::RPC::Driver.new('http://localhost:8808/server.cgi', 'http://tempuri.org/calcService')
|
|
|
|
@calc.add_method('add', 'lhs', 'rhs')
|
|
|
|
@calc.add_method('sub', 'lhs', 'rhs')
|
|
|
|
@calc.add_method('multi', 'lhs', 'rhs')
|
|
|
|
@calc.add_method('div', 'lhs', 'rhs')
|
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
|
|
|
@server.shutdown
|
|
|
|
@t.kill
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_calc
|
|
|
|
assert_equal(3, @calc.add(1, 2))
|
|
|
|
assert_equal(-1.1, @calc.sub(1.1, 2.2))
|
|
|
|
assert_equal(2.42, @calc.multi(1.1, 2.2))
|
|
|
|
assert_equal(2, @calc.div(5, 2))
|
|
|
|
assert_equal(2.5, @calc.div(5.0, 2))
|
|
|
|
assert_equal(1.0/0.0, @calc.div(1.1, 0))
|
|
|
|
assert_raises(ZeroDivisionError) do
|
|
|
|
@calc.div(1, 0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2003-09-26 14:34:41 -04:00
|
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|