代码拉取完成,页面将自动刷新
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)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。