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.
|
2003-10-05 01:42:04 -04:00
|
|
|
RUBYBIN = File.join(
|
|
|
|
Config::CONFIG["bindir"],
|
|
|
|
Config::CONFIG["ruby_install_name"] + Config::CONFIG["EXEEXT"]
|
|
|
|
)
|
|
|
|
|
2003-10-18 11:21:18 -04:00
|
|
|
Port = 17171
|
|
|
|
|
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-10-20 11:37:11 -04:00
|
|
|
logger.level = Logger::Severity::DEBUG if $DEBUG
|
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-10-18 11:21:18 -04:00
|
|
|
:Port => Port,
|
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 {
|
2003-10-20 11:37:11 -04:00
|
|
|
Thread.current.abort_on_exception = true
|
2003-09-24 11:18:44 -04:00
|
|
|
@server.start
|
|
|
|
}
|
|
|
|
while @server.status != :Running
|
|
|
|
sleep 0.1
|
2003-10-20 11:37:11 -04:00
|
|
|
unless @t.alive?
|
|
|
|
@t.join
|
|
|
|
raise
|
|
|
|
end
|
2003-09-24 11:18:44 -04:00
|
|
|
end
|
2003-10-18 11:21:18 -04:00
|
|
|
@calc = SOAP::RPC::Driver.new("http://localhost:#{Port}/server.cgi", 'http://tempuri.org/calcService')
|
2003-09-24 11:18:44 -04:00
|
|
|
@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
|
2003-10-20 11:37:11 -04:00
|
|
|
@t.join
|
2003-09-24 11:18:44 -04:00
|
|
|
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
|