Class: RPC::HelperTest

Inherits:
Test::Unit::TestCase
  • Object
show all
Includes:
ClientTester
Defined in:
lib/vendor/xmpp4r/test/rpc/tc_helper.rb

Instance Method Summary collapse

Instance Method Details

#echo(msg = nil) ⇒ Object



32
33
34
# File 'lib/vendor/xmpp4r/test/rpc/tc_helper.rb', line 32

def echo(msg = nil)
  msg
end

#give_client_jid!Object



16
17
18
19
20
21
# File 'lib/vendor/xmpp4r/test/rpc/tc_helper.rb', line 16

def give_client_jid!
  class << @client
    remove_method(:jid) # avoids warning
    def jid; Jabber::JID.new('[email protected]/clienttester'); end
  end
end

#test_100callsObject



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/vendor/xmpp4r/test/rpc/tc_helper.rb', line 81

def test_100calls
  give_client_jid!

  sv = RPC::Server.new(@server)
  sv.add_handler("add") do |a,b| a+b end

  cl = RPC::Client.new(@client, 'a@b/c')
  correct = true
  100.times {
    a, b = rand(1000), rand(1000)
    correct &&= (cl.call('add', a, b) == a + b)
  }

  assert(correct)
end

#test_createObject



23
24
25
26
27
28
29
30
# File 'lib/vendor/xmpp4r/test/rpc/tc_helper.rb', line 23

def test_create
  give_client_jid!

  cl = RPC::Client.new(@client, 'a@b/c')
  assert_kind_of(RPC::Client, cl)
  sv = RPC::Server.new(@server)
  assert_kind_of(RPC::Server, sv)
end

#test_introspectionObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/vendor/xmpp4r/test/rpc/tc_helper.rb', line 54

def test_introspection
  give_client_jid!

  sv = RPC::Server.new(@server)
  sv.add_introspection

  cl = RPC::Client.new(@client, 'a@b/c')
  cl_methods = cl.call("system.listMethods")
  assert(cl_methods.size > 0)
  cl_methods.each { |method|
    assert_kind_of(String, method)
    assert(method =~ /^system\./)
  }
end

#test_multicallObject



69
70
71
72
73
74
75
76
77
78
79
# File 'lib/vendor/xmpp4r/test/rpc/tc_helper.rb', line 69

def test_multicall
  give_client_jid!

  sv = RPC::Server.new(@server)
  sv.add_multicall
  sv.add_handler("reverse") do |s| s.reverse end
  sv.add_handler("upcase") do |s| s.upcase end

  cl = RPC::Client.new(@client, 'a@b/c')
  assert_equal(['tseT', 'TEST'], cl.multicall(['reverse', 'Test'], ['upcase', 'Test']))
end

#test_simpleObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/vendor/xmpp4r/test/rpc/tc_helper.rb', line 36

def test_simple
  give_client_jid!

  sv = RPC::Server.new(@server)
  sv.add_handler("echo", &method(:echo))

  cl = RPC::Client.new(@client, 'a@b/c')
  assert_nothing_raised do
    assert_equal('Test string', cl.call("echo", 'Test string'))
  end

  # exception during serialisation bug identified on xmpp4r-devel
  # https://mail.gna.org/public/xmpp4r-devel/2008-05/msg00010.html
  assert_raise XMLRPC::FaultException do
    cl.call("echo")
  end
end