1package core_test
2
3import (
4 "testing"
5 "time"
6
7 "github.com/bnema/neferwl/internal/ports"
8)
9
10func sceneFor(set []ports.Scene, output string) ports.Scene {
11 for _, s := range set {
12 if s.Output == output {
13 return s
14 }
15 }
16 return ports.Scene{}
17}
18
19// A page flip of one output advances only that output's springs: the other
20// output keeps its scene (and Seq) until its own flip.
21func TestFlipAdvancesOnlyItsOutput(t *testing.T) {
22 r := startSwipe(t, nil)
23 threeColumns(t, r)
24 second := ports.OutputInfo{Name: "DP-2", Width: 800, Height: 600, RefreshMilli: 60000}
25 r.plug(t, second)
26 r.input <- ports.PointerMotion{X: 1000, Y: 300}
27 scene(t, r.scenes)
28 for id := ports.WindowID(4); id <= 6; id++ {
29 r.mapWindow(t, id)
30 }
31 // A running landing on each output.
32 r.input <- ports.PointerMotion{X: 100, Y: 300}
33 scene(t, r.scenes)
34 r.flick(t, 10, -40, 0)
35 r.input <- ports.PointerMotion{X: 1000, Y: 300}
36 scene(t, r.scenes)
37 r.flick(t, 10, -40, 0)
38 r.drain()
39
40 // The first flip of each output moves its columns.
41 r.advance(32 * time.Millisecond)
42 r.frames <- ports.OutputFrame{Output: wide.Name}
43 set := receive(t, r.scenes)
44 a, b := sceneFor(set, wide.Name), sceneFor(set, second.Name)
45 r.advance(32 * time.Millisecond)
46 r.frames <- ports.OutputFrame{Output: second.Name}
47 set = receive(t, r.scenes)
48 a2, b2 := sceneFor(set, wide.Name), sceneFor(set, second.Name)
49 if a2.Seq != a.Seq || !a2.SameAs(a) {
50 t.Fatalf("DP-1 changed on a flip of DP-2: Seq %d, was %d", a2.Seq, a.Seq)
51 }
52 if b2.Seq <= b.Seq || b2.SameAs(b) {
53 t.Fatalf("DP-2 did not move on its own flip: Seq %d, was %d", b2.Seq, b.Seq)
54 }
55
56 // And the other way round.
57 r.advance(32 * time.Millisecond)
58 r.frames <- ports.OutputFrame{Output: wide.Name}
59 set = receive(t, r.scenes)
60 a3, b3 := sceneFor(set, wide.Name), sceneFor(set, second.Name)
61 if a3.Seq <= a2.Seq || a3.SameAs(a2) {
62 t.Fatalf("DP-1 did not move on its own flip: Seq %d, was %d", a3.Seq, a2.Seq)
63 }
64 if b3.Seq != b2.Seq || !b3.SameAs(b2) {
65 t.Fatalf("DP-2 changed on a flip of DP-1: Seq %d, was %d", b3.Seq, b2.Seq)
66 }
67}