-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontroller_test.go
More file actions
119 lines (82 loc) · 2.54 KB
/
controller_test.go
File metadata and controls
119 lines (82 loc) · 2.54 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package gorpc
import (
"testing"
"time"
)
type embedObj struct {
S1 string
S2 int
}
type funcParams struct {
P1 string
P2 int
P3 embedObj
}
type RpcController struct {
Result funcParams
}
type MyRootController struct {
Controller
Cont1 RpcController
}
func (this *RpcController) RPC_NotifyTest(params funcParams) {
this.Result = params
}
func TestController(t *testing.T) {
beginTest("TestController")
f := GetFactory()
transport := f.MakeTransport(nil).(*LoopbackTransport)
transport.Start()
transport.addConnection(f.MakeAddress("1", "2", nil))
transport.addConnection(f.MakeAddress("2", "1", nil))
conn1, _ := transport.getConnection("1")
conn1.SetRootController(&MyRootController{})
param := funcParams{P1:"Test", P2:42, P3:embedObj{"Wow", 13}}
conn2, _ := transport.getConnection("2")
conn2.Notify("Cont1.NotifyTest", param)
time.Sleep(time.Millisecond * 1)
if conn1.RootController().(*MyRootController).Cont1.Result != param {
t.Errorf("Params was not passed correctly: %v != %v", param, conn1.RootController().(*MyRootController).Cont1.Result)
}
transport.quit <- true
endTest()
}
func TestAdvancedParams(t *testing.T) {
beginTest("TestAdvancedParams")
f := GetFactory()
transport := f.MakeTransport(nil).(*LoopbackTransport)
transport.Start()
transport.addConnection(f.MakeAddress("1", "2", nil))
transport.addConnection(f.MakeAddress("2", "1", nil))
conn1, _ := transport.getConnection("1")
conn1.SetRootController(&MyRootController{})
param := []interface{}{"Test", 42, embedObj{"Wow", 13}}
conn2, _ := transport.getConnection("2")
conn2.Notify("Cont1.NotifyTest", param)
time.Sleep(time.Millisecond * 1)
p := funcParams{P1:"Test", P2:42, P3:embedObj{"Wow", 13}}
if conn1.RootController().(*MyRootController).Cont1.Result != p {
t.Errorf("Params was not passed correctly: %v != %v", p, conn1.RootController().(*MyRootController).Cont1.Result)
}
transport.quit <- true
endTest()
}
func TestClose(t *testing.T) {
beginTest("TestRpcEcho")
f := GetFactory()
options := f.MakeTransportOptions()
if _, ok := options.(ITransportOptions); !ok {
t.Errorf("options should be of type ITransportOption, not (%T)%v", options, options)
}
transport := f.MakeTransport(options).(*LoopbackTransport)
transport.addConnection(f.MakeAddress("1", "2", nil))
conn, _ := transport.getConnection("1")
if len(transport.connections) != 1 {
t.Error("There is not exactly one connection.")
}
conn.Close()
if len(transport.connections) != 0 {
t.Error("There is not exactly zero connections.")
}
endTest()
}