-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
animation_test.go
94 lines (81 loc) · 1.96 KB
/
animation_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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// +build !ci !darwin
package animation
import (
"sync"
"testing"
"time"
"github.com/stretchr/testify/assert"
"fyne.io/fyne/v2"
)
func TestGLDriver_StartAnimation(t *testing.T) {
done := make(chan float32)
run := &Runner{}
a := &fyne.Animation{
Duration: time.Millisecond * 100,
Tick: func(d float32) {
done <- d
}}
run.Start(a)
select {
case d := <-done:
assert.Greater(t, d, float32(0))
case <-time.After(100 * time.Millisecond):
t.Error("animation was not ticked")
}
}
func TestGLDriver_StopAnimation(t *testing.T) {
done := make(chan float32)
run := &Runner{}
a := &fyne.Animation{
Duration: time.Second * 10,
Tick: func(d float32) {
done <- d
}}
run.Start(a)
select {
case d := <-done:
assert.Greater(t, d, float32(0))
case <-time.After(time.Second):
t.Error("animation was not ticked")
}
run.Stop(a)
assert.Zero(t, len(run.animations))
}
func TestGLDriver_StopAnimationImmediatelyAndInsideTick(t *testing.T) {
var wg sync.WaitGroup
run := &Runner{}
// stopping an animation immediately after start, should be effectively removed
// from the internal animation list (first one is added directly to animation list)
a := &fyne.Animation{
Duration: time.Second,
Tick: func(f float32) {},
}
run.Start(a)
run.Stop(a)
// stopping animation inside tick function
for i := 0; i < 10; i++ {
wg.Add(1)
var b *fyne.Animation
b = &fyne.Animation{
Duration: time.Second,
Tick: func(d float32) {
run.Stop(b)
wg.Done()
}}
run.Start(b)
}
// Similar to first part, but in this time this animation should be added and then removed
// from pendingAnimation slice.
c := &fyne.Animation{
Duration: time.Second,
Tick: func(f float32) {},
}
run.Start(c)
run.Stop(c)
wg.Wait()
// animations stopped inside tick are really stopped in the next runner cycle
time.Sleep(time.Second/60 + 100*time.Millisecond)
run.animationMutex.RLock()
assert.Zero(t, len(run.animations))
run.animationMutex.RUnlock()
}