Skip to content

Commit cccdbec

Browse files
authored
Ensure consistency on slider tests (#1052)
* Update TestHand.cs * Ignore some tests instead of commenting them out * SetHandAnchorPoint each test for consistency * Update TestHand.cs
1 parent cb936a4 commit cccdbec

File tree

3 files changed

+102
-94
lines changed
  • org.mixedrealitytoolkit.input/Tests/Runtime/Utilities
  • org.mixedrealitytoolkit.uxcomponents.noncanvas/Tests/Runtime
  • org.mixedrealitytoolkit.uxcomponents/Tests/Runtime

3 files changed

+102
-94
lines changed

org.mixedrealitytoolkit.input/Tests/Runtime/Utilities/TestHand.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,10 @@ public override IEnumerator AimAt(Vector3 target, int numSteps = InputTestUtilit
9696
}
9797

9898
/// <summary>
99-
/// Changes the hand's pose to the given handshape. Does not animate the hand between the current pose and new pose.
99+
/// Changes the hand's pose to the given handshape. Does not animate the hand between the current pose and new pose.
100100
/// </summary>
101101
/// <param name="newHandshapeId">The new hand pose.</param>
102-
/// <param name="numSteps">The new hand pose.</param>
102+
/// <param name="numSteps">The number of steps to take to reach the new hand pose.</param>
103103
/// <param name="waitForFixedUpdate">If true, waits for a fixed update after moving to the new pose.</param>
104104
public IEnumerator SetHandshape(HandshapeId newHandshapeId, int numSteps = InputTestUtilities.ControllerMoveStepsSentinelValue, bool waitForFixedUpdate = true)
105105
{
@@ -112,7 +112,7 @@ public IEnumerator SetHandshape(HandshapeId newHandshapeId, int numSteps = Input
112112
}
113113

114114
/// <summary>
115-
/// Combined sequence of pinching and unpinching
115+
/// Combined sequence of pinching and unpinching.
116116
/// </summary>
117117
public override IEnumerator Click()
118118
{
@@ -123,4 +123,4 @@ public override IEnumerator Click()
123123
}
124124
}
125125
}
126-
#pragma warning restore CS1591
126+
#pragma warning restore CS1591

org.mixedrealitytoolkit.uxcomponents.noncanvas/Tests/Runtime/SliderTests.cs

Lines changed: 75 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using UnityEditor;
1212
using UnityEngine;
1313
using UnityEngine.TestTools;
14+
using UnityEngine.XR.Interaction.Toolkit;
1415

1516
using HandshapeId = MixedReality.Toolkit.Input.HandshapeTypes.HandshapeId;
1617

@@ -38,7 +39,6 @@ public override IEnumerator Setup()
3839
[UnityTest]
3940
public IEnumerator TestAddInteractableAtRuntime()
4041
{
41-
4242
// This should not throw exception
4343
AssembleSlider(InputTestUtilities.InFrontOfUser(Vector3.forward), Vector3.zero, out GameObject sliderObject, out Slider slider, out SliderVisuals sliderVisuals);
4444
yield return DirectPinchAndMoveSlider(slider, 1.0f);
@@ -470,105 +470,104 @@ public IEnumerator TestVisualsOrientation()
470470
yield return null;
471471
}
472472

473-
// Disabled as we adopt Unity's multi-selection implementation
474-
// /// <summary>
475-
// /// Tests that the slider will only use the first valid grab interactor, and reject others.
476-
// /// </summary>
477-
// [UnityTest]
478-
// public IEnumerator TestMultipleGrabBehavior()
479-
// {
480-
// // This should not throw exception
481-
// AssembleSlider(Vector3.forward, Vector3.zero, out GameObject sliderObject, out Slider slider, out SliderVisuals sliderVisuals);
473+
/// <summary>
474+
/// Tests that the slider will only use the first valid grab interactor, and reject others.
475+
/// </summary>
476+
[UnityTest, Ignore("Disabled as we adopt Unity's multi-selection implementation.")]
477+
public IEnumerator TestMultipleGrabBehavior()
478+
{
479+
// This should not throw exception
480+
AssembleSlider(Vector3.forward, Vector3.zero, out GameObject sliderObject, out Slider slider, out SliderVisuals sliderVisuals);
482481

483-
// Debug.Assert(slider.Value == 0.5, "Slider should have value 0.5 at start");
482+
Debug.Assert(slider.Value == 0.5, "Slider should have value 0.5 at start");
484483

485-
// // Single mode needed to reject incoming interactors once we are already selected.
486-
// Debug.Assert(slider.selectMode == InteractableSelectMode.Single, "Slider should be in single select mode");
484+
// Single mode needed to reject incoming interactors once we are already selected.
485+
Debug.Assert(slider.selectMode == InteractableSelectMode.Single, "Slider should be in single select mode");
487486

488-
// var rightHand = new TestHand(Handedness.Right);
489-
// Vector3 initialPos = sliderVisuals.Handle.position;
490-
// yield return rightHand.Show(initialPos);
491-
// yield return rightHand.SetGesture(GestureId.Pinch);
487+
var rightHand = new TestHand(Handedness.Right);
488+
Vector3 initialPos = sliderVisuals.Handle.position;
489+
yield return rightHand.Show(initialPos);
490+
yield return rightHand.SetHandshape(HandshapeId.Pinch);
492491

493-
// yield return RuntimeTestUtilities.WaitForUpdates();
494-
// Debug.Assert(slider.isSelected == true, "Slider was not originally selected");
495-
// Debug.Assert(slider.IsGrabSelected == true, "Slider should specifically be grab selected");
492+
yield return RuntimeTestUtilities.WaitForUpdates();
493+
Debug.Assert(slider.isSelected == true, "Slider was not originally selected");
494+
Debug.Assert(slider.IsGrabSelected == true, "Slider should specifically be grab selected");
496495

497-
// var leftHand = new TestHand(Handedness.Left);
498-
// yield return leftHand.Show(initialPos);
499-
// yield return leftHand.SetGesture(GestureId.Pinch);
496+
var leftHand = new TestHand(Handedness.Left);
497+
yield return leftHand.Show(initialPos);
498+
yield return leftHand.SetHandshape(HandshapeId.Pinch);
500499

501-
// yield return RuntimeTestUtilities.WaitForUpdates();
502-
// Debug.Assert(slider.interactorsSelecting.Count == 1, "Single mode should enforce single selection");
500+
yield return RuntimeTestUtilities.WaitForUpdates();
501+
Debug.Assert(slider.interactorsSelecting.Count == 1, "Single mode should enforce single selection");
503502

504-
// // Now we move the right hand to the left, but the slider should not move.
505-
// yield return rightHand.MoveTo(new Vector3(-0.1f, 0, 1.0f));
503+
// Now we move the right hand to the left, but the slider should not move.
504+
yield return rightHand.MoveTo(new Vector3(-0.1f, 0, 1.0f));
506505

507-
// yield return RuntimeTestUtilities.WaitForUpdates();
508-
// Debug.Assert(Mathf.Abs(slider.Value - 0.5f) < 0.01f, "Slider should not have moved");
506+
yield return RuntimeTestUtilities.WaitForUpdates();
507+
Debug.Assert(Mathf.Abs(slider.Value - 0.5f) < 0.01f, "Slider should not have moved");
509508

510-
// // Now we move the left (new) hand to the right, and the slider should now move.
511-
// yield return leftHand.MoveTo(new Vector3(0.1f, 0, 1.0f));
509+
// Now we move the left (new) hand to the right, and the slider should now move.
510+
yield return leftHand.MoveTo(new Vector3(0.1f, 0, 1.0f));
512511

513-
// yield return RuntimeTestUtilities.WaitForUpdates();
514-
// Assert.That(slider.Value, Is.GreaterThan(0.5), "Slider didn't move after moving new grab");
512+
yield return RuntimeTestUtilities.WaitForUpdates();
513+
Assert.That(slider.Value, Is.GreaterThan(0.5), "Slider didn't move after moving new grab");
515514

516-
// // clean up
517-
// Object.Destroy(sliderObject);
518-
// }
515+
// clean up
516+
Object.Destroy(sliderObject);
517+
}
519518

520-
// /// <summary>
521-
// /// Tests that the slider will only use the first valid GazePinch interactor, and reject others.
522-
// /// </summary>
523-
// [UnityTest]
524-
// public IEnumerator TestMultipleGazePinchBehavior()
525-
// {
526-
// // This should not throw exception
527-
// AssembleSlider(Vector3.forward, Vector3.zero, out GameObject sliderObject, out Slider slider, out _);
519+
/// <summary>
520+
/// Tests that the slider will only use the first valid GazePinch interactor, and reject others.
521+
/// </summary>
522+
[UnityTest, Ignore("Disabled as we adopt Unity's multi-selection implementation.")]
523+
public IEnumerator TestMultipleGazePinchBehavior()
524+
{
525+
// This should not throw exception
526+
AssembleSlider(Vector3.forward, Vector3.zero, out GameObject sliderObject, out Slider slider, out _);
528527

529-
// Debug.Assert(slider.Value == 0.5, "Slider should have value 0.5 at start");
528+
Debug.Assert(slider.Value == 0.5, "Slider should have value 0.5 at start");
530529

531-
// // Single mode needed to reject incoming interactors once we are already selected.
532-
// Debug.Assert(slider.selectMode == InteractableSelectMode.Single, "Slider should be in single select mode");
530+
// Single mode needed to reject incoming interactors once we are already selected.
531+
Debug.Assert(slider.selectMode == InteractableSelectMode.Single, "Slider should be in single select mode");
533532

534-
// var rightHand = new TestHand(Handedness.Right);
535-
// Vector3 initialPos = new Vector3(0.0f, 0, 0.5f);
536-
// yield return rightHand.Show(initialPos);
533+
var rightHand = new TestHand(Handedness.Right);
534+
Vector3 initialPos = new Vector3(0.0f, 0, 0.5f);
535+
yield return rightHand.Show(initialPos);
537536

538-
// // Use more frames for better gaze-pinch reliability
539-
// yield return rightHand.SetGesture(GestureId.Pinch, 10);
537+
// Use more frames for better gaze-pinch reliability
538+
yield return rightHand.SetHandshape(HandshapeId.Pinch, 10);
540539

541-
// yield return RuntimeTestUtilities.WaitForUpdates();
542-
// Debug.Assert(slider.isSelected == true, "Slider was not originally selected");
543-
// Debug.Assert(slider.IsGazePinchSelected == true, "Slider should specifically be gaze-pinch selected");
544-
// Debug.Assert(slider.interactorsSelecting.Count == 1, "Only one interactor should be selecting so far.");
540+
yield return RuntimeTestUtilities.WaitForUpdates();
541+
Debug.Assert(slider.isSelected == true, "Slider was not originally selected");
542+
Debug.Assert(slider.IsGazePinchSelected == true, "Slider should specifically be gaze-pinch selected");
543+
Debug.Assert(slider.interactorsSelecting.Count == 1, "Only one interactor should be selecting so far.");
545544

546-
// float initialSliderValue = slider.Value;
545+
float initialSliderValue = slider.Value;
547546

548-
// var leftHand = new TestHand(Handedness.Left);
549-
// yield return leftHand.Show(initialPos);
547+
var leftHand = new TestHand(Handedness.Left);
548+
yield return leftHand.Show(initialPos);
550549

551-
// // Use more frames for better gaze-pinch reliability
552-
// yield return leftHand.SetGesture(GestureId.Pinch, 10);
550+
// Use more frames for better gaze-pinch reliability
551+
yield return leftHand.SetHandshape(HandshapeId.Pinch, 10);
553552

554-
// yield return RuntimeTestUtilities.WaitForUpdates();
555-
// Debug.Assert(slider.interactorsSelecting.Count == 1, "Single mode should not allow multiple interactors to select");
553+
yield return RuntimeTestUtilities.WaitForUpdates();
554+
Debug.Assert(slider.interactorsSelecting.Count == 1, "Single mode should not allow multiple interactors to select");
556555

557-
// // Now we move the right (original) hand to the left, but the slider should not move.
558-
// yield return rightHand.MoveTo(new Vector3(-0.1f, 0, 1.0f));
556+
// Now we move the right (original) hand to the left, but the slider should not move.
557+
yield return rightHand.MoveTo(new Vector3(-0.1f, 0, 1.0f));
559558

560-
// yield return RuntimeTestUtilities.WaitForUpdates();
561-
// Debug.Assert(Mathf.Abs(slider.Value - initialSliderValue) < 0.01f, "Slider should have detached from the first interactor");
559+
yield return RuntimeTestUtilities.WaitForUpdates();
560+
Debug.Assert(Mathf.Abs(slider.Value - initialSliderValue) < 0.01f, "Slider should have detached from the first interactor");
562561

563-
// // Now we move the left (new) hand to the right, and the slider should now move.
564-
// yield return leftHand.MoveTo(new Vector3(0.1f, 0, 1.0f));
562+
// Now we move the left (new) hand to the right, and the slider should now move.
563+
yield return leftHand.MoveTo(new Vector3(0.1f, 0, 1.0f));
565564

566-
// yield return RuntimeTestUtilities.WaitForUpdates();
567-
// Assert.That(slider.Value, Is.GreaterThan(initialSliderValue), "Slider didn't move after moving the new interactor");
565+
yield return RuntimeTestUtilities.WaitForUpdates();
566+
Assert.That(slider.Value, Is.GreaterThan(initialSliderValue), "Slider didn't move after moving the new interactor");
568567

569-
// // clean up
570-
// Object.Destroy(sliderObject);
571-
// }
568+
// clean up
569+
Object.Destroy(sliderObject);
570+
}
572571

573572
#endregion Tests
574573

@@ -579,7 +578,7 @@ private IEnumerator DirectPinchAndMoveSlider(Slider slider, float toSliderValue)
579578
InputTestUtilities.SetHandAnchorPoint(Handedness.Left, Input.Simulation.ControllerAnchorPoint.Grab);
580579
InputTestUtilities.SetHandAnchorPoint(Handedness.Right, Input.Simulation.ControllerAnchorPoint.Grab);
581580

582-
Debug.Log($"moving hand to value {toSliderValue}");
581+
Debug.Log($"Moving hand to value {toSliderValue}");
583582
var rightHand = new TestHand(Handedness.Right);
584583
Vector3 initialPos = InputTestUtilities.InFrontOfUser(new Vector3(0.05f, 0, 1.0f));
585584
yield return rightHand.Show(initialPos);
@@ -593,7 +592,7 @@ private IEnumerator DirectPinchAndMoveSlider(Slider slider, float toSliderValue)
593592
yield return rightHand.SetHandshape(HandshapeId.Pinch, 30);
594593
yield return RuntimeTestUtilities.WaitForUpdates();
595594

596-
if (!(toSliderValue >= 0 && toSliderValue <= 1))
595+
if (toSliderValue < 0 || toSliderValue > 1)
597596
{
598597
throw new System.ArgumentException("toSliderValue must be between 0 and 1");
599598
}

0 commit comments

Comments
 (0)