SeedXRInputBindingsTests.cs
5.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
using UnityEngine;
using UnityEngine.TestTools;
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
using UnityEditor.XR.LegacyInputHelpers;
using UnityEditor;
namespace UnityEditor.XR.LegacyInputHelpers.Tests
{
[TestFixture]
internal class TestSeededInput
{
const int kNumOverlaps = 4; // we know there are four overlaps between the input asset, and the seeded assets.
const int kNumDupesToKeep = 2;
[Test]
public void SeededInput_FillsOutCompleteData()
{
// load the input asset
var inputManagerAsset = AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/InputManager.asset")[0];
var serializedObject = new SerializedObject(inputManagerAsset);
var inputManagerCurrentData = serializedObject.FindProperty("m_Axes");
// cache the number of items so we can reset.
int prevInputManagerSize = inputManagerCurrentData.arraySize;
SeedXRInputBindings tsxib = new SeedXRInputBindings();
Dictionary<string, SeedXRInputBindings.BindingData> axisMap = new Dictionary<string, SeedXRInputBindings.BindingData>();
for (int i = 0; i < tsxib.axisList.Count; ++i)
{
axisMap.Add(tsxib.axisList[i].name, new SeedXRInputBindings.BindingData() { newDataIndex = i, exists = false, inputManagerIndex = -1 });
}
tsxib.GenerateXRBindings();
inputManagerAsset = AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/InputManager.asset")[0];
serializedObject = new SerializedObject(inputManagerAsset);
inputManagerCurrentData = serializedObject.FindProperty("m_Axes");
// did we create the right number of things?
Assert.That(inputManagerCurrentData.arraySize == (prevInputManagerSize + tsxib.axisList.Count) - kNumOverlaps); // we subtract kNumOverlaps because we know there are 4 things duplicated and they shouldnt be included.
List<SeedXRInputBindings.InputAxis> currentInputData = new List<SeedXRInputBindings.InputAxis>();
tsxib.LoadExistingDataAndCheckAgainstNewData(inputManagerCurrentData, ref axisMap, ref currentInputData);
// the axis map should now be true for every element.
foreach(var item in axisMap)
{
Assert.That(item.Value.exists == true);
}
inputManagerCurrentData.arraySize = prevInputManagerSize;
serializedObject.ApplyModifiedProperties();
AssetDatabase.Refresh();
}
[Test]
public void SeededInput_DoesntAddDuplicates()
{
// load the input asset
var inputManagerAsset = AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/InputManager.asset")[0];
var serializedObject = new SerializedObject(inputManagerAsset);
var inputManagerCurrentData = serializedObject.FindProperty("m_Axes");
// cache the number of items so we can reset.
int prevInputManagerSize = inputManagerCurrentData.arraySize;
inputManagerCurrentData.arraySize = 0;
SeedXRInputBindings tsxib = new SeedXRInputBindings();
Dictionary<string, SeedXRInputBindings.BindingData> axisMap = new Dictionary<string, SeedXRInputBindings.BindingData>();
for (int i = 0; i < tsxib.axisList.Count; ++i)
{
axisMap.Add(tsxib.axisList[i].name, new SeedXRInputBindings.BindingData() { newDataIndex = i, exists = false, inputManagerIndex = -1 });
}
tsxib.GenerateXRBindings();
// slam back the value to a smaller number
inputManagerAsset = AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/InputManager.asset")[0];
serializedObject = new SerializedObject(inputManagerAsset);
inputManagerCurrentData = serializedObject.FindProperty("m_Axes");
// we want to maintain a few records to ensure that we dont add duplicates.
inputManagerCurrentData.arraySize = kNumDupesToKeep;
List<SeedXRInputBindings.InputAxis> currentInputData = new List<SeedXRInputBindings.InputAxis>();
tsxib.LoadExistingDataAndCheckAgainstNewData(inputManagerCurrentData, ref axisMap, ref currentInputData);
// now, we should only have two elements that match, seeing as we only left two items in the asset.
int trueCount = 0;
foreach (var item in axisMap)
{
if (item.Value.exists)
trueCount++;
}
Assert.That(trueCount == kNumDupesToKeep);
tsxib.GenerateXRBindings();
inputManagerAsset = AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/InputManager.asset")[0];
serializedObject = new SerializedObject(inputManagerAsset);
inputManagerCurrentData = serializedObject.FindProperty("m_Axes");
Assert.That(inputManagerCurrentData.arraySize == (prevInputManagerSize + tsxib.axisList.Count) - kNumOverlaps); // we subtract kNumOverlaps because we know there are 4 things duplicated and they shouldnt be included.
tsxib.LoadExistingDataAndCheckAgainstNewData(inputManagerCurrentData, ref axisMap, ref currentInputData);
// the axis map should now be true for every element.
foreach (var item in axisMap)
{
Assert.That(item.Value.exists == true);
}
inputManagerCurrentData.arraySize = prevInputManagerSize;
serializedObject.ApplyModifiedProperties();
AssetDatabase.Refresh();
}
}
}