Added Grabbing and Socket Editor Tests
This commit is contained in:
parent
c8c2a855c2
commit
221818a81c
8
Tests/Editor/Grabbing.meta
Normal file
8
Tests/Editor/Grabbing.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8294de65677130e4aa29ff95e16f9fc6
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
222
Tests/Editor/Grabbing/GrabbingTest.cs
Normal file
222
Tests/Editor/Grabbing/GrabbingTest.cs
Normal file
@ -0,0 +1,222 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
|
||||
#if pHUMANOID4
|
||||
using NUnit.Framework;
|
||||
using Passer;
|
||||
|
||||
namespace Passer {
|
||||
using Pawn;
|
||||
using Humanoid;
|
||||
|
||||
public class GrabbingTest : IPrebuildSetup {
|
||||
|
||||
public void Setup() {
|
||||
UnityEditor.SceneManagement.EditorSceneManager.OpenScene("[Test]GrabbingHumanoid.unity");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Rigidbody() {
|
||||
// Can be grabbed on any place on the mesh.
|
||||
try {
|
||||
HumanoidControl humanoid = UnityEngine.Object.FindObjectOfType<HumanoidControl>();
|
||||
|
||||
GameObject obj = GameObject.Find("CubeRigidbody");
|
||||
Assert.IsFalse(obj == null);
|
||||
|
||||
#region Grab
|
||||
GameObject grabbedObject = Grab(humanoid, obj);
|
||||
Assert.AreEqual(grabbedObject, obj, "Object is not grabbed");
|
||||
#endregion
|
||||
|
||||
#region LetGo
|
||||
grabbedObject = LetGo(humanoid);
|
||||
Assert.IsTrue(grabbedObject == null, "Object is not released");
|
||||
#endregion
|
||||
}
|
||||
catch (Exception e) {
|
||||
Debug.LogError("Test failed");
|
||||
throw (e);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RigidbodyHandle() {
|
||||
// Can be grabbed on the handle.
|
||||
// Snaps back into the socket when let go.
|
||||
try {
|
||||
Setup();
|
||||
|
||||
HumanoidControl humanoid = UnityEngine.Object.FindObjectOfType<HumanoidControl>();
|
||||
|
||||
GameObject obj = GameObject.Find("CubeWithHandle");
|
||||
Assert.IsFalse(obj == null);
|
||||
|
||||
#region Grab
|
||||
|
||||
GameObject grabbedObject = Grab(humanoid, obj);
|
||||
Assert.AreEqual(grabbedObject, obj);
|
||||
|
||||
#endregion
|
||||
|
||||
#region LetGo
|
||||
grabbedObject = LetGo(humanoid);
|
||||
Assert.IsTrue(grabbedObject == null);
|
||||
#endregion
|
||||
}
|
||||
catch (Exception e) {
|
||||
Debug.LogError("Test failed");
|
||||
throw (e);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void KinematicRigidbodyWithoutPhysics() {
|
||||
// the controller holds the Rigidbody.
|
||||
try {
|
||||
HumanoidControl humanoid = UnityEngine.Object.FindObjectOfType<HumanoidControl>();
|
||||
humanoid.leftHandTarget.physics = false;
|
||||
|
||||
GameObject obj = GameObject.Find("KinematicCube");
|
||||
Assert.IsFalse(obj == null);
|
||||
|
||||
#region Grab
|
||||
GameObject grabbedObject = Grab(humanoid, obj);
|
||||
Assert.AreEqual(grabbedObject, obj);
|
||||
#endregion
|
||||
|
||||
#region LetGo
|
||||
grabbedObject = LetGo(humanoid);
|
||||
Assert.IsTrue(grabbedObject == null);
|
||||
#endregion
|
||||
}
|
||||
catch (Exception e) {
|
||||
Debug.LogError("Test failed");
|
||||
throw (e);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void KinematicRigidbodyWithPhysics() {
|
||||
// the Rigidbody will move the controller.
|
||||
try {
|
||||
HumanoidControl humanoid = UnityEngine.Object.FindObjectOfType<HumanoidControl>();
|
||||
humanoid.leftHandTarget.physics = true;
|
||||
|
||||
GameObject obj = GameObject.Find("KinematicCube");
|
||||
Assert.IsFalse(obj == null);
|
||||
|
||||
#region Grab
|
||||
GameObject grabbedObject = Grab(humanoid, obj);
|
||||
Assert.AreEqual(grabbedObject, obj);
|
||||
#endregion
|
||||
|
||||
#region LetGo
|
||||
grabbedObject = LetGo(humanoid);
|
||||
Assert.IsTrue(grabbedObject == null);
|
||||
#endregion
|
||||
}
|
||||
catch (Exception e) {
|
||||
Debug.LogError("Test failed");
|
||||
throw (e);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void KinematicRigidbodyLimitations() {
|
||||
// the Rigidbody will move the controller.
|
||||
try {
|
||||
HumanoidControl humanoid = UnityEngine.Object.FindObjectOfType<HumanoidControl>();
|
||||
|
||||
GameObject obj = GameObject.Find("KinematicCubeLimitations");
|
||||
Assert.IsFalse(obj == null);
|
||||
|
||||
#region Grab
|
||||
GameObject grabbedObject = Grab(humanoid, obj);
|
||||
Assert.AreEqual(grabbedObject, obj);
|
||||
#endregion
|
||||
|
||||
#region LetGo
|
||||
grabbedObject = LetGo(humanoid);
|
||||
Assert.IsTrue(grabbedObject == null);
|
||||
#endregion
|
||||
}
|
||||
catch (Exception e) {
|
||||
Debug.LogError("Test failed");
|
||||
throw (e);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void StaticObject() {
|
||||
// Static object can not be grabbed
|
||||
try {
|
||||
HumanoidControl humanoid = UnityEngine.Object.FindObjectOfType<HumanoidControl>();
|
||||
|
||||
GameObject obj = GameObject.Find("StaticCube");
|
||||
Assert.IsFalse(obj == null);
|
||||
|
||||
#region Grab
|
||||
GameObject grabbedObject = Grab(humanoid, obj);
|
||||
Assert.IsTrue(grabbedObject == null);
|
||||
#endregion
|
||||
|
||||
#region LetGo
|
||||
grabbedObject = LetGo(humanoid);
|
||||
Assert.IsTrue(grabbedObject == null);
|
||||
#endregion
|
||||
}
|
||||
catch (Exception e) {
|
||||
Debug.LogError("Test failed");
|
||||
throw (e);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void StaticObjectHandle() {
|
||||
// Can be grabbed but cannot move.
|
||||
// When Body Pull is enabled, the position of the pawn will move.
|
||||
try {
|
||||
HumanoidControl humanoid = UnityEngine.Object.FindObjectOfType<HumanoidControl>();
|
||||
|
||||
GameObject obj = GameObject.Find("StaticCubeWithHandle");
|
||||
Assert.IsFalse(obj == null);
|
||||
|
||||
Handle handle = obj.GetComponentInChildren<Handle>();
|
||||
Assert.IsFalse(handle == null);
|
||||
|
||||
#region Grab
|
||||
GameObject grabbedObject = Grab(humanoid, obj);
|
||||
Assert.AreEqual(grabbedObject, handle.gameObject);
|
||||
#endregion
|
||||
|
||||
#region LetGo
|
||||
grabbedObject = LetGo(humanoid);
|
||||
Assert.IsTrue(grabbedObject == null);
|
||||
#endregion
|
||||
}
|
||||
catch (Exception e) {
|
||||
Debug.LogError("Test failed");
|
||||
throw (e);
|
||||
}
|
||||
}
|
||||
|
||||
#region Utilities
|
||||
|
||||
protected GameObject Grab(HumanoidControl humanoid, GameObject obj) {
|
||||
humanoid.leftHandTarget.Grab(obj);
|
||||
return humanoid.leftHandTarget.grabbedObject;
|
||||
}
|
||||
|
||||
protected GameObject LetGo(HumanoidControl humanoid) {
|
||||
humanoid.leftHandTarget.LetGo();
|
||||
return humanoid.leftHandTarget.grabbedObject;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
12
Tests/Editor/Grabbing/GrabbingTest.cs.meta
Normal file
12
Tests/Editor/Grabbing/GrabbingTest.cs.meta
Normal file
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a216cd04d4ed1164ca1e93007ad1bec5
|
||||
timeCreated: 1558946624
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
339
Tests/Editor/Grabbing/GrabbingTestHumanoid.cs
Normal file
339
Tests/Editor/Grabbing/GrabbingTestHumanoid.cs
Normal file
@ -0,0 +1,339 @@
|
||||
/*
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Passer {
|
||||
using Pawn;
|
||||
using Humanoid;
|
||||
|
||||
public class GrabbingTestHumanoid {
|
||||
|
||||
public static string testScene = "GrabbingHumanoid";
|
||||
|
||||
protected void Setup() {
|
||||
UnityEditor.SceneManagement.EditorSceneManager.OpenScene(
|
||||
"Assets/_TestCases/Grabbing/[Test]" + testScene + ".unity");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Rigidbody() {
|
||||
Setup();
|
||||
|
||||
// Can be grabbed on any place on the mesh.
|
||||
try {
|
||||
HumanoidControl humanoid = UnityEngine.Object.FindObjectOfType<HumanoidControl>();
|
||||
PawnControl pawn = null;
|
||||
if (humanoid == null) {
|
||||
pawn = UnityEngine.Object.FindObjectOfType<PawnControl>();
|
||||
Assert.IsFalse(pawn == null);
|
||||
}
|
||||
|
||||
GameObject obj = GameObject.Find("CubeRigidbody");
|
||||
Assert.IsFalse(obj == null);
|
||||
|
||||
#region Grab
|
||||
|
||||
GameObject grabbedObject = Grab(humanoid, pawn, obj);
|
||||
|
||||
Assert.AreEqual(grabbedObject, obj);
|
||||
|
||||
Collider[] colliders = grabbedObject.GetComponentsInChildren<Collider>();
|
||||
foreach (Collider collider in colliders)
|
||||
Assert.IsFalse(collider.isTrigger);
|
||||
|
||||
Assert.AreEqual(grabbedObject.transform.parent, humanoid.leftHandTarget.handRigidbody.transform);
|
||||
|
||||
#endregion
|
||||
|
||||
#region LetGo
|
||||
grabbedObject = LetGo(humanoid, pawn);
|
||||
Assert.IsTrue(grabbedObject == null);
|
||||
#endregion
|
||||
}
|
||||
catch (Exception e) {
|
||||
Debug.LogError("Test failed");
|
||||
throw (e);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RigidbodyHandle() {
|
||||
Setup();
|
||||
|
||||
// Can be grabbed on the handle.
|
||||
// Snaps back into the socket when let go.
|
||||
try {
|
||||
HumanoidControl humanoid = UnityEngine.Object.FindObjectOfType<HumanoidControl>();
|
||||
PawnControl pawn = null;
|
||||
if (humanoid == null) {
|
||||
pawn = UnityEngine.Object.FindObjectOfType<PawnControl>();
|
||||
Assert.IsFalse(pawn == null);
|
||||
}
|
||||
|
||||
GameObject obj = GameObject.Find("CubeWithHandle");
|
||||
Assert.IsFalse(obj == null);
|
||||
|
||||
#region Grab
|
||||
|
||||
GameObject grabbedObject = Grab(humanoid, pawn, obj);
|
||||
|
||||
Assert.AreEqual(grabbedObject, obj);
|
||||
|
||||
Collider[] colliders = grabbedObject.GetComponentsInChildren<Collider>();
|
||||
foreach (Collider collider in colliders)
|
||||
Assert.IsFalse(collider.isTrigger);
|
||||
|
||||
Assert.AreEqual(grabbedObject.transform.parent, humanoid.leftHandTarget.grabSocket.transform);
|
||||
|
||||
#endregion
|
||||
|
||||
#region LetGo
|
||||
grabbedObject = LetGo(humanoid, pawn);
|
||||
Assert.IsTrue(grabbedObject == null);
|
||||
#endregion
|
||||
}
|
||||
catch (Exception e) {
|
||||
Debug.LogError("Test failed");
|
||||
throw (e);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RigidbodyJoint() {
|
||||
Setup();
|
||||
|
||||
// Can be grabbed on the handle.
|
||||
// Snaps back into the socket when let go.
|
||||
try {
|
||||
HumanoidControl humanoid = UnityEngine.Object.FindObjectOfType<HumanoidControl>();
|
||||
PawnControl pawn = null;
|
||||
if (humanoid == null) {
|
||||
pawn = UnityEngine.Object.FindObjectOfType<PawnControl>();
|
||||
Assert.IsFalse(pawn == null);
|
||||
}
|
||||
|
||||
GameObject obj = GameObject.Find("CubeWithJoint");
|
||||
Assert.IsFalse(obj == null);
|
||||
|
||||
#region Grab
|
||||
|
||||
GameObject grabbedObject = Grab(humanoid, pawn, obj);
|
||||
|
||||
Assert.AreEqual(grabbedObject, obj);
|
||||
|
||||
Collider[] colliders = grabbedObject.GetComponentsInChildren<Collider>();
|
||||
foreach (Collider collider in colliders)
|
||||
Assert.IsFalse(collider.isTrigger);
|
||||
|
||||
Assert.AreEqual(grabbedObject.transform.parent, humanoid.leftHandTarget.grabSocket.transform);
|
||||
|
||||
#endregion
|
||||
|
||||
#region LetGo
|
||||
grabbedObject = LetGo(humanoid, pawn);
|
||||
Assert.IsTrue(grabbedObject == null);
|
||||
#endregion
|
||||
}
|
||||
catch (Exception e) {
|
||||
Debug.LogError("Test failed");
|
||||
throw (e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void KinematicRigidbodyWithoutPhysics() {
|
||||
Setup();
|
||||
|
||||
// the controller holds the Rigidbody.
|
||||
try {
|
||||
HumanoidControl humanoid = UnityEngine.Object.FindObjectOfType<HumanoidControl>();
|
||||
PawnControl pawn = null;
|
||||
if (humanoid == null) {
|
||||
pawn = UnityEngine.Object.FindObjectOfType<PawnControl>();
|
||||
Assert.IsFalse(pawn == null);
|
||||
pawn.leftHandTarget.physics = false;
|
||||
}
|
||||
else {
|
||||
humanoid.leftHandTarget.physics = false;
|
||||
}
|
||||
|
||||
GameObject obj = GameObject.Find("KinematicCube");
|
||||
Assert.IsFalse(obj == null);
|
||||
|
||||
#region Grab
|
||||
GameObject grabbedObject = Grab(humanoid, pawn, obj);
|
||||
Assert.AreEqual(grabbedObject, obj);
|
||||
#endregion
|
||||
|
||||
#region LetGo
|
||||
grabbedObject = LetGo(humanoid, pawn);
|
||||
Assert.IsTrue(grabbedObject == null);
|
||||
#endregion
|
||||
}
|
||||
catch (Exception e) {
|
||||
Debug.LogError("Test failed");
|
||||
throw (e);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void KinematicRigidbodyWithPhysics() {
|
||||
Setup();
|
||||
|
||||
// the Rigidbody will move the controller.
|
||||
try {
|
||||
HumanoidControl humanoid = UnityEngine.Object.FindObjectOfType<HumanoidControl>();
|
||||
PawnControl pawn = null;
|
||||
if (humanoid == null) {
|
||||
pawn = UnityEngine.Object.FindObjectOfType<PawnControl>();
|
||||
Assert.IsFalse(pawn == null);
|
||||
pawn.leftHandTarget.physics = true;
|
||||
}
|
||||
else {
|
||||
humanoid.leftHandTarget.physics = true;
|
||||
}
|
||||
|
||||
GameObject obj = GameObject.Find("KinematicCube");
|
||||
Assert.IsFalse(obj == null);
|
||||
|
||||
#region Grab
|
||||
GameObject grabbedObject = Grab(humanoid, pawn, obj);
|
||||
Assert.AreEqual(grabbedObject, obj);
|
||||
#endregion
|
||||
|
||||
#region LetGo
|
||||
grabbedObject = LetGo(humanoid, pawn);
|
||||
Assert.IsTrue(grabbedObject == null);
|
||||
#endregion
|
||||
}
|
||||
catch (Exception e) {
|
||||
Debug.LogError("Test failed");
|
||||
throw (e);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void KinematicRigidbodyLimitations() {
|
||||
Setup();
|
||||
|
||||
// the Rigidbody will move the controller.
|
||||
try {
|
||||
HumanoidControl humanoid = UnityEngine.Object.FindObjectOfType<HumanoidControl>();
|
||||
PawnControl pawn = null;
|
||||
if (humanoid == null) {
|
||||
pawn = UnityEngine.Object.FindObjectOfType<PawnControl>();
|
||||
Assert.IsFalse(pawn == null);
|
||||
}
|
||||
|
||||
GameObject obj = GameObject.Find("KinematicCubeLimitations");
|
||||
Assert.IsFalse(obj == null);
|
||||
|
||||
#region Grab
|
||||
GameObject grabbedObject = Grab(humanoid, pawn, obj);
|
||||
Assert.AreEqual(grabbedObject, obj);
|
||||
#endregion
|
||||
|
||||
#region LetGo
|
||||
grabbedObject = LetGo(humanoid, pawn);
|
||||
Assert.IsTrue(grabbedObject == null);
|
||||
#endregion
|
||||
}
|
||||
catch (Exception e) {
|
||||
Debug.LogError("Test failed");
|
||||
throw (e);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void StaticObject() {
|
||||
Setup();
|
||||
|
||||
// Static object can not be grabbed
|
||||
try {
|
||||
HumanoidControl humanoid = UnityEngine.Object.FindObjectOfType<HumanoidControl>();
|
||||
PawnControl pawn = null;
|
||||
if (humanoid == null) {
|
||||
pawn = UnityEngine.Object.FindObjectOfType<PawnControl>();
|
||||
Assert.IsFalse(pawn == null);
|
||||
}
|
||||
|
||||
GameObject obj = GameObject.Find("StaticCube");
|
||||
Assert.IsFalse(obj == null);
|
||||
|
||||
#region Grab
|
||||
|
||||
GameObject grabbedObject = Grab(humanoid, pawn, obj);
|
||||
Assert.IsTrue(grabbedObject == null);
|
||||
|
||||
#endregion
|
||||
|
||||
#region LetGo
|
||||
grabbedObject = LetGo(humanoid, pawn);
|
||||
Assert.IsTrue(grabbedObject == null);
|
||||
#endregion
|
||||
}
|
||||
catch (Exception e) {
|
||||
Debug.LogError("Test failed");
|
||||
throw (e);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void StaticObjectHandle() {
|
||||
Setup();
|
||||
|
||||
// Can be grabbed but cannot move.
|
||||
// When Body Pull is enabled, the position of the pawn will move.
|
||||
try {
|
||||
HumanoidControl humanoid = UnityEngine.Object.FindObjectOfType<HumanoidControl>();
|
||||
PawnControl pawn = null;
|
||||
if (humanoid == null) {
|
||||
pawn = UnityEngine.Object.FindObjectOfType<PawnControl>();
|
||||
Assert.IsFalse(pawn == null);
|
||||
}
|
||||
|
||||
GameObject obj = GameObject.Find("StaticCubeWithHandle");
|
||||
Assert.IsFalse(obj == null);
|
||||
|
||||
Handle handle = obj.GetComponentInChildren<Handle>();
|
||||
Assert.IsFalse(handle == null);
|
||||
|
||||
#region Grab
|
||||
|
||||
GameObject grabbedObject = Grab(humanoid, pawn, obj);
|
||||
Assert.AreEqual(grabbedObject, handle.gameObject);
|
||||
|
||||
Assert.AreEqual(humanoid.leftHandTarget.hand.bone.transform.parent, handle.transform);
|
||||
|
||||
#endregion
|
||||
|
||||
#region LetGo
|
||||
grabbedObject = LetGo(humanoid, pawn);
|
||||
Assert.IsTrue(grabbedObject == null);
|
||||
#endregion
|
||||
}
|
||||
catch (Exception e) {
|
||||
Debug.LogError("Test failed");
|
||||
throw (e);
|
||||
}
|
||||
}
|
||||
|
||||
#region Utilities
|
||||
|
||||
protected GameObject Grab(HumanoidControl humanoid, PawnControl pawn, GameObject obj) {
|
||||
humanoid.leftHandTarget.Grab(obj, false);
|
||||
return humanoid.leftHandTarget.grabbedObject;
|
||||
}
|
||||
|
||||
protected GameObject LetGo(HumanoidControl humanoid, PawnControl pawn) {
|
||||
humanoid.leftHandTarget.LetGo();
|
||||
return humanoid.leftHandTarget.grabbedObject;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
12
Tests/Editor/Grabbing/GrabbingTestHumanoid.cs.meta
Normal file
12
Tests/Editor/Grabbing/GrabbingTestHumanoid.cs.meta
Normal file
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c1216c052fa7b92489256144c8a3892b
|
||||
timeCreated: 1558946624
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Tests/Editor/Socket.meta
Normal file
8
Tests/Editor/Socket.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 21e5ec4d7a6c9ed4fbcbe173682201b8
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
501
Tests/Editor/Socket/SocketTest.cs
Normal file
501
Tests/Editor/Socket/SocketTest.cs
Normal file
@ -0,0 +1,501 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
|
||||
#if pHUMANOID4
|
||||
using NUnit.Framework;
|
||||
using Passer;
|
||||
using Passer.Humanoid;
|
||||
public class SocketTest : IPrebuildSetup {
|
||||
|
||||
public static string testScene = "Sockets";
|
||||
|
||||
public void Setup() {
|
||||
Debug.Log("Setup SocketTest");
|
||||
UnityEditor.SceneManagement.EditorSceneManager.OpenScene(
|
||||
"Assets/_TestCases/[Test]" + testScene + ".unity");
|
||||
}
|
||||
|
||||
#region Static Socket
|
||||
[Test]
|
||||
[Category("Socket")]
|
||||
public void StaticSocket_RigidbodyHandle() {
|
||||
// Rigidbody handles will get a fixed joint without attachedRigidbody
|
||||
try {
|
||||
|
||||
GameObject socketObj = GameObject.Find("StaticSocket");
|
||||
Socket socket = socketObj.GetComponent<Socket>();
|
||||
Assert.IsFalse(socket == null);
|
||||
|
||||
GameObject handleObj = GameObject.Find("RigidbodyHandle");
|
||||
Handle handle = handleObj.GetComponent<Handle>();
|
||||
Assert.IsFalse(handle == null);
|
||||
|
||||
socket.transform.localPosition = Vector3.zero;
|
||||
handle.transform.localPosition = Vector3.zero;
|
||||
|
||||
Transform socketParent = socket.transform.parent;
|
||||
Transform handleParent = handle.transform.parent;
|
||||
|
||||
Vector3 socketPosition = socket.transform.position;
|
||||
Vector3 handlePosition = handle.transform.position;
|
||||
|
||||
#region Attach
|
||||
socket.Attach(handle.transform, false);
|
||||
|
||||
Joint joint = handle.GetComponent<Joint>();
|
||||
Assert.IsTrue(joint != null);
|
||||
|
||||
Assert.AreEqual(socket.attachedTransform, handle.transform);
|
||||
Assert.AreNotEqual(handle.transform.parent, socket.transform);
|
||||
|
||||
// Handle should be at socket position
|
||||
float distance = Vector3.Distance(socket.transform.position, handle.transform.position);
|
||||
Assert.Less(distance, 0.0001F);
|
||||
// Socket should not have moved
|
||||
distance = Vector3.Distance(socketPosition, socket.transform.position);
|
||||
Assert.Less(distance, 0.0001F);
|
||||
#endregion
|
||||
|
||||
#region Release
|
||||
socket.Release();
|
||||
|
||||
Assert.IsTrue(socket.attachedTransform == null);
|
||||
Assert.AreNotEqual(handle.transform.parent, socket.transform);
|
||||
|
||||
// Handle should still be at socket position
|
||||
distance = Vector3.Distance(socket.transform.position, handle.transform.position);
|
||||
Assert.Less(distance, 0.0001F);
|
||||
#endregion
|
||||
|
||||
}
|
||||
catch (Exception e) {
|
||||
Debug.LogError("Test failed");
|
||||
throw (e);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("Socket")]
|
||||
public void StaticSocket_StaticHandle() {
|
||||
// Static Handles cannot be attached to static sockets
|
||||
try {
|
||||
GameObject socketObj = GameObject.Find("StaticSocket");
|
||||
Socket socket = socketObj.GetComponent<Socket>();
|
||||
Assert.IsTrue(socket != null);
|
||||
|
||||
GameObject handleObj = GameObject.Find("StaticHandle");
|
||||
Handle handle = handleObj.GetComponent<Handle>();
|
||||
Assert.IsTrue(handle != null);
|
||||
|
||||
Transform socketParent = socket.transform.parent;
|
||||
Transform handleParent = handle.transform.parent;
|
||||
|
||||
Vector3 socketPosition = socket.transform.position;
|
||||
Vector3 handlePosition = handle.transform.position;
|
||||
|
||||
#region Attach
|
||||
socket.Attach(handle.transform, false);
|
||||
|
||||
Assert.IsTrue(socket.attachedTransform == null);
|
||||
|
||||
// Handle should not have moved
|
||||
float distance = Vector3.Distance(handle.transform.position, handlePosition);
|
||||
Assert.Less(distance, 0.0001F);
|
||||
// Socket should not have moved
|
||||
distance = Vector3.Distance(socket.transform.position, socketPosition);
|
||||
Assert.Less(distance, 0.0001F);
|
||||
#endregion
|
||||
|
||||
#region Release
|
||||
socket.Release();
|
||||
|
||||
Assert.IsTrue(socket.attachedTransform == null);
|
||||
|
||||
// Handle should not have moved
|
||||
Assert.Less(Vector3.Distance(handle.transform.position, handlePosition), 0.0001F);
|
||||
// Socket should not have moved
|
||||
Assert.Less(Vector3.Distance(socket.transform.position, socketPosition), 0.0001F);
|
||||
|
||||
#endregion
|
||||
|
||||
socket.transform.localPosition = Vector3.zero;
|
||||
handle.transform.localPosition = Vector3.zero;
|
||||
}
|
||||
catch (Exception e) {
|
||||
Debug.LogError("Test failed");
|
||||
throw (e);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("Socket")]
|
||||
public void StaticSocket_KinematicHandle() {
|
||||
// Kinematic Handles should be parented to the socket
|
||||
try {
|
||||
GameObject socketObj = GameObject.Find("StaticSocket");
|
||||
Socket socket = socketObj.GetComponent<Socket>();
|
||||
|
||||
Assert.IsTrue(socket != null);
|
||||
|
||||
GameObject handleObj = GameObject.Find("KinematicHandle");
|
||||
Handle handle = handleObj.GetComponent<Handle>();
|
||||
Assert.IsTrue(handle != null);
|
||||
|
||||
Transform socketParent = socket.transform.parent;
|
||||
Transform handleParent = handle.transform.parent;
|
||||
|
||||
Vector3 socketPosition = socket.transform.position;
|
||||
Vector3 handlePosition = handle.transform.position;
|
||||
|
||||
#region Attach
|
||||
socket.Attach(handle.transform, false);
|
||||
|
||||
Assert.IsTrue(socket.attachedTransform != null);
|
||||
Assert.AreEqual(handle.transform.parent, socket.transform);
|
||||
|
||||
// Handle should be at socket position
|
||||
Assert.Less(Vector3.Distance(socket.transform.position, handle.transform.position), 0.0001F);
|
||||
// Socket should not have moved
|
||||
Assert.Less(Vector3.Distance(socketPosition, socket.transform.position), 0.0001F);
|
||||
#endregion
|
||||
|
||||
#region Release
|
||||
socket.Release();
|
||||
|
||||
Assert.IsTrue(socket.attachedTransform == null);
|
||||
Assert.AreEqual(handle.transform.parent, handleParent);
|
||||
|
||||
// Handle should still be at socket position
|
||||
Assert.Less(Vector3.Distance(socket.transform.position, handle.transform.position), 0.0001F);
|
||||
#endregion
|
||||
|
||||
socket.transform.localPosition = Vector3.zero;
|
||||
handle.transform.localPosition = Vector3.zero;
|
||||
}
|
||||
catch (Exception e) {
|
||||
Debug.LogError("Test failed");
|
||||
throw (e);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Rigidbody Socket
|
||||
[Test]
|
||||
[Category("Socket")]
|
||||
public void RigidbodySocket_RigidbodyHandle() {
|
||||
// Rigidbody Handles will be parented to Rigidbody Sockets
|
||||
try {
|
||||
GameObject socketObj = GameObject.Find("RigidbodySocket");
|
||||
Socket socket = socketObj.GetComponent<Socket>();
|
||||
Assert.IsTrue(socket != null);
|
||||
|
||||
GameObject handleObj = GameObject.Find("RigidbodyHandle");
|
||||
Handle handle = handleObj.GetComponent<Handle>();
|
||||
Assert.IsTrue(handle != null);
|
||||
|
||||
Transform socketParent = socket.transform.parent;
|
||||
Transform handleParent = handle.transform.parent;
|
||||
|
||||
Vector3 socketPosition = socket.transform.position;
|
||||
Vector3 handlePosition = handle.transform.position;
|
||||
|
||||
#region Attach
|
||||
socket.Attach(handle.transform, false);
|
||||
|
||||
Assert.AreEqual(socket.attachedTransform, handle.transform);
|
||||
Assert.AreEqual(handle.transform.parent, socket.transform);
|
||||
|
||||
// Handle should be at socket position
|
||||
float distance = Vector3.Distance(socket.transform.position, handle.transform.position);
|
||||
Assert.Less(distance, 0.0001F);
|
||||
// Socket should not have moved
|
||||
distance = Vector3.Distance(socketPosition, socket.transform.position);
|
||||
Assert.Less(distance, 0.0001F);
|
||||
#endregion
|
||||
|
||||
#region Release
|
||||
socket.Release();
|
||||
|
||||
Assert.IsTrue(socket.attachedTransform == null);
|
||||
Assert.AreEqual(handle.transform.parent, handleParent);
|
||||
|
||||
// Handle should be at socket position
|
||||
distance = Vector3.Distance(socket.transform.position, handle.transform.position);
|
||||
Assert.Less(distance, 0.0001F);
|
||||
#endregion
|
||||
|
||||
socket.transform.localPosition = Vector3.zero;
|
||||
handle.transform.localPosition = Vector3.zero;
|
||||
}
|
||||
catch (Exception e) {
|
||||
Debug.LogError("Test failed");
|
||||
throw (e);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("Socket")]
|
||||
public void RigidbodySocket_StaticHandle() {
|
||||
// Rigidbody sockets will get a fixed joint to a static handle
|
||||
try {
|
||||
GameObject socketObj = GameObject.Find("RigidbodySocket");
|
||||
Socket socket = socketObj.GetComponent<Socket>();
|
||||
Assert.IsFalse(socket == null);
|
||||
|
||||
GameObject handleObj = GameObject.Find("StaticHandle");
|
||||
Handle handle = handleObj.GetComponent<Handle>();
|
||||
Assert.IsFalse(handle == null);
|
||||
|
||||
Transform socketParent = socket.transform.parent;
|
||||
Transform handleParent = handle.transform.parent;
|
||||
|
||||
Vector3 socketPosition = socket.transform.position;
|
||||
Vector3 handlePosition = handle.transform.position;
|
||||
|
||||
#region Attach
|
||||
socket.Attach(handle.transform, false);
|
||||
|
||||
Joint joint = socket.GetComponent<Joint>();
|
||||
Assert.IsTrue(joint != null);
|
||||
Assert.IsTrue(joint.connectedBody == null);
|
||||
|
||||
Assert.AreEqual(socket.attachedTransform, handle.transform);
|
||||
Assert.AreNotEqual(handle.transform.parent, socket.transform);
|
||||
|
||||
// Socket should be at handle position
|
||||
Assert.Less(Vector3.Distance(socket.transform.position, handle.transform.position), 0.0001F);
|
||||
// Handle should not have moved
|
||||
Assert.Less(Vector3.Distance(handle.transform.position, handlePosition), 0.0001F);
|
||||
#endregion
|
||||
|
||||
#region Release
|
||||
socket.Release();
|
||||
|
||||
Assert.IsTrue(socket.attachedTransform == null);
|
||||
Assert.AreNotEqual(handle.transform.parent, socket.transform);
|
||||
|
||||
joint = socket.GetComponent<Joint>();
|
||||
Assert.IsTrue(joint == null);
|
||||
|
||||
// Socket should still be at handle position
|
||||
Assert.Less(Vector3.Distance(socket.transform.position, handle.transform.position), 0.0001F);
|
||||
#endregion
|
||||
|
||||
socket.transform.localPosition = Vector3.zero;
|
||||
handle.transform.localPosition = Vector3.zero;
|
||||
}
|
||||
catch (Exception e) {
|
||||
Debug.LogError("Test failed");
|
||||
throw (e);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("Socket")]
|
||||
public void RigidbodySocket_KinematicHandle() {
|
||||
// Rigidbody sockets will get parented to kinematic handles
|
||||
try {
|
||||
GameObject socketObj = GameObject.Find("RigidbodySocket");
|
||||
Socket socket = socketObj.GetComponent<Socket>();
|
||||
Assert.IsFalse(socket == null);
|
||||
|
||||
GameObject handleObj = GameObject.Find("KinematicHandle");
|
||||
Handle handle = handleObj.GetComponent<Handle>();
|
||||
Assert.IsFalse(handle == null);
|
||||
|
||||
Transform socketParent = socket.transform.parent;
|
||||
Transform handleParent = handle.transform.parent;
|
||||
|
||||
Vector3 socketPosition = socket.transform.position;
|
||||
Vector3 handlePosition = handle.transform.position;
|
||||
|
||||
#region Attach
|
||||
socket.Attach(handle.transform, false);
|
||||
|
||||
Assert.AreEqual(socket.attachedTransform, handle.transform);
|
||||
Assert.AreEqual(socket.transform.parent, handle.transform);
|
||||
|
||||
// Socket should be at handle position
|
||||
Assert.Less(Vector3.Distance(socket.transform.position, handle.transform.position), 0.0001F);
|
||||
// Handle should not have moved
|
||||
Assert.Less(Vector3.Distance(handle.transform.position, handlePosition), 0.0001F);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Release
|
||||
socket.Release();
|
||||
|
||||
Assert.IsTrue(socket.attachedTransform == null, "Socket still is attached to transform");
|
||||
Assert.AreEqual(socket.transform.parent, socketParent, "Socket is not restored to previous parent");
|
||||
|
||||
// Socket should be at handle position
|
||||
Assert.Less(Vector3.Distance(socket.transform.position, handle.transform.position), 0.0001F);
|
||||
#endregion
|
||||
|
||||
socket.transform.localPosition = Vector3.zero;
|
||||
handle.transform.localPosition = Vector3.zero;
|
||||
}
|
||||
catch (Exception e) {
|
||||
Debug.LogError("Test failed");
|
||||
throw (e);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Kinematic Socket
|
||||
[Test]
|
||||
[Category("Socket")]
|
||||
public void KinematicSocket_RigidbodyHandle() {
|
||||
Setup();
|
||||
// Rigidbody Handles will be parented to Kinematic Sockets
|
||||
try {
|
||||
GameObject socketObj = GameObject.Find("KinematicSocket");
|
||||
Socket socket = socketObj.GetComponent<Socket>();
|
||||
Assert.IsTrue(socket != null);
|
||||
|
||||
GameObject handleObj = GameObject.Find("RigidbodyHandle");
|
||||
Handle handle = handleObj.GetComponent<Handle>();
|
||||
Assert.IsTrue(handle != null);
|
||||
|
||||
Transform socketParent = socket.transform.parent;
|
||||
Transform handleParent = handle.transform.parent;
|
||||
|
||||
Vector3 socketPosition = socket.transform.position;
|
||||
Vector3 handlePosition = handle.transform.position;
|
||||
|
||||
#region Attach
|
||||
socket.Attach(handle.transform, false);
|
||||
|
||||
Assert.AreEqual(socket.attachedTransform, handle.transform);
|
||||
Assert.AreEqual(handle.transform.parent, socket.transform);
|
||||
|
||||
// Handle should be at socket position
|
||||
float distance = Vector3.Distance(socket.transform.position, handle.transform.position);
|
||||
Assert.Less(distance, 0.0001F);
|
||||
// Socket should not have moved
|
||||
distance = Vector3.Distance(socketPosition, socket.transform.position);
|
||||
Assert.Less(distance, 0.0001F);
|
||||
#endregion
|
||||
|
||||
#region Release
|
||||
socket.Release();
|
||||
|
||||
Assert.IsTrue(socket.attachedTransform == null);
|
||||
Assert.AreEqual(handle.transform.parent, handleParent);
|
||||
|
||||
// Handle should still be at socket position
|
||||
distance = Vector3.Distance(socket.transform.position, handle.transform.position);
|
||||
Assert.Less(distance, 0.0001F);
|
||||
#endregion
|
||||
|
||||
socket.transform.localPosition = Vector3.zero;
|
||||
handle.transform.localPosition = Vector3.zero;
|
||||
}
|
||||
catch (Exception e) {
|
||||
Debug.LogError("Test failed");
|
||||
throw (e);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("Socket")]
|
||||
public void KinematicSocket_StaticHandle() {
|
||||
Setup();
|
||||
|
||||
// Kinematic Sockets should be parented to a static handle
|
||||
try {
|
||||
GameObject socketObj = GameObject.Find("KinematicSocket");
|
||||
Socket socket = socketObj.GetComponent<Socket>();
|
||||
Assert.IsTrue(socket != null);
|
||||
|
||||
GameObject handleObj = GameObject.Find("StaticHandle");
|
||||
Handle handle = handleObj.GetComponent<Handle>();
|
||||
Assert.IsTrue(handle != null);
|
||||
|
||||
Transform socketParent = socket.transform.parent;
|
||||
Transform handleParent = handle.transform.parent;
|
||||
|
||||
Vector3 socketPosition = socket.transform.position;
|
||||
Vector3 handlePosition = handle.transform.position;
|
||||
|
||||
#region Attach
|
||||
socket.Attach(handle.transform, false);
|
||||
|
||||
Assert.AreEqual(socket.attachedTransform, handle.transform);
|
||||
Assert.AreEqual(socket.transform.parent, handle.transform);
|
||||
|
||||
// Handle should be at socket position
|
||||
Assert.Less(Vector3.Distance(socket.transform.position, handle.transform.position), 0.0001F);
|
||||
// Handle should not have moved
|
||||
Assert.Less(Vector3.Distance(handlePosition, handle.transform.position), 0.0001F);
|
||||
#endregion
|
||||
|
||||
#region Release
|
||||
socket.Release();
|
||||
|
||||
Assert.IsTrue(socket.attachedTransform == null);
|
||||
Assert.AreEqual(socket.transform.parent, socketParent);
|
||||
#endregion
|
||||
|
||||
socket.transform.localPosition = Vector3.zero;
|
||||
handle.transform.localPosition = Vector3.zero;
|
||||
}
|
||||
catch (Exception e) {
|
||||
Debug.LogError("Test failed");
|
||||
throw (e);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Category("Socket")]
|
||||
public void KinematicSocket_KinematicHandle() {
|
||||
Setup();
|
||||
|
||||
// Kinematic Handles should be parented to a kinematic socket
|
||||
try {
|
||||
GameObject socketObj = GameObject.Find("KinematicSocket");
|
||||
Socket socket = socketObj.GetComponent<Socket>();
|
||||
Assert.IsTrue(socket != null);
|
||||
|
||||
GameObject handleObj = GameObject.Find("KinematicHandle");
|
||||
Handle handle = handleObj.GetComponent<Handle>();
|
||||
Assert.IsTrue(handle != null);
|
||||
|
||||
Transform socketParent = socket.transform.parent;
|
||||
Transform handleParent = handle.transform.parent;
|
||||
|
||||
Vector3 socketPosition = socket.transform.position;
|
||||
Vector3 handlePosition = handle.transform.position;
|
||||
|
||||
#region Attach
|
||||
socket.Attach(handle.transform, false);
|
||||
|
||||
Assert.IsTrue(socket.attachedTransform != null);
|
||||
Assert.AreEqual(handle.transform.parent, socket.transform);
|
||||
|
||||
// Handle should be at socket position
|
||||
Assert.Less(Vector3.Distance(socket.transform.position, handle.transform.position), 0.0001F);
|
||||
// Socket should not have moved
|
||||
Assert.Less(Vector3.Distance(socketPosition, socket.transform.position), 0.0001F);
|
||||
#endregion
|
||||
|
||||
#region Release
|
||||
socket.Release();
|
||||
|
||||
Assert.IsTrue(socket.attachedTransform == null);
|
||||
Assert.AreEqual(handle.transform.parent, handleParent);
|
||||
#endregion
|
||||
|
||||
socket.transform.localPosition = Vector3.zero;
|
||||
handle.transform.localPosition = Vector3.zero;
|
||||
}
|
||||
catch (Exception e) {
|
||||
Debug.LogError("Test failed");
|
||||
throw (e);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
#endif
|
12
Tests/Editor/Socket/SocketTest.cs.meta
Normal file
12
Tests/Editor/Socket/SocketTest.cs.meta
Normal file
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 50c15dd580f1d4044a08b1a27d70e6bd
|
||||
timeCreated: 1551084484
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
x
Reference in New Issue
Block a user