forked from openatx/atx-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminitouch_test.go
70 lines (62 loc) · 1.51 KB
/
minitouch_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
package main
import (
"bytes"
"net"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
type MockConn struct {
buffer *bytes.Buffer
}
func (c *MockConn) Read(b []byte) (n int, err error) {
return c.buffer.Read(b)
}
func (c *MockConn) Write(b []byte) (n int, err error) {
return c.buffer.Write(b)
}
func (c *MockConn) Close() error { return nil }
func (c *MockConn) LocalAddr() net.Addr { return nil }
func (c *MockConn) RemoteAddr() net.Addr { return nil }
func (c *MockConn) SetDeadline(t time.Time) error { return nil }
func (c *MockConn) SetReadDeadline(t time.Time) error { return nil }
func (c *MockConn) SetWriteDeadline(t time.Time) error { return nil }
func TestDrainTouchRequests(t *testing.T) {
reqC := make(chan TouchRequest, 0)
conn := &MockConn{
buffer: bytes.NewBuffer(nil),
}
err := drainTouchRequests(conn, reqC)
assert.Error(t, err)
conn = &MockConn{
buffer: bytes.NewBufferString(`v 1
^ 10 1080 1920 255
$ 25654`),
}
reqC = make(chan TouchRequest, 4)
reqC <- TouchRequest{
Operation: "d",
Index: 1,
PercentX: 1.0,
PercentY: 1.0,
Pressure: 1,
}
reqC <- TouchRequest{
Operation: "c",
}
reqC <- TouchRequest{
Operation: "m",
Index: 3,
PercentX: 0.5,
PercentY: 0.5,
Pressure: 1,
}
reqC <- TouchRequest{
Operation: "u",
Index: 4,
}
close(reqC)
drainTouchRequests(conn, reqC)
output := string(conn.buffer.Bytes())
assert.Equal(t, "d 1 1080 1920 255\nc\nm 3 540 960 255\nu 4\n", output)
}