-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
54 changed files
with
1,270 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
146 changes: 146 additions & 0 deletions
146
Assets/AdncAnimatorHelpers/Editor/Testing/AnimatorStub/TestAnimatorStub.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
using Adnc.Utility.Testing; | ||
using Adnc.AnimatorHelpers.Editors.Testing.Utilities; | ||
using NUnit.Framework; | ||
using UnityEngine; | ||
|
||
namespace Adnc.AnimatorHelpers.Editors.Testing { | ||
public class TestAnimatorStub : TestBase { | ||
private GameObject _go; | ||
private AnimatorStub _animStub; | ||
|
||
[SetUp] | ||
public void Setup () { | ||
_go = new GameObject("AnimatorStub"); | ||
} | ||
|
||
[TearDown] | ||
public void Teardown () { | ||
Object.DestroyImmediate(_go); | ||
} | ||
|
||
[Test] | ||
public void DoesNotFailCreationIfNoGameObject () { | ||
var stub = new AnimatorStub(null); | ||
|
||
Assert.IsTrue(stub.IsValid); | ||
} | ||
|
||
[Test] | ||
public void CreatesIfGameObjectPassedIn () { | ||
var stub = new AnimatorStub(_go); | ||
|
||
Assert.IsTrue(stub.IsValid); | ||
} | ||
|
||
[Test] | ||
public void AttachRuntimeController () { | ||
var stub = new AnimatorStub(_go); | ||
|
||
stub.InjectCtrl(); | ||
|
||
Assert.AreSame(stub.Animator.runtimeAnimatorController, stub.AnimatorCtrl); | ||
} | ||
|
||
[Test] | ||
public void GetAnimatorParameter () { | ||
var stub = new AnimatorStub(_go); | ||
const string param = "test"; | ||
|
||
stub.AnimatorCtrl.AddParameter(param, AnimatorControllerParameterType.Bool); | ||
stub.InjectCtrl(); | ||
var result = stub.Animator.GetBool(param); | ||
|
||
Assert.IsFalse(result); | ||
} | ||
|
||
[Test] | ||
public void SetAnimatorParameter () { | ||
var stub = new AnimatorStub(_go); | ||
const string param = "test"; | ||
|
||
stub.AnimatorCtrl.AddParameter(param, AnimatorControllerParameterType.Bool); | ||
stub.InjectCtrl(); | ||
stub.Animator.SetBool(param, true); | ||
var result = stub.Animator.GetBool(param); | ||
|
||
Assert.IsTrue(result); | ||
} | ||
|
||
[Test] | ||
public void CreateNewLayerReturnsLayer () { | ||
var stub = new AnimatorStub(_go); | ||
var layer = stub.AddLayer("Test"); | ||
|
||
Assert.IsNotNull(layer); | ||
} | ||
|
||
[Test] | ||
public void CreateNewLayerAddsAnotherLayer () { | ||
var stub = new AnimatorStub(_go); | ||
stub.AddLayer("Test"); | ||
|
||
Assert.AreEqual(stub.AnimatorCtrl.layers.Length, 2); | ||
} | ||
|
||
[Test] | ||
public void CreateNewLayerSetsName () { | ||
var layerName = "Test"; | ||
var stub = new AnimatorStub(_go); | ||
var layer = stub.AddLayer(layerName); | ||
|
||
Assert.AreEqual(layerName, layer.name); | ||
} | ||
|
||
[Test] | ||
public void CreateNewLayerSetsStateMachine () { | ||
var stub = new AnimatorStub(_go); | ||
var layer = stub.AddLayer("Test"); | ||
|
||
Assert.IsNotNull(layer.stateMachine); | ||
} | ||
|
||
[Test] | ||
public void CreateNewLayerCreatesAtLeastOneState () { | ||
var stub = new AnimatorStub(_go); | ||
var layer = stub.AddLayer("Test"); | ||
|
||
Assert.IsTrue(layer.stateMachine.states.Length >= 1); | ||
} | ||
|
||
[Test] | ||
public void CreateNewLayerSetsDefaultState () { | ||
var stub = new AnimatorStub(_go); | ||
var layer = stub.AddLayer("Test"); | ||
|
||
Assert.IsNotNull(layer.stateMachine.defaultState); | ||
} | ||
|
||
[Test] | ||
public void PlayAdvancesToTheNextState () { | ||
var stub = new AnimatorStub(_go); | ||
var layer = stub.AnimatorCtrl.layers[0]; | ||
const string stateName = "New State"; | ||
var state = layer.stateMachine.AddState(stateName); | ||
var trans = layer.stateMachine.defaultState.AddTransition(state); | ||
|
||
layer.stateMachine.defaultState.AddTransition(state); | ||
trans.hasExitTime = true; | ||
stub.InjectCtrl(); | ||
stub.Animator.Update(10); | ||
|
||
var stateInfo = stub.Animator.GetCurrentAnimatorStateInfo(0); | ||
Assert.IsTrue(stateInfo.IsName(stateName)); | ||
} | ||
|
||
[Test] | ||
public void RuntimeControllerNameSameAsCreationName () { | ||
var stub = new AnimatorStub(_go); | ||
|
||
stub.AnimatorCtrl.name = "asdf"; | ||
stub.InjectCtrl(); | ||
|
||
Assert.AreEqual(stub.AnimatorCtrl.name, stub.Animator.runtimeAnimatorController.name); | ||
Assert.AreNotEqual(stub.Animator.gameObject.name, stub.Animator.runtimeAnimatorController.name); | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
Assets/AdncAnimatorHelpers/Editor/Testing/AnimatorStub/TestAnimatorStub.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
105 changes: 105 additions & 0 deletions
105
Assets/AdncAnimatorHelpers/Editor/Testing/HasParameter/TestAnimatorParameters.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
using System; | ||
using Adnc.AnimatorHelpers.Editors.Testing.Utilities; | ||
using Adnc.AnimatorHelpers.HasParameters; | ||
using Adnc.Utility.Testing; | ||
using NUnit.Framework; | ||
using UnityEngine; | ||
using Object = UnityEngine.Object; | ||
|
||
namespace Adnc.AnimatorHelpers.Editors.Testing.HasParameters { | ||
[TestFixture(Category = "HasParameter")] | ||
public class TestAnimatorParameters : TestBase { | ||
private AnimatorStub _stub; | ||
|
||
[SetUp] | ||
public void Setup () { | ||
_stub = new AnimatorStub(); | ||
} | ||
|
||
[TearDown] | ||
public void Teardown () { | ||
Object.DestroyImmediate(_stub.Animator.gameObject); | ||
_stub = null; | ||
} | ||
|
||
[Test] | ||
public void ErrorsOnNullAnimatorConstructor () { | ||
Assert.Throws<ArgumentNullException>(() => { new AnimatorParameters(null); }); | ||
} | ||
|
||
[Test] | ||
public void DoesNotCrashOnNullAnimatorParameters () { | ||
_stub.InjectCtrl(); | ||
var par = new AnimatorParameters(_stub.Animator); | ||
} | ||
|
||
[Test] | ||
public void StoresAllParameters () { | ||
_stub.AnimatorCtrl.AddParameter(new AnimatorControllerParameter { | ||
name = "a", | ||
defaultBool = true, | ||
type = AnimatorControllerParameterType.Bool | ||
}); | ||
|
||
_stub.InjectCtrl(); | ||
var par = new AnimatorParameters(_stub.Animator); | ||
|
||
Assert.IsTrue(par.parameters.dic.ContainsKey("a")); | ||
} | ||
|
||
[Test] | ||
public void StoresAllBools () { | ||
_stub.AnimatorCtrl.AddParameter(new AnimatorControllerParameter { | ||
name = "a", | ||
defaultBool = true, | ||
type = AnimatorControllerParameterType.Bool | ||
}); | ||
|
||
_stub.InjectCtrl(); | ||
var par = new AnimatorParameters(_stub.Animator); | ||
|
||
Assert.IsTrue(par.bools.dic.ContainsKey("a")); | ||
} | ||
|
||
[Test] | ||
public void StoresAllFloats () { | ||
_stub.AnimatorCtrl.AddParameter(new AnimatorControllerParameter { | ||
name = "a", | ||
defaultFloat = 1, | ||
type = AnimatorControllerParameterType.Float | ||
}); | ||
|
||
_stub.InjectCtrl(); | ||
var par = new AnimatorParameters(_stub.Animator); | ||
|
||
Assert.IsTrue(par.floats.dic.ContainsKey("a")); | ||
} | ||
|
||
[Test] | ||
public void StoresAllInts () { | ||
_stub.AnimatorCtrl.AddParameter(new AnimatorControllerParameter { | ||
name = "a", | ||
defaultInt = 1, | ||
type = AnimatorControllerParameterType.Int | ||
}); | ||
|
||
_stub.InjectCtrl(); | ||
var par = new AnimatorParameters(_stub.Animator); | ||
|
||
Assert.IsTrue(par.ints.dic.ContainsKey("a")); | ||
} | ||
|
||
[Test] | ||
public void StoresAllTriggers () { | ||
_stub.AnimatorCtrl.AddParameter(new AnimatorControllerParameter { | ||
name = "a", | ||
type = AnimatorControllerParameterType.Trigger | ||
}); | ||
|
||
_stub.InjectCtrl(); | ||
var par = new AnimatorParameters(_stub.Animator); | ||
|
||
Assert.IsTrue(par.triggers.dic.ContainsKey("a")); | ||
} | ||
} | ||
} |
Oops, something went wrong.