1
+ using Adnc . AnimatorHelpers . Editors . Testing . Utilities ;
2
+ using Adnc . AnimatorHelpers . HasParameters ;
3
+ using Adnc . Utility . Testing ;
4
+ using NUnit . Framework ;
5
+ using UnityEngine ;
6
+
7
+ namespace Adnc . AnimatorHelpers . Editors . Testing . HasParameters {
8
+ [ TestFixture ( Category = "HasParameter" ) ]
9
+ public class TestHasParametersExtensions : TestBase {
10
+ private AnimatorStub _stub ;
11
+ private AnimatorHelperRuntime _runtime ;
12
+
13
+ [ SetUp ]
14
+ public void Setup ( ) {
15
+ _runtime = new GameObject ( "AnimatorRuntime" ) . AddComponent < AnimatorHelperRuntime > ( ) ;
16
+ _stub = new AnimatorStub ( ) ;
17
+
18
+ _stub . AnimatorCtrl . AddParameter ( new AnimatorControllerParameter {
19
+ name = "bool" ,
20
+ type = AnimatorControllerParameterType . Bool
21
+ } ) ;
22
+
23
+ _stub . AnimatorCtrl . AddParameter ( new AnimatorControllerParameter {
24
+ name = "float" ,
25
+ type = AnimatorControllerParameterType . Float
26
+ } ) ;
27
+
28
+ _stub . AnimatorCtrl . AddParameter ( new AnimatorControllerParameter {
29
+ name = "int" ,
30
+ type = AnimatorControllerParameterType . Int
31
+ } ) ;
32
+
33
+ _stub . AnimatorCtrl . AddParameter ( new AnimatorControllerParameter {
34
+ name = "trigger" ,
35
+ type = AnimatorControllerParameterType . Trigger
36
+ } ) ;
37
+ }
38
+
39
+ [ TearDown ]
40
+ public void Teardown ( ) {
41
+ Object . DestroyImmediate ( _stub . Animator . gameObject ) ;
42
+ _stub = null ;
43
+
44
+ AnimatorHelperRuntime . ClearSingleton ( ) ;
45
+ _runtime = null ;
46
+ }
47
+
48
+ [ Test ]
49
+ public void HasParameterDoesNotFailOnMultipleIdenticalKeyNames ( ) {
50
+ _stub . AnimatorCtrl . AddParameter ( new AnimatorControllerParameter {
51
+ name = "bool" ,
52
+ type = AnimatorControllerParameterType . Float
53
+ } ) ;
54
+
55
+ _stub . InjectCtrl ( ) ;
56
+
57
+ Assert . IsTrue ( _stub . Animator . HasParameter ( "bool" ) ) ;
58
+ }
59
+
60
+ [ Test ]
61
+ public void HasParameterWorksWithPreCaching ( ) {
62
+ _stub . InjectCtrl ( ) ;
63
+ AnimatorHelperRuntime . Instance . Cache ( _stub . Animator ) ;
64
+ var id = _stub . Animator . runtimeAnimatorController . name ;
65
+
66
+ Assert . IsTrue ( AnimatorHelperRuntime . Instance . parameters . HasParameters ( id ) ) ;
67
+ Assert . IsTrue ( _stub . Animator . HasParameter ( "bool" ) ) ;
68
+ }
69
+
70
+ // @TODO Move cahce test onto a AnimatorHelperRuntime testing class
71
+ [ Test ]
72
+ public void HasParameterGetsTheSameParameterCacheAcrossAnimatorControllers ( ) {
73
+ _stub . InjectCtrl ( ) ;
74
+ _stub . Animator . HasParameter ( "bool" ) ;
75
+
76
+ var clone = Object . Instantiate ( _stub . Animator . gameObject ) . GetComponent < Animator > ( ) ;
77
+ var id = clone . runtimeAnimatorController . name ;
78
+
79
+ Assert . IsTrue ( AnimatorHelperRuntime . Instance . parameters . HasParameters ( id ) ) ;
80
+
81
+ Assert . IsTrue ( clone . HasParameter ( "bool" ) ) ;
82
+ }
83
+
84
+ [ Test ]
85
+ public void HasParameterReturnsTrue ( ) {
86
+ _stub . InjectCtrl ( ) ;
87
+
88
+ Assert . IsTrue ( _stub . Animator . HasParameter ( "bool" ) ) ;
89
+ }
90
+
91
+ [ Test ]
92
+ public void HasParameterReturnsFalse ( ) {
93
+ _stub . InjectCtrl ( ) ;
94
+
95
+ Assert . IsFalse ( _stub . Animator . HasParameter ( "asdf" ) ) ;
96
+ }
97
+
98
+ [ Test ]
99
+ public void HasParameterEmptyReturnsFalse ( ) {
100
+ _stub . InjectCtrl ( ) ;
101
+
102
+ Assert . IsFalse ( _stub . Animator . HasParameter ( "" ) ) ;
103
+ }
104
+
105
+ [ Test ]
106
+ public void HasParameterNullReturnsFalse ( ) {
107
+ _stub . InjectCtrl ( ) ;
108
+
109
+ Assert . IsFalse ( _stub . Animator . HasParameter ( null ) ) ;
110
+ }
111
+
112
+ [ Test ]
113
+ public void HasBoolReturnsTrue ( ) {
114
+ _stub . InjectCtrl ( ) ;
115
+
116
+ Assert . IsTrue ( _stub . Animator . HasBool ( "bool" ) ) ;
117
+ }
118
+
119
+ [ Test ]
120
+ public void HasBoolReturnsFalse ( ) {
121
+ _stub . InjectCtrl ( ) ;
122
+
123
+ Assert . IsFalse ( _stub . Animator . HasBool ( "asdf" ) ) ;
124
+ }
125
+
126
+ [ Test ]
127
+ public void HasBoolEmptyReturnsFalse ( ) {
128
+ _stub . InjectCtrl ( ) ;
129
+
130
+ Assert . IsFalse ( _stub . Animator . HasBool ( "" ) ) ;
131
+ }
132
+
133
+ [ Test ]
134
+ public void HasBoolNullReturnsFalse ( ) {
135
+ _stub . InjectCtrl ( ) ;
136
+
137
+ Assert . IsFalse ( _stub . Animator . HasBool ( null ) ) ;
138
+ }
139
+
140
+ [ Test ]
141
+ public void HasFloatReturnsTrue ( ) {
142
+ _stub . InjectCtrl ( ) ;
143
+
144
+ Assert . IsTrue ( _stub . Animator . HasFloat ( "float" ) ) ;
145
+ }
146
+
147
+ [ Test ]
148
+ public void HasFloatReturnsFalse ( ) {
149
+ _stub . InjectCtrl ( ) ;
150
+
151
+ Assert . IsFalse ( _stub . Animator . HasFloat ( "asdf" ) ) ;
152
+ }
153
+
154
+ [ Test ]
155
+ public void HasFloatEmptyReturnsFalse ( ) {
156
+ _stub . InjectCtrl ( ) ;
157
+
158
+ Assert . IsFalse ( _stub . Animator . HasFloat ( "" ) ) ;
159
+ }
160
+
161
+ [ Test ]
162
+ public void HasFloatNullReturnsFalse ( ) {
163
+ _stub . InjectCtrl ( ) ;
164
+
165
+ Assert . IsFalse ( _stub . Animator . HasFloat ( null ) ) ;
166
+ }
167
+
168
+ [ Test ]
169
+ public void HasIntReturnsTrue ( ) {
170
+ _stub . InjectCtrl ( ) ;
171
+
172
+ Assert . IsTrue ( _stub . Animator . HasInt ( "int" ) ) ;
173
+ }
174
+
175
+ [ Test ]
176
+ public void HasIntReturnsFalse ( ) {
177
+ _stub . InjectCtrl ( ) ;
178
+
179
+ Assert . IsFalse ( _stub . Animator . HasInt ( "asdf" ) ) ;
180
+ }
181
+
182
+ [ Test ]
183
+ public void HasIntEmptyReturnsFalse ( ) {
184
+ _stub . InjectCtrl ( ) ;
185
+
186
+ Assert . IsFalse ( _stub . Animator . HasInt ( "" ) ) ;
187
+ }
188
+
189
+ [ Test ]
190
+ public void HasIntNullReturnsFalse ( ) {
191
+ _stub . InjectCtrl ( ) ;
192
+
193
+ Assert . IsFalse ( _stub . Animator . HasInt ( null ) ) ;
194
+ }
195
+
196
+ [ Test ]
197
+ public void HasTriggerReturnsTrue ( ) {
198
+ _stub . InjectCtrl ( ) ;
199
+
200
+ Assert . IsTrue ( _stub . Animator . HasTrigger ( "trigger" ) ) ;
201
+ }
202
+
203
+ [ Test ]
204
+ public void HasTriggerReturnsFalse ( ) {
205
+ _stub . InjectCtrl ( ) ;
206
+
207
+ Assert . IsFalse ( _stub . Animator . HasTrigger ( "asdf" ) ) ;
208
+ }
209
+
210
+ [ Test ]
211
+ public void HasTriggerEmptyReturnsFalse ( ) {
212
+ _stub . InjectCtrl ( ) ;
213
+
214
+ Assert . IsFalse ( _stub . Animator . HasTrigger ( "" ) ) ;
215
+ }
216
+
217
+ [ Test ]
218
+ public void HasTriggerNullReturnsFalse ( ) {
219
+ _stub . InjectCtrl ( ) ;
220
+
221
+ Assert . IsFalse ( _stub . Animator . HasTrigger ( null ) ) ;
222
+ }
223
+ }
224
+ }
0 commit comments