-
-
Notifications
You must be signed in to change notification settings - Fork 229
/
Copy pathrender_test.go
89 lines (75 loc) · 2.19 KB
/
render_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
package sdl
import (
"errors"
"testing"
)
func TestRenderIntegerScale(t *testing.T) {
_, r, err := CreateWindowAndRenderer(50, 50, 0)
if err != nil {
t.Fatalf("unable to create renderer: %s", err)
return
}
errUnsupported := errors.New("That operation is not supported")
if !VERSION_ATLEAST(2, 0, 5) {
t.Run("GetIntegerScale on versions < 2.0.5 should return unsupported", func(t *testing.T) {
_, got := r.GetIntegerScale()
if got.Error() != errUnsupported.Error() {
t.Fatalf("expected call to GetIntegerScale to fail with %s, got %s", errUnsupported, got)
}
})
t.Run("SetIntegerScale on versions < 2.0.5 should return unsupported", func(t *testing.T) {
got := r.SetIntegerScale(false)
if got.Error() != errUnsupported.Error() {
t.Fatalf("expected call to SetIntegerScale to fail with %s, got %s", errUnsupported, got)
}
})
return
}
set := func(v bool, t *testing.T) {
if err := r.SetIntegerScale(v); err != nil {
t.Fatalf("unable to set scale %v: %s", v, err)
}
}
check := func(want bool, t *testing.T) {
got, err := r.GetIntegerScale()
if err != nil {
t.Fatalf("unable to get scale: %s", err)
}
if got != want {
t.Fatalf("wanted renderer scale to be %v", want)
}
}
t.Run("should start out as false", func(t *testing.T) {
check(false, t)
})
t.Run("if set to true should return true", func(t *testing.T) {
set(true, t)
check(true, t)
})
t.Run("if set to false should return false", func(t *testing.T) {
set(true, t)
check(true, t)
set(false, t)
check(false, t)
})
t.Run("should handle SDL_FALSE return on GetIntegerScale", func(t *testing.T) {
_, dummy, err := CreateWindowAndRenderer(50, 50, 0)
if err != nil {
t.Fatalf("unable to create renderer: %s", err)
return
}
if err := dummy.SetIntegerScale(true); err != nil {
t.Fatalf("expected call to SetIntegerScale to succeed, got %s", err)
}
if err := dummy.Destroy(); err != nil {
t.Fatalf("expected call to Destroy to succeed, got %s", err)
}
v, err := dummy.GetIntegerScale()
if err == nil {
t.Fatalf("expected call to GetIntegerScale on ivalid renderer to fail")
}
if v != false {
t.Fatalf("wanted renderer scale to be %v", false)
}
})
}