Skip to content

Commit 36ec9b9

Browse files
Adding test for pose is tracked fix
1 parent 40aaca8 commit 36ec9b9

1 file changed

Lines changed: 46 additions & 0 deletions

File tree

Assets/Tests/InputSystem/Plugins/XRTests.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,6 +1222,52 @@ public void Controls_OptimizedControls_PoseControl_IsOptimized()
12221222
Assert.That((device["posecontrol"] as PoseControl).optimizedControlDataType, Is.EqualTo(InputStateBlock.FormatPose));
12231223
}
12241224

1225+
[Test]
1226+
[Category("Controls")]
1227+
[TestCase(true)]
1228+
[TestCase(false)]
1229+
public void Controls_PoseControl_IsTracked_ReadsCorrectly(bool useOptimizedControls)
1230+
{
1231+
InputSystem.settings.SetInternalFeatureFlag(InputFeatureNames.kUseOptimizedControls, useOptimizedControls);
1232+
1233+
runtime.ReportNewInputDevice(PoseDeviceState.CreateDeviceDescription().ToJson());
1234+
1235+
InputSystem.Update();
1236+
1237+
var device = InputSystem.devices[0];
1238+
var poseControl = device["posecontrol"] as PoseControl;
1239+
1240+
// Queue state with isTracked = true (byte value 1)
1241+
InputSystem.QueueStateEvent(device, new PoseDeviceState
1242+
{
1243+
isTracked = 1,
1244+
trackingState = (uint)(InputTrackingState.Position | InputTrackingState.Rotation),
1245+
position = new Vector3(1, 2, 3),
1246+
rotation = Quaternion.identity,
1247+
});
1248+
InputSystem.Update();
1249+
1250+
// Reading isTracked as a ButtonControl should return true
1251+
Assert.That(poseControl.isTracked.isPressed, Is.True, "isTracked.isPressed should be true when tracked");
1252+
Assert.That(poseControl.isTracked.ReadValue(), Is.EqualTo(1.0f).Within(0.001f), "isTracked.ReadValue() should be 1.0f when tracked");
1253+
1254+
// Reading the full PoseState should also have isTracked = true
1255+
var poseState = poseControl.ReadValue();
1256+
Assert.That(poseState.isTracked, Is.True, "PoseState.isTracked should be true when tracked");
1257+
1258+
// Queue state with isTracked = false (byte value 0)
1259+
InputSystem.QueueStateEvent(device, new PoseDeviceState
1260+
{
1261+
isTracked = 0,
1262+
trackingState = 0,
1263+
});
1264+
InputSystem.Update();
1265+
1266+
Assert.That(poseControl.isTracked.isPressed, Is.False, "isTracked.isPressed should be false when not tracked");
1267+
Assert.That(poseControl.isTracked.ReadValue(), Is.EqualTo(0.0f).Within(0.001f), "isTracked.ReadValue() should be 0.0f when not tracked");
1268+
Assert.That(poseControl.ReadValue().isTracked, Is.False, "PoseState.isTracked should be false when not tracked");
1269+
}
1270+
12251271
// ISXB-405
12261272
[Test]
12271273
[Category("Devices")]

0 commit comments

Comments
 (0)