-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathTestCaseRpc.cs
88 lines (72 loc) · 2.71 KB
/
TestCaseRpc.cs
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using System;
using Sproto;
namespace sprotoCsharp
{
public class TestCaseRpc : TestCaseBase
{
public TestCaseRpc ()
{
}
public override void run() {
SprotoRpc client = new SprotoRpc ();
SprotoRpc service = new SprotoRpc (Protocol.Instance);
SprotoRpc.RpcRequest clientRequest = client.Attach (Protocol.Instance);
// ===============foobar=====================
// request
SprotoType.foobar.request obj = new SprotoType.foobar.request ();
obj.what = "foo";
byte[] req = clientRequest.Invoke<Protocol.foobar> (obj, 1);
assert (req, new byte[] {0X55, 0X02, 0X04, 0X04, 0X01, 0Xc4, 0X03, 0X66, 0X6f, 0X01, 0X6f});
// dispatch
SprotoRpc.RpcInfo sinfo = service.Dispatch (req);
assert (sinfo.type == SprotoRpc.RpcType.REQUEST);
assert (sinfo.requestObj.GetType () == typeof(SprotoType.foobar.request));
assert (sinfo.Response != null);
SprotoType.foobar.request req_obj = (SprotoType.foobar.request)sinfo.requestObj;
assert (req_obj.what == "foo");
// response
SprotoType.foobar.response obj2 = new SprotoType.foobar.response ();
obj2.ok = true;
byte[] resp = sinfo.Response (obj2);
assert (resp, new byte[] {0X55, 0X02, 0X01, 0X04, 0X01, 0X01, 0X04});
// dispatch
sinfo = client.Dispatch (resp);
assert (sinfo.type == SprotoRpc.RpcType.RESPONSE);
assert (sinfo.session == 1);
assert (((SprotoType.foobar.response)sinfo.responseObj).ok == true);
// ================foo====================
// request
req = clientRequest.Invoke<Protocol.foo> (null, 2);
assert (req, new byte[] {0X15, 0X02, 0X06, 0X06});
// dispatch
sinfo = service.Dispatch (req);
assert (sinfo.type == SprotoRpc.RpcType.REQUEST);
assert (sinfo.tag == Protocol.foo.Tag);
assert (sinfo.requestObj == null);
// response
SprotoType.foo.response obj3 = new SprotoType.foo.response();
obj3.ok = false;
resp = sinfo.Response (obj3);
assert (resp, new byte[] {0X55, 0X02, 0X01, 0X06, 0X01, 0X01, 0X02});
// dispatch
sinfo = client.Dispatch (resp);
assert (sinfo.type == SprotoRpc.RpcType.RESPONSE);
assert (sinfo.session == 2);
assert (((SprotoType.foo.response)sinfo.responseObj).ok == false);
// ================bar====================
// request
req = clientRequest.Invoke<Protocol.bar> ();
assert (req, new byte[] { 0X05, 0X01, 0X08, });
// dispatch
sinfo = service.Dispatch (req);
assert (sinfo.type == SprotoRpc.RpcType.REQUEST);
assert (sinfo.requestObj == null);
assert (sinfo.tag == Protocol.bar.Tag);
assert (sinfo.Response == null);
// ================blackhole====================
// request
req = clientRequest.Invoke<Protocol.blackhole> ();
assert (req, new byte[]{ 0X05, 0X01, 0X0a });
}
}
}