-
Notifications
You must be signed in to change notification settings - Fork 1
/
view_test.go
145 lines (136 loc) · 4.31 KB
/
view_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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// Copyright 2016 Josh Deprez
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package awakengine
import (
"reflect"
"testing"
"github.com/DrJosh9000/vec"
)
func TestViewInvalidation(t *testing.T) {
v := &View{}
v.compute()
if !v.valid {
t.Errorf("After compute, got valid value %t, want true", v.valid)
}
v.invalidate()
if v.valid {
t.Errorf("After invalidate, got valid value %t, want false", v.valid)
}
v.SetBounds(vec.Rect{})
if v.valid {
t.Errorf("After SetBounds, got valid value %t, want false", v.valid)
}
v.Bounds()
if !v.valid {
t.Errorf("After Bounds, got valid value %t, want true", v.valid)
}
v.SetPosition(vec.I2{})
if v.valid {
t.Errorf("After SetOffset, got valid value %t, want false", v.valid)
}
v.Position()
if !v.valid {
t.Errorf("After Offset, got valid value %t, want true", v.valid)
}
v.SetZ(0)
if v.valid {
t.Errorf("After SetZ, got valid value %t, want false", v.valid)
}
v.Z()
if !v.valid {
t.Errorf("After Z, got valid value %t, want true", v.valid)
}
w := &View{}
w.SetParent(v)
if !v.valid {
t.Errorf("After w.SetParent(v), got v.valid value %t, want true", v.valid)
}
if w.valid {
t.Errorf("After w.SetParent(v), got w.valid value %t, want false", w.valid)
}
v.invalidate()
if v.valid {
t.Errorf("After v.invalidate, got v.valid value %t, want false", v.valid)
}
if w.valid {
t.Errorf("After v.invalidate, got w.valid value %t, want false", w.valid)
}
}
func TestSetParent(t *testing.T) {
parent := &View{}
child1 := &View{}
child2 := &View{}
child1.SetParent(parent)
if got, want := parent.children, []*View{child1}; !reflect.DeepEqual(got, want) {
t.Errorf("Got parent.children %v, want %v", got, want)
}
child2.SetParent(parent)
if got, want := parent.children, []*View{child1, child2}; !reflect.DeepEqual(got, want) {
t.Errorf("Got parent.children %v, want %v", got, want)
}
child1.SetParent(child2)
if got, want := parent.children, []*View{child2}; !reflect.DeepEqual(got, want) {
t.Errorf("Got parent.children %v, want %v", got, want)
}
if got, want := child2.children, []*View{child1}; !reflect.DeepEqual(got, want) {
t.Errorf("Got parent.children %v, want %v", got, want)
}
}
func TestSetVisible(t *testing.T) {
parent := &View{}
child1 := &View{}
child2 := &View{}
child1.SetParent(parent)
child2.SetParent(parent)
grandchild1 := &View{}
grandchild1.SetParent(child1)
if got, want := parent.Visible(), true; got != want {
t.Errorf("Got parent.Visible %t, want %t", got, want)
}
if got, want := child1.Visible(), true; got != want {
t.Errorf("Got child1.Visible %t, want %t", got, want)
}
if got, want := child2.Visible(), true; got != want {
t.Errorf("Got child2.Visible %t, want %t", got, want)
}
if got, want := grandchild1.Visible(), true; got != want {
t.Errorf("Got grandchild1.Visible %t, want %t", got, want)
}
child1.SetVisible(false)
if got, want := parent.Visible(), true; got != want {
t.Errorf("Got parent.Visible %t, want %t", got, want)
}
if got, want := child1.Visible(), false; got != want {
t.Errorf("Got child1.Visible %t, want %t", got, want)
}
if got, want := child2.Visible(), true; got != want {
t.Errorf("Got child2.Visible %t, want %t", got, want)
}
if got, want := grandchild1.Visible(), false; got != want {
t.Errorf("Got grandchild1.Visible %t, want %t", got, want)
}
grandchild1.SetVisible(true)
if got, want := parent.Visible(), true; got != want {
t.Errorf("Got parent.Visible %t, want %t", got, want)
}
if got, want := child1.Visible(), false; got != want {
t.Errorf("Got child1.Visible %t, want %t", got, want)
}
if got, want := child2.Visible(), true; got != want {
t.Errorf("Got child2.Visible %t, want %t", got, want)
}
if got, want := grandchild1.Visible(), false; got != want { // No change; child1 is invisible
t.Errorf("Got grandchild1.Visible %t, want %t", got, want)
}
}