Welcome to the "trac"-ing site of soap4r!
[soap4r] [httpclient] [openpgp4u] [pkcs1] [logger] [csv] [vtr]

root/tags/RELEASE_1_5_0/test/test_calc.rb

Revision 930, 1.0 kB (checked in by nahi, 5 years ago)

Add tests.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to author date id revision
Line 
1 require 'test/unit'
2 require 'soap/rpc/driver'
3
4 dir = '../sample/Calc/'
5 $:.push(dir)
6 require 'server.rb'
7 $:.delete(dir)
8
9 class TestCalc < Test::Unit::TestCase
10   def setup
11     @server = CalcServer.new(self.class.name, nil, '0.0.0.0', 7000)
12     @t = Thread.new {
13       @server.start
14     }
15     while @server.server.status != :Running
16       sleep 0.1
17     end
18     @calc = SOAP::RPC::Driver.new('http://localhost:7000/', 'http://tempuri.org/calcService')
19     @calc.add_method('add', 'lhs', 'rhs')
20     @calc.add_method('sub', 'lhs', 'rhs')
21     @calc.add_method('multi', 'lhs', 'rhs')
22     @calc.add_method('div', 'lhs', 'rhs')
23   end
24
25   def teardown
26     @server.server.shutdown
27     @t.kill
28   end
29
30   def test_calc
31     assert_equal(3, @calc.add(1, 2))
32     assert_equal(-1.1, @calc.sub(1.1, 2.2))
33     assert_equal(2.42, @calc.multi(1.1, 2.2))
34     assert_equal(2, @calc.div(5, 2))
35     assert_equal(2.5, @calc.div(5.0, 2))
36     assert_equal(1.0/0.0, @calc.div(1.1, 0))
37     assert_raises(ZeroDivisionError) do
38       @calc.div(1, 0)
39     end
40   end
41 end
Note: See TracBrowser for help on using the browser.