Skip to content

Commit 471da07

Browse files
committed
Update tests
1 parent ce20d98 commit 471da07

File tree

2 files changed

+62
-35
lines changed

2 files changed

+62
-35
lines changed

org.mixedrealitytoolkit.input/Tests/Runtime/InteractionModeManagerTests.cs

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public IEnumerator ProximityDetectorTest()
6868
}
6969

7070
/// <summary>
71-
/// Tests the basic Interaction detector. The controller should enter one mode during hover, another during select, and fall back to the default mode during neither
71+
/// Tests the basic Interaction detector. The controller should enter one mode during hover, another during select, and fall back to the default mode during neither.
7272
/// </summary>
7373
[UnityTest]
7474
public IEnumerator InteractionDetectorTest()
@@ -89,28 +89,40 @@ public IEnumerator InteractionDetectorTest()
8989
yield return rightHand.AimAt(cube.transform.position);
9090
yield return RuntimeTestUtilities.WaitForUpdates();
9191

92-
InteractionMode currentMode = rightHandController.GetComponentInChildren<MRTKRayInteractor>().GetComponent<InteractionDetector>().ModeOnHover;
93-
Assert.AreEqual(currentMode, rightHandController.GetComponentInChildren<MRTKRayInteractor>().GetComponent<InteractionDetector>().ModeOnDetection);
94-
ValidateInteractionModeActive(rightHandController, currentMode);
92+
InteractionDetector interactionDetector = rightHandController.GetComponentInChildren<MRTKRayInteractor>().GetComponent<InteractionDetector>();
93+
94+
InteractionMode expectedMode = interactionDetector.ModeOnHover;
95+
Assert.AreEqual(expectedMode, interactionDetector.ModeOnDetection);
96+
ValidateInteractionModeActive(rightHandController, expectedMode);
9597

98+
// Select the cube and check that we're in the correct mode
9699
yield return rightHand.SetHandshape(HandshapeTypes.HandshapeId.Grab);
97100
yield return RuntimeTestUtilities.WaitForUpdates();
98-
currentMode = rightHandController.GetComponentInChildren<MRTKRayInteractor>().GetComponent<InteractionDetector>().ModeOnSelect;
99-
Assert.AreEqual(currentMode, rightHandController.GetComponentInChildren<MRTKRayInteractor>().GetComponent<InteractionDetector>().ModeOnDetection);
100-
ValidateInteractionModeActive(rightHandController, currentMode);
101+
expectedMode = interactionDetector.ModeOnSelect;
102+
Assert.AreEqual(expectedMode, interactionDetector.ModeOnDetection);
103+
ValidateInteractionModeActive(rightHandController, expectedMode);
101104

102-
// move the hand far away and validate that we are in the default mode
105+
// Release the selection and move the hand far away and validate that we are in the default mode
103106
yield return rightHand.SetHandshape(HandshapeTypes.HandshapeId.Open);
104107
yield return RuntimeTestUtilities.WaitForUpdates();
105-
yield return rightHand.MoveTo(cube.transform.position + new Vector3(3.0f,0,0));
108+
yield return rightHand.MoveTo(cube.transform.position + new Vector3(3.0f, 0, 0));
106109
yield return RuntimeTestUtilities.WaitForUpdates();
110+
expectedMode = InteractionModeManager.Instance.DefaultMode;
111+
ValidateInteractionModeActive(rightHandController, expectedMode);
107112

108-
currentMode = InteractionModeManager.Instance.DefaultMode;
109-
ValidateInteractionModeActive(rightHandController, currentMode);
113+
// Put the hand into a grab state and validate that we are in the default mode, since we're not selecting an object
114+
yield return rightHand.SetHandshape(HandshapeTypes.HandshapeId.Grab);
115+
yield return RuntimeTestUtilities.WaitForUpdates();
116+
ValidateInteractionModeActive(rightHandController, expectedMode);
117+
118+
// Release the grab state and validate that we are in the default mode
119+
yield return rightHand.SetHandshape(HandshapeTypes.HandshapeId.Open);
120+
yield return RuntimeTestUtilities.WaitForUpdates();
121+
ValidateInteractionModeActive(rightHandController, expectedMode);
110122
}
111123

112124
/// <summary>
113-
/// Tests that mode mediation works properly.
125+
/// Tests that mode mediation works properly.
114126
/// </summary>
115127
/// <remarks>
116128
/// The interaction mode with the higher priority should be the valid one which affects the controller.
@@ -136,12 +148,14 @@ public IEnumerator ModeMediationTest()
136148
InputTestUtilities.SetHandAnchorPoint(Handedness.Right, ControllerAnchorPoint.Grab);
137149
yield return RuntimeTestUtilities.WaitForUpdates();
138150

139-
// Moving the hand to a position where it's far ray is hovering over the cube
151+
InteractionDetector rayInteractionDetector = rightHandController.GetComponentInChildren<MRTKRayInteractor>().GetComponent<InteractionDetector>();
152+
153+
// Moving the hand to a position where its far ray is hovering over the cube
140154
yield return rightHand.AimAt(cube.transform.position);
141155
yield return RuntimeTestUtilities.WaitForUpdates();
142-
InteractionMode farRayMode = rightHandController.GetComponentInChildren<MRTKRayInteractor>().GetComponent<InteractionDetector>().ModeOnHover;
156+
InteractionMode farRayMode = rayInteractionDetector.ModeOnHover;
143157
yield return RuntimeTestUtilities.WaitForUpdates();
144-
Assert.AreEqual(farRayMode, rightHandController.GetComponentInChildren<MRTKRayInteractor>().GetComponent<InteractionDetector>().ModeOnDetection);
158+
Assert.AreEqual(farRayMode, rayInteractionDetector.ModeOnDetection);
145159
ValidateInteractionModeActive(rightHandController, farRayMode);
146160

147161
// Now move the hand in range for the proximity detector
@@ -159,8 +173,10 @@ public IEnumerator ModeMediationTest()
159173
yield return rightHand.SetHandshape(HandshapeTypes.HandshapeId.Grab);
160174
yield return RuntimeTestUtilities.WaitForUpdates();
161175

162-
InteractionMode grabMode = rightHandController.GetComponentInChildren<GrabInteractor>().GetComponent<InteractionDetector>().ModeOnSelect;
163-
Assert.AreEqual(grabMode, rightHandController.GetComponentInChildren<GrabInteractor>().GetComponent<InteractionDetector>().ModeOnDetection);
176+
InteractionDetector grabInteractionDetector = rightHandController.GetComponentInChildren<GrabInteractor>().GetComponent<InteractionDetector>();
177+
178+
InteractionMode grabMode = grabInteractionDetector.ModeOnSelect;
179+
Assert.AreEqual(grabMode, grabInteractionDetector.ModeOnDetection);
164180
yield return RuntimeTestUtilities.WaitForUpdates();
165181
ValidateInteractionModeActive(rightHandController, grabMode);
166182
Assert.IsTrue(grabMode.Priority > nearMode.Priority);
@@ -176,7 +192,7 @@ public IEnumerator ModeMediationTest()
176192

177193
// Moving the hand to a position where it's far ray is hovering over the cube
178194
yield return rightHand.MoveTo(cube.transform.position + new Vector3(0.02f, -0.1f, -0.8f));
179-
yield return RuntimeTestUtilities.WaitForUpdates(frameCount:120);
195+
yield return RuntimeTestUtilities.WaitForUpdates(frameCount: 120);
180196

181197
ValidateInteractionModeActive(rightHandController, farRayMode);
182198
}
@@ -189,15 +205,14 @@ public IEnumerator ModeMediationTest()
189205
private void ValidateInteractionModeActive(XRBaseController controller, InteractionMode currentMode)
190206
{
191207
// We construct the list of managed interactor types manually because we don't want to expose the internal controller mapping implementation to even internal use, since
192-
// we don't want any other class to be able to modify those collections without going through the Mode Manager or it's in-editor inspector.
193-
HashSet<System.Type> managedInteractorTypes = new HashSet<System.Type>(InteractionModeManager.Instance.PrioritizedInteractionModes.SelectMany(x => x.AssociatedTypes));
194-
HashSet<System.Type> activeInteractorTypes = InteractionModeManager.Instance.PrioritizedInteractionModes.Find(x => x.ModeName == currentMode.Name).AssociatedTypes;
208+
// we don't want any other class to be able to modify those collections without going through the Mode Manager or its in-editor inspector.
209+
HashSet<Type> managedInteractorTypes = new HashSet<System.Type>(InteractionModeManager.Instance.PrioritizedInteractionModes.SelectMany(x => x.AssociatedTypes));
210+
HashSet<Type> activeInteractorTypes = InteractionModeManager.Instance.PrioritizedInteractionModes.Find(x => x.ModeName == currentMode.Name).AssociatedTypes;
195211

196212
// Ensure the prox detector has actually had the desired effect of enabling/disabling interactors.
197-
foreach (System.Type interactorType in managedInteractorTypes)
213+
foreach (Type interactorType in managedInteractorTypes)
198214
{
199-
XRBaseInteractor interactor = controller.GetComponentInChildren(interactorType) as XRBaseInputInteractor;
200-
if (interactor != null)
215+
if (controller.GetComponentInChildren(interactorType) is XRBaseInputInteractor interactor && interactor != null)
201216
{
202217
Assert.AreEqual(activeInteractorTypes.Contains(interactorType), interactor.enabled);
203218
}

org.mixedrealitytoolkit.input/Tests/Runtime/InteractionModeManagerTestsForControllerlessRig.cs

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -91,30 +91,42 @@ public IEnumerator InteractionDetectorTest()
9191
yield return RuntimeTestUtilities.WaitForUpdates();
9292

9393
TrackedPoseDriver rightHandTrackedPoseDriver = CachedTrackedPoseDriverLookup.RightHandTrackedPoseDriver;
94-
InteractionDetector rightHandInteractionDetector = rightHandTrackedPoseDriver.transform.parent.GetComponentInChildren<MRTKRayInteractor>().GetComponent<InteractionDetector>();
94+
Assert.IsTrue(rightHandTrackedPoseDriver != null, "No tracked pose driver found for right hand.");
9595

9696
// Moving the hand to a position where it's far ray is hovering over the cube
9797
yield return rightHand.AimAt(cube.transform.position);
9898
yield return RuntimeTestUtilities.WaitForUpdates();
9999

100-
InteractionMode currentMode = rightHandInteractionDetector.ModeOnHover;
101-
Assert.AreEqual(currentMode, rightHandInteractionDetector.ModeOnDetection);
102-
ValidateInteractionModeActive(rightHandTrackedPoseDriver, currentMode);
100+
InteractionDetector interactionDetector = rightHandTrackedPoseDriver.transform.parent.GetComponentInChildren<MRTKRayInteractor>().GetComponent<InteractionDetector>();
101+
102+
InteractionMode expectedMode = interactionDetector.ModeOnHover;
103+
Assert.AreEqual(expectedMode, interactionDetector.ModeOnDetection);
104+
ValidateInteractionModeActive(rightHandTrackedPoseDriver, expectedMode);
103105

106+
// Select the cube and check that we're in the correct mode
104107
yield return rightHand.SetHandshape(HandshapeTypes.HandshapeId.Grab);
105108
yield return RuntimeTestUtilities.WaitForUpdates();
106-
currentMode = rightHandInteractionDetector.ModeOnSelect;
107-
Assert.AreEqual(currentMode, rightHandInteractionDetector.ModeOnDetection);
108-
ValidateInteractionModeActive(rightHandTrackedPoseDriver, currentMode);
109+
expectedMode = interactionDetector.ModeOnSelect;
110+
Assert.AreEqual(expectedMode, interactionDetector.ModeOnDetection);
111+
ValidateInteractionModeActive(rightHandTrackedPoseDriver, expectedMode);
109112

110-
// move the hand far away and validate that we are in the default mode
113+
// Release the selection and move the hand far away and validate that we are in the default mode
111114
yield return rightHand.SetHandshape(HandshapeTypes.HandshapeId.Open);
112115
yield return RuntimeTestUtilities.WaitForUpdates();
113-
yield return rightHand.MoveTo(cube.transform.position + new Vector3(3.0f,0,0));
116+
yield return rightHand.MoveTo(cube.transform.position + new Vector3(3.0f, 0, 0));
114117
yield return RuntimeTestUtilities.WaitForUpdates();
118+
expectedMode = InteractionModeManager.Instance.DefaultMode;
119+
ValidateInteractionModeActive(rightHandTrackedPoseDriver, expectedMode);
115120

116-
currentMode = InteractionModeManager.Instance.DefaultMode;
117-
ValidateInteractionModeActive(rightHandTrackedPoseDriver, currentMode);
121+
// Put the hand into a grab state and validate that we are in the default mode, since we're not selecting an object
122+
yield return rightHand.SetHandshape(HandshapeTypes.HandshapeId.Grab);
123+
yield return RuntimeTestUtilities.WaitForUpdates();
124+
ValidateInteractionModeActive(rightHandTrackedPoseDriver, expectedMode);
125+
126+
// Release the grab state and validate that we are in the default mode
127+
yield return rightHand.SetHandshape(HandshapeTypes.HandshapeId.Open);
128+
yield return RuntimeTestUtilities.WaitForUpdates();
129+
ValidateInteractionModeActive(rightHandTrackedPoseDriver, expectedMode);
118130
}
119131

120132
/// <summary>

0 commit comments

Comments
 (0)