Skip to content

CHANGE: Update XR tests to use InputDeviceCharacteristics #1655

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 39 additions & 40 deletions Assets/Tests/InputSystem/Plugins/XRTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,14 @@ internal class XRTests : CoreTestsFixture
{
[Test]
[Category("Devices")]
[TestCase(InputDeviceRole.Generic, "XRHMD", typeof(XRHMD))]
[TestCase(InputDeviceRole.LeftHanded, "XRController", typeof(XRController))]
[TestCase(InputDeviceRole.RightHanded, "XRController", typeof(XRController))]
[TestCase(InputDeviceRole.HardwareTracker, null, typeof(UnityEngine.InputSystem.InputDevice))]
[TestCase(InputDeviceRole.TrackingReference, null, typeof(UnityEngine.InputSystem.InputDevice))]
[TestCase(InputDeviceRole.GameController, null, typeof(UnityEngine.InputSystem.InputDevice))]
[TestCase(InputDeviceRole.Unknown, null, typeof(UnityEngine.InputSystem.InputDevice))]
public void Devices_XRDeviceRoleDeterminesTypeOfDevice(InputDeviceRole role, string baseLayoutName, Type expectedType)
[TestCase(InputDeviceCharacteristics.HeadMounted, "XRHMD", typeof(XRHMD))]
[TestCase((InputDeviceCharacteristics.HeldInHand | InputDeviceCharacteristics.Controller), "XRController", typeof(XRController))]
[TestCase((InputDeviceCharacteristics.HeldInHand | InputDeviceCharacteristics.Controller | InputDeviceCharacteristics.Left), "XRController", typeof(XRController))]
[TestCase(InputDeviceCharacteristics.TrackedDevice, null, typeof(UnityEngine.InputSystem.InputDevice))]
[TestCase(InputDeviceCharacteristics.None, null, typeof(UnityEngine.InputSystem.InputDevice))]
public void Devices_XRDeviceCharacteristicsDeterminesTypeOfDevice(InputDeviceCharacteristics characteristics, string baseLayoutName, Type expectedType)
{
var deviceDescription = CreateSimpleDeviceDescriptionByRole(role);
var deviceDescription = CreateSimpleDeviceDescriptionByType(characteristics);
runtime.ReportNewInputDevice(deviceDescription.ToJson());

InputSystem.Update();
Expand All @@ -44,6 +42,7 @@ public void Devices_XRDeviceRoleDeterminesTypeOfDevice(InputDeviceRole role, str

var generatedLayout = InputSystem.LoadLayout(
$"{XRUtilities.InterfaceCurrent}::{deviceDescription.manufacturer}::{deviceDescription.product}");

Assert.That(generatedLayout, Is.Not.Null);
if (baseLayoutName == null)
Assert.That(generatedLayout.baseLayouts, Is.Empty);
Expand All @@ -55,7 +54,8 @@ public void Devices_XRDeviceRoleDeterminesTypeOfDevice(InputDeviceRole role, str
[Category("Devices")]
public void Devices_CanChangeHandednessOfXRController()
{
var deviceDescription = CreateSimpleDeviceDescriptionByRole(InputDeviceRole.LeftHanded);
var deviceDescription = CreateSimpleDeviceDescriptionByType(InputDeviceCharacteristics.Controller | InputDeviceCharacteristics.HeldInHand | InputDeviceCharacteristics.Left);

runtime.ReportNewInputDevice(deviceDescription.ToJson());

InputSystem.Update();
Expand All @@ -79,7 +79,7 @@ public void Devices_CanChangeHandednessOfXRController()
[Category("Layouts")]
public void Layouts_XRLayoutIsNamespacedAsInterfaceManufacturerDevice()
{
var deviceDescription = CreateSimpleDeviceDescriptionByRole(InputDeviceRole.Generic);
var deviceDescription = CreateSimpleDeviceDescriptionByType(InputDeviceCharacteristics.HeadMounted);
runtime.ReportNewInputDevice(deviceDescription.ToJson());

InputSystem.Update();
Expand All @@ -96,7 +96,7 @@ public void Layouts_XRLayoutIsNamespacedAsInterfaceManufacturerDevice()
[Category("Layouts")]
public void Layouts_XRLayoutWithoutManufacturer_IsNamespacedAsInterfaceDevice()
{
var deviceDescription = CreateSimpleDeviceDescriptionByRole(InputDeviceRole.Generic);
var deviceDescription = CreateSimpleDeviceDescriptionByType(InputDeviceCharacteristics.HeadMounted);
deviceDescription.manufacturer = null;
runtime.ReportNewInputDevice(deviceDescription.ToJson());

Expand Down Expand Up @@ -146,7 +146,7 @@ public void Layouts_XRLayoutFeatures_OnlyContainAllowedCharacters()
[Category("Layouts")]
public void Layouts_XRDevicesWithNoOrInvalidCapabilities_DoNotCreateLayouts()
{
var deviceDescription = CreateSimpleDeviceDescriptionByRole(InputDeviceRole.Generic);
var deviceDescription = CreateSimpleDeviceDescriptionByType(InputDeviceCharacteristics.HeadMounted);
deviceDescription.capabilities = null;
runtime.ReportNewInputDevice(deviceDescription.ToJson());

Expand Down Expand Up @@ -746,29 +746,31 @@ public void Layouts_PoseControlsCanBeCreatedBySubcontrols()

private const int kNumBaseHMDControls = 10;

static InputDeviceCharacteristics CharacteristicsFromInputDeviceRole(InputDeviceRole role)
InputDeviceRole RoleFromCharacteristics(InputDeviceCharacteristics characteristics)
{
switch (role)
{
case InputDeviceRole.Generic:
return InputDeviceCharacteristics.HeadMounted;
case InputDeviceRole.LeftHanded:
return InputDeviceCharacteristics.Controller | InputDeviceCharacteristics.HeldInHand | InputDeviceCharacteristics.Left;
case InputDeviceRole.RightHanded:
return InputDeviceCharacteristics.Controller | InputDeviceCharacteristics.HeldInHand | InputDeviceCharacteristics.Right;
case InputDeviceRole.GameController:
return InputDeviceCharacteristics.Controller;
case InputDeviceRole.TrackingReference:
return InputDeviceCharacteristics.TrackingReference;
case InputDeviceRole.HardwareTracker:
return InputDeviceCharacteristics.TrackedDevice;
case InputDeviceRole.LegacyController:
return InputDeviceCharacteristics.Controller;
}
return InputDeviceCharacteristics.None;
if ((characteristics & InputDeviceCharacteristics.Left) != 0)
return InputDeviceRole.LeftHanded;
if ((characteristics & InputDeviceCharacteristics.Right) != 0)
return InputDeviceRole.RightHanded;
if ((characteristics & InputDeviceCharacteristics.TrackingReference) != 0)
return InputDeviceRole.TrackingReference;
if ((characteristics & InputDeviceCharacteristics.HeadMounted) != 0)
return InputDeviceRole.Generic;
if ((characteristics & InputDeviceCharacteristics.HeldInHand) != 0)
return InputDeviceRole.Generic;
if ((characteristics & InputDeviceCharacteristics.EyeTracking) != 0)
return InputDeviceRole.Generic;
if ((characteristics & InputDeviceCharacteristics.Camera) != 0)
return InputDeviceRole.Generic;
if ((characteristics & InputDeviceCharacteristics.Controller) != 0)
return InputDeviceRole.GameController;
if ((characteristics & InputDeviceCharacteristics.TrackedDevice) != 0)
return InputDeviceRole.HardwareTracker;

return InputDeviceRole.LegacyController;
}

private static InputDeviceDescription CreateSimpleDeviceDescriptionByRole(InputDeviceRole role)
private static InputDeviceDescription CreateSimpleDeviceDescriptionByType(InputDeviceCharacteristics deviceCharacteristics)
{
return new InputDeviceDescription
{
Expand All @@ -777,7 +779,7 @@ private static InputDeviceDescription CreateSimpleDeviceDescriptionByRole(InputD
manufacturer = "Manufacturer",
capabilities = new XRDeviceDescriptor
{
characteristics = CharacteristicsFromInputDeviceRole(role),
characteristics = deviceCharacteristics,
inputFeatures = new List<XRFeatureDescriptor>()
{
new XRFeatureDescriptor()
Expand All @@ -799,7 +801,7 @@ private static InputDeviceDescription CreateMangledNameDeviceDescription()
manufacturer = "__Manufacturer::",
capabilities = new XRDeviceDescriptor
{
characteristics = CharacteristicsFromInputDeviceRole(InputDeviceRole.Generic),
characteristics = InputDeviceCharacteristics.HeadMounted,
inputFeatures = new List<XRFeatureDescriptor>()
{
new XRFeatureDescriptor()
Expand Down Expand Up @@ -833,7 +835,7 @@ public static InputDeviceDescription CreateDeviceDescription()
manufacturer = "XRManufacturer",
capabilities = new XRDeviceDescriptor
{
characteristics = CharacteristicsFromInputDeviceRole(InputDeviceRole.Generic),
characteristics = InputDeviceCharacteristics.HeadMounted,
inputFeatures = new List<XRFeatureDescriptor>()
{
new XRFeatureDescriptor()
Expand Down Expand Up @@ -905,7 +907,7 @@ public static InputDeviceDescription CreateDeviceDescription()
manufacturer = "XRManufacturer",
capabilities = new XRDeviceDescriptor
{
characteristics = CharacteristicsFromInputDeviceRole(InputDeviceRole.Generic),
characteristics = InputDeviceCharacteristics.HeadMounted,
inputFeatures = new List<XRFeatureDescriptor>()
{
new XRFeatureDescriptor()
Expand Down Expand Up @@ -1039,9 +1041,6 @@ public static InputDeviceDescription CreateDeviceDescription()
manufacturer = "XRManufacturer",
capabilities = new XRDeviceDescriptor
{
#if !UNITY_2019_3_OR_NEWER
deviceRole = InputDeviceRole.Generic,
#endif
inputFeatures = new List<XRFeatureDescriptor>()
{
new XRFeatureDescriptor()
Expand Down