-
Notifications
You must be signed in to change notification settings - Fork 1
/
io_test.go
53 lines (48 loc) · 996 Bytes
/
io_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
package iec62056
import (
"net"
"reflect"
"testing"
)
func listenWithParity() (net.Conn, Conn) {
go func() {
rv, _ := listener.Accept()
ch <- rv
}()
d := &TCPDialer{
SwParity: true,
}
conn, _ := d.Dial(listener.Addr().String())
return <-ch, conn
}
func Test_FixParity(t *testing.T) {
server, client := listenWithParity()
defer server.Close()
defer client.Close()
td := NewTariffDevice(client)
go func() {
buf := make([]byte, 10)
_, _ = server.Read(buf)
resp := []byte("/ABC6dev\r\n")
for i := 0; i < len(resp); i++ {
resp[i] |= 0x80
}
_, _ = server.Write(resp)
if !reflect.DeepEqual(buf[:5], []byte{175, 63, 33, 141, 10}) {
t.Error("Parity encoding failed")
}
}()
res, err := td.Identity()
if err != nil {
t.Error(err.Error())
}
want := Identity{
Device: "dev",
Manufacturer: "ABC",
Mode: ModeC,
bri: '6',
}
if !reflect.DeepEqual(res, want) {
t.Errorf("Sw Parity failed. wanted %v, got %v", want, res)
}
}