1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
require File.dirname(__FILE__) + '/abstract_unit'
module Nested
class StructClass
attr_accessor :name
attr_accessor :version
def initialize
@name = 5
@version = "1.0"
end
def ==(other)
@name == other.name && @version == other.version
end
end
end
module EncodingTest
def setup
@call_signature = [:int, :bool, :string, :float, [:time], Nested::StructClass]
@call_params = [1, true, "string", 5.0, [Time.now], Nested::StructClass.new]
@response_signature = [:string]
@response_param = "hello world"
test_setup
end
def test_abstract
obj = WS::Encoding::AbstractEncoding.new
assert_raises(NotImplementedError) do
obj.encode_rpc_call(nil, nil)
end
assert_raises(NotImplementedError) do
obj.decode_rpc_call(nil)
end
assert_raises(NotImplementedError) do
obj.encode_rpc_response(nil, nil)
end
assert_raises(NotImplementedError) do
obj.decode_rpc_response(nil)
end
end
def encode_rpc_call(method_name, signature, params)
params = params.dup
(0..(signature.length-1)).each do |i|
type_binding = @marshaler.register_type(signature[i])
info = WS::ParamInfo.create(signature[i], i, type_binding)
params[i] = @marshaler.marshal(WS::Param.new(params[i], info))
end
@encoder.encode_rpc_call(method_name, params)
end
def decode_rpc_call(obj)
@encoder.decode_rpc_call(obj)
end
def encode_rpc_response(method_name, signature, param)
type_binding = @marshaler.register_type(signature[0])
info = WS::ParamInfo.create(signature[0], 0, type_binding)
param = @marshaler.marshal(WS::Param.new(param, info))
@encoder.encode_rpc_response(method_name, param)
end
def decode_rpc_response(obj)
@encoder.decode_rpc_response(obj)
end
end
|