Tanoda
CreationAndDeletionTests.cs
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) Ultraleap, Inc. 2011-2020. *
3 * *
4 * Use subject to the terms of the Apache License 2.0 available at *
5 * http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
6 * between Ultraleap and you, your company or other organization. *
7 ******************************************************************************/
8
9#if LEAP_TESTS
10using NUnit.Framework;
11using System.Collections;
12using UnityEngine;
13using UnityEngine.TestTools;
14
16
17 public class CreationAndDeletionTests : InteractionEngineTestBase {
18
19 #region General Tests
20
21 [UnityTest]
22 public IEnumerator CanCreateAndDelete() {
23 yield return wait(beginningTestWait);
24
25 InitTest();
26 provider.editTimePose = TestHandFactory.TestHandPose.HeadMountedB;
27
28 yield return wait(aBit);
29
30 var lHandPos = leftHand.leapHand.PalmPosition.ToVector3();
31 var rHandPos = rightHand.leapHand.PalmPosition.ToVector3();
32
33 var addBox0 = Spawn(box0, lHandPos - Physics.gravity * 0.1F + Vector3.forward * 0.5F);
34 var addBox1 = Spawn(box1, rHandPos - Physics.gravity * 0.1F + Vector3.forward * 0.5F);
35
36 yield return wait(aWhile);
37
38 GameObject.Destroy(addBox0.gameObject);
39 GameObject.Destroy(addBox1.gameObject);
40
41 yield return wait(endingTestWait);
42 }
43
44 [UnityTest]
45 public IEnumerator CanCreateInteractionBehaviourAtRuntime() {
46 yield return wait(beginningTestWait);
47
48 InitTest();
49 provider.editTimePose = TestHandFactory.TestHandPose.HeadMountedB;
50
51 var rHandPos = rightHand.leapHand.PalmPosition.ToVector3();
52
53 var spawnPos = rHandPos;
54 var newBox = GameObject.CreatePrimitive(PrimitiveType.Cube);
55 newBox.transform.parent = rigObj.transform;
56 newBox.transform.position = spawnPos;
57 newBox.transform.localScale = Vector3.one * 0.1F;
58 var newBody = newBox.AddComponent<Rigidbody>();
59 newBody.useGravity = true;
60 newBody.isKinematic = false;
61 newBox.AddComponent<InteractionBehaviour>();
62
63 yield return wait(aWhile);
64
65 yield return wait(endingTestWait);
66 }
67
68 #endregion
69
70 #region Hover Tests
71
72 [UnityTest]
73 public IEnumerator CanDeleteObjectWhileHovering() {
74 yield return wait(beginningTestWait);
75
76 InitTest();
77 provider.editTimePose = TestHandFactory.TestHandPose.HeadMountedB;
78
79 yield return wait(aBit);
80
81 var lHandPos = leftHand.leapHand.PalmPosition.ToVector3();
82 var addBox0 = Spawn(box0, lHandPos + Vector3.forward * 0.2F);
83 addBox0.rigidbody.useGravity = false;
84
85 yield return wait(aBit);
86
87 Assert.That(addBox0.isHovered);
88
89 GameObject.Destroy(addBox0.gameObject);
90
91 yield return wait(endingTestWait);
92 }
93
94 #endregion
95
96 #region Contact Tests
97
98 [UnityTest]
99 public IEnumerator CanDeleteObjectDuringContact() {
100 yield return wait(beginningTestWait);
101
102 InitTest();
103 provider.editTimePose = TestHandFactory.TestHandPose.HeadMountedB;
104
105 yield return wait(aWhile);
106
107 var lHandPos = leftHand.leapHand.PalmPosition.ToVector3();
108 var rHandPos = rightHand.leapHand.PalmPosition.ToVector3();
109
110 var addBox0 = Spawn(box0, lHandPos - Physics.gravity * 0.1F);
111 var addBox1 = Spawn(box1, rHandPos - Physics.gravity * 0.1F);
112
113 bool addBox0Contacted = false;
114 bool addBox1Contacted = false;
115 addBox0.OnContactBegin += () => {
116 addBox0Contacted = true;
117 };
118 addBox1.OnContactBegin += () => {
119 addBox1Contacted = true;
120 };
121
122 int contactFramesWaited = 0;
123 while ((!addBox0Contacted || !addBox1Contacted) && contactFramesWaited < WAIT_FOR_INTERACTION_FRAME_LIMIT) {
124 yield return null;
125
126 contactFramesWaited++;
127 }
128 Assert.That(contactFramesWaited != WAIT_FOR_INTERACTION_FRAME_LIMIT);
129
130 GameObject.Destroy(addBox0.gameObject);
131 GameObject.Destroy(addBox1.gameObject);
132
133 yield return wait(endingTestWait);
134 }
135
136 #endregion Contact
137
138 #region Grasping Tests
139
140 [UnityTest]
141 public IEnumerator CanDeleteObjectDuringGrasp() {
142 yield return wait(beginningTestWait);
143
144 InitTest(GRASP_THROW_RIG, DEFAULT_STAGE);
145
146 // Wait for boxes to rest on the ground.
147 yield return wait(aBit);
148
149 // Play the grasping animation.
150 recording.Play();
151
152 // Wait for box0 to be grasped.
153 bool graspOccurred = false;
154 box0.OnGraspBegin += () => {
155 graspOccurred = true;
156 };
157 int framesWaited = 0;
158 while (!graspOccurred && framesWaited < WAIT_FOR_INTERACTION_FRAME_LIMIT) {
159 yield return null;
160 framesWaited++;
161 }
162 Assert.That(framesWaited != WAIT_FOR_INTERACTION_FRAME_LIMIT);
163
164 // We should have box0 grasped now.
165 GameObject.Destroy(box0);
166
167 yield return wait(endingTestWait);
168 }
169
170 #endregion
171
172 }
173
174}
175
176#endif // LEAP_TESTS