Files
go-worm/lib/capture/protocol_test.go
T
kato a3c78820ed refactor(capture): screen capture in subprocess
- Move screen capture to child process
- Isolate GDI/BitBlt crashes from agent
- Use -capture flag for internal helper mode
- Add protocol for frame request/response
- Make monitor enumeration thread-safe
2026-09-01 23:25:38 +03:00

54 lines
1.3 KiB
Go

package capture
import (
"bufio"
"bytes"
"testing"
"tea.chunkbyte.com/kato/go-worm/lib/models"
)
func TestCaptureProtocolRoundTrip(t *testing.T) {
t.Parallel()
var buf bytes.Buffer
if err := writeRequest(&buf, 1, "jpeg", 40); err != nil {
t.Fatal(err)
}
mon, format, quality, err := readRequest(bufio.NewReader(bytes.NewReader(buf.Bytes())))
if err != nil {
t.Fatal(err)
}
if mon != 1 || format != "jpeg" || quality != 40 {
t.Fatalf("request = %d %s %d", mon, format, quality)
}
buf.Reset()
want := models.CapturedImage{
ContentType: "image/jpeg",
Data: []byte{0xff, 0xd8, '\n', 0x00, 0xff},
Left: 10, Top: 20, Width: 100, Height: 50,
}
if err := writeFrame(&buf, want); err != nil {
t.Fatal(err)
}
got, err := readResponse(bufio.NewReader(&buf))
if err != nil {
t.Fatal(err)
}
if got.ContentType != want.ContentType || got.Left != want.Left || got.Width != want.Width || !bytes.Equal(got.Data, want.Data) {
t.Fatalf("frame mismatch: %#v", got)
}
}
func TestCaptureProtocolError(t *testing.T) {
t.Parallel()
var buf bytes.Buffer
if err := writeErr(&buf, "no displays found"); err != nil {
t.Fatal(err)
}
_, err := readResponse(bufio.NewReader(&buf))
if err == nil || err.Error() != "no displays found" {
t.Fatalf("err = %v", err)
}
}