Skip to content

Commit bb34a67

Browse files
authored
Various test improvements (#1073)
* Formatting * Fix test referring to the wrong interactable * Add a few more smoke tests * Update InteractionModeManagerTests.cs * Adding visibility modifier * Docs updates * Restore a commented-out test and Ignore it instead
1 parent 9fdcb39 commit bb34a67

9 files changed

Lines changed: 90 additions & 74 deletions

File tree

org.mixedrealitytoolkit.core/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
99
* Updated code style in `HandsSubsystemDescriptor`, `MRTKSubsystemDescriptor`, `DictationSubsystemDescriptor`, and `XRSubsystemHelpers`. [PR #1109](https://github.com/MixedRealityToolkit/MixedRealityToolkit-Unity/pull/1109)
1010
* Updated `PackageValidator` to only be valid if `UNITY_EDITOR` is true. [PR #1125](https://github.com/MixedRealityToolkit/MixedRealityToolkit-Unity/pull/1125)
1111
* `AssemblyExtensions.GetLoadableTypes` now throws `ArgumentNullException` when called on a null assembly instead of `NullReferenceException`. [PR #1122](https://github.com/MixedRealityToolkit/MixedRealityToolkit-Unity/pull/1122)
12+
* Updated `MRTKBaseInteractable` to follow MRTK style. [PR #1073](https://github.com/MixedRealityToolkit/MixedRealityToolkit-Unity/pull/1073)
1213

1314
### Added
1415

1516
* Added edit mode tests for `AssemblyExtensions`, `SystemType`, and `SerializableDictionary`. [PR #1122](https://github.com/MixedRealityToolkit/MixedRealityToolkit-Unity/pull/1122)
1617

1718
### Fixed
1819

19-
* Fixed "The type MixedReality.Toolkit.Core MixedReality.Toolkit.Experimental.BubbleChildHoverEvents/TrickleChildHoverEvents/BubbleChildSelectEvents/TrickleChildSelectEvents is being serialized by `[SerializeReference]`, but is missing the `[Serializable]` attribute." on Unity 6.3. [PR #1107](https://github.com/MixedRealityToolkit/MixedRealityToolkit-Unity/pull/1107)
20+
* Fixed "The type `MixedReality.Toolkit.Core MixedReality.Toolkit.Experimental.BubbleChildHoverEvents/TrickleChildHoverEvents/BubbleChildSelectEvents/TrickleChildSelectEvents` is being serialized by `[SerializeReference]`, but is missing the `[Serializable]` attribute." on Unity 6.3. [PR #1107](https://github.com/MixedRealityToolkit/MixedRealityToolkit-Unity/pull/1107)
2021

2122
## Deprecated
2223

org.mixedrealitytoolkit.core/Interactables/MRTKBaseInteractable.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class MRTKBaseInteractable : XRBaseInteractable
1717
{
1818
#region Gaze
1919

20-
readonly List<IGazeInteractor> hoveringGazeInteractors = new List<IGazeInteractor>();
20+
private readonly List<IGazeInteractor> hoveringGazeInteractors = new List<IGazeInteractor>();
2121

2222
/// <summary>
2323
/// (Read Only) The list of <see cref="IGazeInteractor"/> components currently gazing this object.
@@ -28,14 +28,14 @@ public class MRTKBaseInteractable : XRBaseInteractable
2828

2929
#region GazePinch
3030

31-
readonly List<IGazePinchInteractor> hoveringGazePinchInteractors = new List<IGazePinchInteractor>();
31+
private readonly List<IGazePinchInteractor> hoveringGazePinchInteractors = new List<IGazePinchInteractor>();
3232

3333
/// <summary>
3434
/// (Read Only) The list of <see cref="IGazePinchInteractor"/> components currently hovering this object.
3535
/// </summary>
3636
public List<IGazePinchInteractor> HoveringGazePinchInteractors => hoveringGazePinchInteractors;
3737

38-
readonly List<IGazePinchInteractor> selectingGazePinchInteractors = new List<IGazePinchInteractor>();
38+
private readonly List<IGazePinchInteractor> selectingGazePinchInteractors = new List<IGazePinchInteractor>();
3939

4040
/// <summary>
4141
/// (Read Only) The list of <see cref="IGazePinchInteractor"/> components currently selecting this object.
@@ -46,7 +46,7 @@ public class MRTKBaseInteractable : XRBaseInteractable
4646

4747
#region Poke
4848

49-
readonly List<IPokeInteractor> hoveringPokeInteractors = new List<IPokeInteractor>();
49+
private readonly List<IPokeInteractor> hoveringPokeInteractors = new List<IPokeInteractor>();
5050

5151
/// <summary>
5252
/// (Read Only) The list of <see cref="IPokeInteractor"/> components currently hovering this object.
@@ -57,14 +57,14 @@ public class MRTKBaseInteractable : XRBaseInteractable
5757

5858
#region Grab
5959

60-
readonly List<IGrabInteractor> hoveringGrabInteractors = new List<IGrabInteractor>();
60+
private readonly List<IGrabInteractor> hoveringGrabInteractors = new List<IGrabInteractor>();
6161

6262
/// <summary>
6363
/// (Read Only) The list of <see cref="IGrabInteractor"/> components currently hovering this object.
6464
/// </summary>]
6565
public List<IGrabInteractor> HoveringGrabInteractors => hoveringGrabInteractors;
6666

67-
readonly List<IGrabInteractor> selectingGrabInteractors = new List<IGrabInteractor>();
67+
private readonly List<IGrabInteractor> selectingGrabInteractors = new List<IGrabInteractor>();
6868

6969
/// <summary>
7070
/// (Read Only) The list of <see cref="IGrabInteractor"/> components currently selecting this object.
@@ -75,7 +75,7 @@ public class MRTKBaseInteractable : XRBaseInteractable
7575

7676
#region Ray
7777

78-
readonly List<IRayInteractor> hoveringRayInteractors = new List<IRayInteractor>();
78+
private readonly List<IRayInteractor> hoveringRayInteractors = new List<IRayInteractor>();
7979

8080
/// <summary>
8181
/// (Read Only) The list of <see cref="IRayInteractor"/> components currently hovering this object.
@@ -93,7 +93,7 @@ public class MRTKBaseInteractable : XRBaseInteractable
9393
/// <summary>
9494
/// Is this object selected by a gaze-pinch interactor?
9595
/// </summary>
96-
public TimedFlag IsGazePinchSelected { get => isGazePinchSelected; }
96+
public TimedFlag IsGazePinchSelected => isGazePinchSelected;
9797

9898
[SerializeField]
9999
[Tooltip("Is this object selected by a non-gaze ray interactor?")]
@@ -102,7 +102,7 @@ public class MRTKBaseInteractable : XRBaseInteractable
102102
/// <summary>
103103
/// Is this object selected by a non-gaze ray interactor?
104104
/// </summary>
105-
public TimedFlag IsRaySelected { get => isRaySelected; }
105+
public TimedFlag IsRaySelected => isRaySelected;
106106

107107
[SerializeField]
108108
[Tooltip("Is this object selected by a poke interactor?")]
@@ -111,7 +111,7 @@ public class MRTKBaseInteractable : XRBaseInteractable
111111
/// <summary>
112112
/// Is this object selected by a poke interactor?
113113
/// </summary>
114-
public TimedFlag IsPokeSelected { get => isPokeSelected; }
114+
public TimedFlag IsPokeSelected => isPokeSelected;
115115

116116
[SerializeField]
117117
[Tooltip("Is this object selected by a grab interactor?")]
@@ -120,7 +120,7 @@ public class MRTKBaseInteractable : XRBaseInteractable
120120
/// <summary>
121121
/// Is this object selected by a grab interactor?
122122
/// </summary>
123-
public TimedFlag IsGrabSelected { get => isGrabSelected; }
123+
public TimedFlag IsGrabSelected => isGrabSelected;
124124

125125
[SerializeField]
126126
[Tooltip("Is this object hovered by any gaze interactor?")]
@@ -129,7 +129,7 @@ public class MRTKBaseInteractable : XRBaseInteractable
129129
/// <summary>
130130
/// Is this object hovered by any gaze interactor?
131131
/// </summary>
132-
public TimedFlag IsGazeHovered { get => isGazeHovered; }
132+
public TimedFlag IsGazeHovered => isGazeHovered;
133133

134134
[SerializeField]
135135
[Tooltip("Is this object hovered by a gaze-pinch interactor?")]
@@ -138,7 +138,7 @@ public class MRTKBaseInteractable : XRBaseInteractable
138138
/// <summary>
139139
/// Is this object hovered by a gaze-pinch interactor?
140140
/// </summary>
141-
public TimedFlag IsGazePinchHovered { get => isGazePinchHovered; }
141+
public TimedFlag IsGazePinchHovered => isGazePinchHovered;
142142

143143
[SerializeField]
144144
[Tooltip("Is this object hovered by a non-gaze ray interactor?")]
@@ -147,7 +147,7 @@ public class MRTKBaseInteractable : XRBaseInteractable
147147
/// <summary>
148148
/// Is this object hovered by a non-gaze ray interactor?
149149
/// </summary>
150-
public TimedFlag IsRayHovered { get => isRayHovered; }
150+
public TimedFlag IsRayHovered => isRayHovered;
151151

152152
[SerializeField]
153153
[Tooltip("Is this object hovered by a grab interactor?")]
@@ -156,7 +156,7 @@ public class MRTKBaseInteractable : XRBaseInteractable
156156
/// <summary>
157157
/// Is this object hovered by a grab interactor?
158158
/// </summary>
159-
public TimedFlag IsGrabHovered { get => isGrabHovered; }
159+
public TimedFlag IsGrabHovered => isGrabHovered;
160160

161161
[SerializeField]
162162
[Tooltip("Is this object hovered by a near touch/poke interactor?")]
@@ -166,12 +166,12 @@ public class MRTKBaseInteractable : XRBaseInteractable
166166
/// <summary>
167167
/// Is this object hovered by a near touch/poke interactor?
168168
/// </summary>
169-
public TimedFlag IsPokeHovered { get => isPokeHovered; }
169+
public TimedFlag IsPokeHovered => isPokeHovered;
170170

171171
/// <summary>
172172
/// Is this object hovered by any interactor other than passive targeting interactors?
173173
/// </summary>
174-
public TimedFlag IsActiveHovered { get => isActiveHovered; }
174+
public TimedFlag IsActiveHovered => isActiveHovered;
175175

176176
[SerializeField]
177177
[Tooltip("Is this object hovered by any interactor other than only passive targeting interactors?")]
@@ -199,7 +199,7 @@ public void DisableInteractorType(SystemInterfaceType type)
199199
}
200200
}
201201
/// <summary>
202-
/// Removes the specified type to the set of interactors which cannot select this interactable
202+
/// Removes the specified type from the set of interactors which cannot select this interactable
203203
/// </summary>
204204
public void EnableInteractorType(SystemInterfaceType type)
205205
{

org.mixedrealitytoolkit.input/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
77
### Changed
88

99
* Reserialized MRTK XR Rig prefab to remove stale serialized fields. [PR #1110](https://github.com/MixedRealityToolkit/MixedRealityToolkit-Unity/pull/1110)
10+
* Updated tests to follow existing MRTK test patterns. [PR #1073](https://github.com/MixedRealityToolkit/MixedRealityToolkit-Unity/pull/1073)
1011

1112
### Fixed
1213

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

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,15 @@
55
#pragma warning disable CS1591
66

77
using MixedReality.Toolkit.Core.Tests;
8+
using MixedReality.Toolkit.Input.Simulation;
9+
using MixedReality.Toolkit.Subsystems;
810
using NUnit.Framework;
911
using System.Collections;
10-
using System.Collections.Generic;
1112
using UnityEngine;
1213
using UnityEngine.InputSystem;
1314
using UnityEngine.TestTools;
1415
using UnityEngine.XR;
1516
using UnityEngine.XR.Interaction.Toolkit;
16-
using MixedReality.Toolkit.Input;
17-
using MixedReality.Toolkit.Input.Simulation;
18-
using MixedReality.Toolkit;
19-
using MixedReality.Toolkit.Subsystems;
20-
2117
using HandshapeId = MixedReality.Toolkit.Input.HandshapeTypes.HandshapeId;
2218

2319
namespace MixedReality.Toolkit.Input.Tests
@@ -31,7 +27,7 @@ public class BasicInputTests : BaseRuntimeInputTests
3127
/// Ensure the simulated input devices are registered and present.
3228
/// </summary>
3329
[UnityTest]
34-
public IEnumerator InputDeviceSmoketest()
30+
public IEnumerator InputDeviceSmokeTest()
3531
{
3632
foreach (var device in InputSystem.devices)
3733
{
@@ -45,9 +41,10 @@ public IEnumerator InputDeviceSmoketest()
4541
/// Ensure the simulated input devices bind to the controllers on the rig.
4642
/// </summary>
4743
[UnityTest]
48-
public IEnumerator InputBindingSmoketest()
44+
public IEnumerator InputBindingSmokeTest()
4945
{
50-
var controllers = new[] {
46+
XRBaseController[] controllers =
47+
{
5148
CachedLookup.LeftHandController,
5249
CachedLookup.RightHandController,
5350
CachedLookup.GazeController
@@ -69,7 +66,7 @@ public IEnumerator InputBindingSmoketest()
6966
/// Ensure the simulated input device actually makes the rig's controllers move/actuate.
7067
/// </summary>
7168
[UnityTest]
72-
public IEnumerator HandMovingSmoketest()
69+
public IEnumerator HandMovingSmokeTest()
7370
{
7471
var controller = CachedLookup.RightHandController as ActionBasedController;
7572

@@ -107,7 +104,7 @@ public IEnumerator GrabAnchorTest()
107104
Vector3 cubePos = InputTestUtilities.InFrontOfUser();
108105
cube.transform.position = cubePos;
109106
cube.transform.localScale = Vector3.one * 1.0f;
110-
107+
111108
var testHand = new TestHand(Handedness.Right);
112109
InputTestUtilities.SetHandAnchorPoint(Handedness.Right, ControllerAnchorPoint.Grab);
113110

@@ -136,32 +133,28 @@ public IEnumerator GrabAnchorTest()
136133
public IEnumerator StatefulInteractableSmokeTest()
137134
{
138135
GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
139-
cube.AddComponent<StatefulInteractable>();
136+
StatefulInteractable firstCubeInteractable = cube.AddComponent<StatefulInteractable>();
140137
cube.transform.position = InputTestUtilities.InFrontOfUser(new Vector3(0.2f, 0.2f, 0.5f));
141138
cube.transform.localScale = Vector3.one * 0.1f;
142139

143140
// For this test, we won't use poke selection.
144-
cube.GetComponent<StatefulInteractable>().DisableInteractorType(typeof(PokeInteractor));
141+
firstCubeInteractable.DisableInteractorType(typeof(PokeInteractor));
145142

146143
GameObject cube2 = GameObject.CreatePrimitive(PrimitiveType.Cube);
147-
cube2.AddComponent<StatefulInteractable>();
144+
StatefulInteractable secondCubeInteractable = cube2.AddComponent<StatefulInteractable>();
148145
cube2.transform.position = InputTestUtilities.InFrontOfUser(new Vector3(-0.2f, -0.2f, 0.5f));
149146
cube2.transform.localScale = Vector3.one * 0.1f;
150147

151148
// For this test, we won't use poke selection.
152-
cube2.GetComponent<StatefulInteractable>().DisableInteractorType(typeof(PokeInteractor));
149+
secondCubeInteractable.DisableInteractorType(typeof(PokeInteractor));
153150

154151
var rightHand = new TestHand(Handedness.Right);
155152

156153
yield return rightHand.Show(InputTestUtilities.InFrontOfUser(0.5f));
157-
158154
yield return RuntimeTestUtilities.WaitForUpdates();
159155

160156
bool shouldTestToggle = false;
161157

162-
StatefulInteractable firstCubeInteractable = cube.GetComponent<StatefulInteractable>();
163-
StatefulInteractable secondCubeInteractable = cube2.GetComponent<StatefulInteractable>();
164-
165158
for (int i = 0; i < 5; i++)
166159
{
167160
// Flip this back and forth to test both toggleability and un-toggleability
@@ -176,27 +169,33 @@ public IEnumerator StatefulInteractableSmokeTest()
176169
firstCubeInteractable.TriggerOnRelease = (i % 2) == 0;
177170

178171
Assert.IsFalse(firstCubeInteractable.IsGrabHovered,
172+
"StatefulInteractable was already GrabHovered.");
173+
Assert.IsFalse(firstCubeInteractable.isHovered,
179174
"StatefulInteractable was already hovered.");
180175

181176
yield return rightHand.MoveTo(cube.transform.position);
182177
yield return RuntimeTestUtilities.WaitForUpdates();
183178
Assert.IsTrue(firstCubeInteractable.IsGrabHovered,
179+
"StatefulInteractable did not get GrabHovered.");
180+
Assert.IsTrue(firstCubeInteractable.isHovered,
184181
"StatefulInteractable did not get hovered.");
185182

186183
yield return rightHand.SetHandshape(HandshapeId.Pinch);
187184
yield return RuntimeTestUtilities.WaitForUpdates();
188185
Assert.IsTrue(firstCubeInteractable.IsGrabSelected,
189186
"StatefulInteractable did not get GrabSelected.");
187+
Assert.IsTrue(firstCubeInteractable.isSelected,
188+
"StatefulInteractable did not get selected.");
190189

191190
if (shouldTestToggle)
192191
{
193-
if (secondCubeInteractable.TriggerOnRelease)
192+
if (firstCubeInteractable.TriggerOnRelease)
194193
{
195-
Assert.IsFalse(secondCubeInteractable.IsToggled, "StatefulInteractable toggled on press, when it was set to be toggled on release.");
194+
Assert.IsFalse(firstCubeInteractable.IsToggled, "StatefulInteractable toggled on press, when it was set to be toggled on release.");
196195
}
197196
else
198197
{
199-
Assert.IsFalse(secondCubeInteractable.IsToggled, "StatefulInteractable didn't toggled on press, when it was set to be toggled on press.");
198+
Assert.IsFalse(firstCubeInteractable.IsToggled, "StatefulInteractable didn't toggled on press, when it was set to be toggled on press.");
200199
}
201200
}
202201

@@ -225,17 +224,23 @@ public IEnumerator StatefulInteractableSmokeTest()
225224
yield return RuntimeTestUtilities.WaitForUpdates();
226225

227226
Assert.IsFalse(secondCubeInteractable.IsGrabHovered,
227+
"StatefulInteractable was already GrabHovered.");
228+
Assert.IsFalse(secondCubeInteractable.isHovered,
228229
"StatefulInteractable was already hovered.");
229230

230231
yield return rightHand.MoveTo(secondCubeInteractable.transform.position);
231232
yield return RuntimeTestUtilities.WaitForUpdates();
232233
Assert.IsTrue(secondCubeInteractable.IsGrabHovered,
234+
"StatefulInteractable did not get GrabHovered.");
235+
Assert.IsTrue(secondCubeInteractable.isHovered,
233236
"StatefulInteractable did not get hovered.");
234237

235238
yield return rightHand.SetHandshape(HandshapeId.Pinch);
236239
yield return RuntimeTestUtilities.WaitForUpdates();
237240
Assert.IsTrue(secondCubeInteractable.IsGrabSelected,
238241
"StatefulInteractable did not get GrabSelected.");
242+
Assert.IsTrue(secondCubeInteractable.isSelected,
243+
"StatefulInteractable did not get selected.");
239244

240245
if (shouldTestToggle)
241246
{
@@ -303,7 +308,7 @@ public IEnumerator GazePinchSmokeTest()
303308

304309
yield return rightHand.SetHandshape(HandshapeId.Open);
305310
yield return RuntimeTestUtilities.WaitForUpdates();
306-
311+
307312
Assert.IsFalse(interactable.isSelected);
308313
Assert.IsFalse(interactable.IsGazePinchSelected);
309314
Assert.IsTrue(interactable.isHovered);
@@ -388,7 +393,7 @@ public IEnumerator ToggleHydrationTest()
388393

389394
didFireEvent = false;
390395
interactable.ForceSetToggled(true, fireEvents: false);
391-
396+
392397
Assert.IsTrue(interactable.IsToggled, "Interactable didn't get toggled.");
393398
Assert.IsFalse(didFireEvent, "ForceSetToggled(true, fireEvents:false) should NOT have fired the event.");
394399

@@ -493,7 +498,7 @@ public IEnumerator SpawnInteractableOnHand()
493498

494499
// Move hand far away.
495500
yield return rightHand.MoveTo(new Vector3(2, 2, 2));
496-
yield return RuntimeTestUtilities.WaitForUpdates(frameCount:240);
501+
yield return RuntimeTestUtilities.WaitForUpdates(frameCount: 240);
497502

498503
Assert.IsFalse(AnyProximityDetectorsTriggered(), "Prox detectors should no longer be triggered.");
499504

@@ -608,4 +613,4 @@ private bool AnyProximityDetectorsTriggered()
608613
}
609614
}
610615
}
611-
#pragma warning restore CS1591
616+
#pragma warning restore CS1591

0 commit comments

Comments
 (0)