-
Notifications
You must be signed in to change notification settings - Fork 11
/
client_test.go
335 lines (288 loc) · 6.64 KB
/
client_test.go
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
package fanuc
import (
"net/http"
"net/http/httptest"
"testing"
)
func TestFileClient(t *testing.T) {
c, err := NewFileClient("testdata/MD")
if err != nil {
t.Fatal(err)
}
allTests(c, t)
}
func TestHTTPClient(t *testing.T) {
server := httptest.NewServer(http.FileServer(http.Dir("testdata")))
defer server.Close()
c, err := NewHTTPClient(server.URL)
if err != nil {
t.Fatal(err)
}
allTests(c, t)
}
func allTests(c Client, t *testing.T) {
testNumregs(c, t)
testPosregs(c, t)
testErrors(c, t)
testIO(c, t)
testTPPrograms(c, t)
testTPPositions(c, t)
}
func testNumregs(c Client, t *testing.T) {
// numregs
numregs, err := c.NumericRegisters()
if err != nil {
t.Fatal(err)
}
if len(numregs) != 200 {
t.Fatalf("Got %d numregs. Want 200", len(numregs))
}
tests := []struct {
index int
id int
comment string
value string
}{
{0, 1, "this is an extre", "0"},
{1, 2, "two", "0"},
{2, 3, "three", "0"},
{15, 16, "OutfeedAPLD", "70.000000"},
{199, 200, "SIM/DryRun", "0"},
}
for _, test := range tests {
n := numregs[test.index]
if n.Id != test.id {
t.Errorf("bad id. Got %d, want %d", n.Id, test.id)
}
if n.Comment != test.comment {
t.Errorf("bad comment. Got %q, want %q", n.Comment, test.comment)
}
if n.Value != test.value {
t.Errorf("bad value. Got %q, want %q", n.Value, test.value)
}
}
}
func testPosregs(c Client, t *testing.T) {
posregs, err := c.PositionRegisters()
if err != nil {
t.Fatal(err)
}
if len(posregs) != 100 {
t.Fatalf("Got %d posregs. Want 100", len(posregs))
}
tests := []struct {
id int
comment string
}{
{1, "Maintenance"},
{2, "pr2"},
{6, "ZERO"},
{20, "Outfeed Approach"},
{97, "M2 Place RTTO"},
}
for _, test := range tests {
pr := posregs[test.id-1]
if pr.Id != test.id {
t.Errorf("bad id. Got %d, want %d", pr.Id, test.id)
}
if pr.Comment != test.comment {
t.Errorf("bad comment. Got %q, want %q", pr.Comment, test.comment)
}
}
}
func testErrors(c Client, t *testing.T) {
errors, err := c.Errors()
if err != nil {
t.Fatal(err)
}
if len(errors) != 99 {
t.Fatalf("Got %d errors, want 99", len(errors))
}
var tests = []struct {
id int
seq int
alarm string
msg string
severity string
}{
{2, 1779, "SYST-179", "SHIFT-RESET Released", "WARN"},
{3, 1780, "SYST-178", "SHIFT-RESET Pressed", "WARN"},
{14, 1791, "HOST-209", "SM: Connection Aborted", "WARN"},
{91, 1869, "SYST-043", "TP disabled in T1/T2 mode", "STOP.L"},
}
for _, test := range tests {
err := errors[test.id]
if err.Sequence != test.seq {
t.Errorf("bad seq. Got %d, want %d", err.Sequence, test.seq)
}
if err.Alarm.String() != test.alarm {
t.Errorf("Bad alarm. Got %q, want %q", err.Alarm, test.alarm)
}
if err.Alarm.Msg != test.msg {
t.Errorf("Bad msg. Got %q, want %q", err.Alarm.Msg, test.msg)
}
if err.Severity != test.severity {
t.Errorf("Bad severity. Got %q, want %q", err.Severity, test.severity)
}
}
}
func testIO(c Client, t *testing.T) {
tests := []struct {
Index int
Type
Id int
Value string
Comment string
}{
{0, Ain, 1, "0", ""},
{1, Aout, 1, "0", "test"},
{2, Gin, 1, "0", "RecipeReadData"},
{3, Gout, 1, "0", "RecipeEchoData"},
{4, Uin, 1, "OFF", "*IMSTP"},
{12, Uin, 9, "OFF", "RSR1/PNS1/STYLE1"},
}
io, err := c.IO(Ain, Aout, Gin, Gout, Uin, Uout)
if err != nil {
t.Fatal(err)
}
if len(io) < len(tests) {
t.Fatalf("Only got %d signals. Need at least %d", len(io), len(tests))
}
for _, test := range tests {
bit := io[test.Index]
if bit.Type != test.Type {
t.Errorf("Bad type. Got %s, want %s", bit.Type, test.Type)
}
if bit.Id != test.Id {
t.Errorf("Bad id. Got %d, want %d", bit.Id, test.Id)
}
if bit.Comment != test.Comment {
t.Errorf("Bad comment. Got %q, want %q", bit.Comment, test.Comment)
}
}
}
func TestNewClient(t *testing.T) {
c, err := NewClient(".")
if err != nil {
t.Fatal(err)
}
if _, ok := c.(*FileClient); !ok {
t.Errorf("Bad type. Got %T, want *FileClient", c)
}
c, err = NewClient("127.0.0.1")
if err != nil {
t.Fatal(err)
}
if _, ok := c.(*HTTPClient); !ok {
t.Errorf("Bad type. Got %T, want *HTTPClient", c)
}
}
func testTPPrograms(c Client, t *testing.T) {
names, err := c.TPPrograms()
if err != nil {
t.Fatal(err)
}
exp := []string{
"A.TP",
"BG.TP",
"CALL.TP",
"CSTN_SERVER.TP",
"GETDATA.TP",
"GET_FSTN_PART.TP",
"PK_PLC_RECIPE_OPERATION.TP",
"PROMPTOK.TP",
"REQMENU.TP",
"SENDDATA.TP",
"SENDEVNT.TP",
"SENDSYSV.TP",
"SUB.TP",
"S_FAULT.TP",
"S_SETUP_OUTFEED_OFFSETS.TP",
"S_SET_PR.TP",
"S_TEST_SETUP_OUTFEED_OFFSETS.TP",
"TEST123.TP",
"TESTA.TP",
}
if len(names) != 19 {
t.Fatalf("bad names len: got %d, want %d", len(names), 19)
}
for i, e := range exp {
if names[i] != e {
t.Errorf("bad name. got %q, want %q", names[i], e)
}
}
}
func testTPPositions(c Client, t *testing.T) {
positions, err := c.TPPositions("TEST.TP")
if err != nil {
t.Fatal(err)
}
exp := []Position{
Position{
Id: 1,
Comment: "",
Group: 1,
Rep: Cartesian,
Uframe: 0,
Utool: 1,
Config: Config{
Flip: false,
Up: true,
Top: true,
TurnCounts: [3]int{0, 0, 0},
},
X: float32(1295.220),
Y: float32(-398.168),
Z: float32(1301.202),
W: float32(-31.64),
P: float32(88.218),
R: float32(147.54),
},
Position{
Id: 2,
Comment: "test 123",
Group: 1,
Rep: Cartesian,
Uframe: 0,
Utool: 1,
Config: Config{
Flip: true,
Up: false,
Top: false,
TurnCounts: [3]int{-1, -1, 1},
},
X: float32(1153.583),
Y: float32(-1754.161),
Z: float32(493.036),
W: float32(90.147),
P: float32(0.582),
R: float32(-0.593),
},
}
if len(positions) != len(exp) {
t.Errorf("bad # of positions. got %d, want %d", len(positions), len(exp))
}
for i, e := range exp {
if positions[i].Id != e.Id {
t.Errorf("Bad id. Got %d, want %d", positions[i].Id, e.Id)
}
if positions[i].Comment != e.Comment {
t.Errorf("bad comment. got %q, want %q", positions[i].Comment, e.Comment)
}
if positions[i].Group != e.Group {
t.Errorf("Bad group. Got %d, want %d", positions[i].Group, e.Group)
}
if positions[i].Uframe != e.Uframe {
t.Errorf("Bad uframe. Got %d, want %d", positions[i].Uframe, e.Uframe)
}
if positions[i].Utool != e.Utool {
t.Errorf("Bad utool. Got %d, want %d", positions[i].Utool, e.Utool)
}
if positions[i].Config != e.Config {
t.Errorf("bad config.top got %v, want %v", positions[i].Config, e.Config)
}
if positions[i].X != e.X {
t.Errorf("bad X. got %f, want %f", positions[i].X, e.X)
}
}
}