43 lines
989 B
Go
43 lines
989 B
Go
package device
|
|
|
|
import (
|
|
"image/jpeg"
|
|
"net/http"
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestLocalPhonePreview(t *testing.T) {
|
|
serial := os.Getenv("ITUOKE_TEST_DEVICE")
|
|
if serial == "" {
|
|
t.Skip("local phone integration only")
|
|
}
|
|
s := &Service{}
|
|
defer s.StopPreviewStream()
|
|
for attempt := 0; attempt < 2; attempt++ {
|
|
started := time.Now()
|
|
result := s.StartPreviewStream(serial)
|
|
if !result.OK {
|
|
t.Fatal(result.Message)
|
|
}
|
|
client := &http.Client{Timeout: 3 * time.Second}
|
|
res, err := client.Get(strings.Replace(result.Message, "/mjpeg", "/snap.jpg", 1))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
img, err := jpeg.Decode(res.Body)
|
|
res.Body.Close()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Logf("attempt %d: first JPEG %dx%d in %s", attempt+1, img.Bounds().Dx(), img.Bounds().Dy(), time.Since(started))
|
|
if attempt == 0 {
|
|
// A static screen must not disconnect after the former 20-second timeout.
|
|
time.Sleep(22 * time.Second)
|
|
}
|
|
s.StopPreviewStream()
|
|
}
|
|
}
|