Skip to content

Commit 0a65443

Browse files
committed
refactor tests
1 parent 0bef5d2 commit 0a65443

File tree

1 file changed

+11
-28
lines changed

1 file changed

+11
-28
lines changed

Assets/Tests/InputSystem/CoreTests_MouseEvents.cs

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,29 @@
88
using UnityEngine.TestTools;
99
using Is = UnityEngine.TestTools.Constraints.Is;
1010

11-
1211
partial class CoreTests
1312
{
14-
internal GameObject SetUpScene()
13+
internal GameObject SetUpScene(Type pointerType, out Pointer pointer)
1514
{
1615
var gameObject = GameObject.CreatePrimitive(PrimitiveType.Cube);
1716
gameObject.transform.position = Vector3.zero;
1817
var camera = new GameObject("MainCamera").AddComponent<Camera>();
1918
camera.transform.position = new Vector3(0, 0, -2f);
2019
camera.tag = "MainCamera";
20+
pointer = (Pointer)InputSystem.s_Manager.AddDevice(pointerType);
21+
InputSystem.AddDevice(pointer);
2122
return gameObject;
2223
}
2324

24-
private static HashSet<Type> _testDevices = new HashSet<Type> { typeof(Mouse), typeof(Pen), typeof(Touchscreen) };
25+
private static readonly Type[] _testDevices = new Type[] { typeof(Mouse), typeof(Pen), typeof(Touchscreen) };
2526
// OnMouseOver/Exit and Hover events are not supported for touch
26-
private static HashSet<Type> _testDevicesNoTouch = new HashSet<Type> { typeof(Mouse), typeof(Pen) };
27+
private static readonly Type[] _testDevicesNoTouch = new Type[] { typeof(Mouse), typeof(Pen) };
2728

2829
[UnityTest]
2930
[Category("MouseEvents")]
3031
public IEnumerator MouseEvents_CanReceiveOnMouseDown([ValueSource(nameof(_testDevices))] Type pointerType)
3132
{
32-
var pointer = (Pointer)InputSystem.s_Manager.AddDevice(pointerType);
33-
InputSystem.AddDevice(pointer);
34-
35-
var gameObject = SetUpScene();
33+
var gameObject = SetUpScene(pointerType, out var pointer);
3634
gameObject.AddComponent<OnMouseEventsTest>();
3735
var vec = Camera.main.WorldToScreenPoint(gameObject.transform.position);
3836

@@ -46,10 +44,7 @@ public IEnumerator MouseEvents_CanReceiveOnMouseDown([ValueSource(nameof(_testDe
4644
[Category("MouseEvents")]
4745
public IEnumerator MouseEvents_CanReceiveOnMouseUp([ValueSource(nameof(_testDevices))] Type pointerType)
4846
{
49-
var pointer = (Pointer)InputSystem.s_Manager.AddDevice(pointerType);
50-
InputSystem.AddDevice(pointer);
51-
52-
var gameObject = SetUpScene();
47+
var gameObject = SetUpScene(pointerType, out var pointer);
5348
gameObject.AddComponent<OnMouseEventsTest>();
5449
var vec = Camera.main.WorldToScreenPoint(gameObject.transform.position);
5550
Set(pointer, new Vector2(vec.x, vec.y), true, false);
@@ -63,10 +58,7 @@ public IEnumerator MouseEvents_CanReceiveOnMouseUp([ValueSource(nameof(_testDevi
6358
[Category("MouseEvents")]
6459
public IEnumerator MouseEvents_CanReceiveOnMouseUpAsButton([ValueSource(nameof(_testDevices))] Type pointerType)
6560
{
66-
var pointer = (Pointer)InputSystem.s_Manager.AddDevice(pointerType);
67-
InputSystem.AddDevice(pointer);
68-
69-
var gameObject = SetUpScene();
61+
var gameObject = SetUpScene(pointerType, out var pointer);
7062
gameObject.AddComponent<OnMousEventTestTwo>();
7163
var vec = Camera.main.WorldToScreenPoint(gameObject.transform.position);
7264
Set(pointer, new Vector2(vec.x, vec.y), true, false);
@@ -80,10 +72,7 @@ public IEnumerator MouseEvents_CanReceiveOnMouseUpAsButton([ValueSource(nameof(_
8072
[Category("MouseEvents")]
8173
public IEnumerator MouseEvents_CanReceiveOnMouseDrag([ValueSource(nameof(_testDevices))] Type pointerType)
8274
{
83-
var pointer = (Pointer)InputSystem.s_Manager.AddDevice(pointerType);
84-
InputSystem.AddDevice(pointer);
85-
86-
var gameObject = SetUpScene();
75+
var gameObject = SetUpScene(pointerType, out var pointer);
8776
gameObject.AddComponent<OnMouseEventsTest>();
8877
var vec = Camera.main.WorldToScreenPoint(gameObject.transform.position);
8978
Set(pointer, new Vector2(vec.x, vec.y), false, false);
@@ -99,10 +88,7 @@ public IEnumerator MouseEvents_CanReceiveOnMouseDrag([ValueSource(nameof(_testDe
9988
[Category("MouseEvents")]
10089
public IEnumerator MouseEvents_CanReceiveOnMouseEnterAndMouseExit([ValueSource(nameof(_testDevicesNoTouch))] Type pointerType)
10190
{
102-
var pointer = (Pointer)InputSystem.s_Manager.AddDevice(pointerType);
103-
InputSystem.AddDevice(pointer);
104-
105-
var gameObject = SetUpScene();
91+
var gameObject = SetUpScene(pointerType, out var pointer);
10692
gameObject.AddComponent<OnMouseEventsTest>();
10793
var vec = Camera.main.WorldToScreenPoint(gameObject.transform.position);
10894
Set(pointer, new Vector2(0, 0), false, false);
@@ -120,10 +106,7 @@ public IEnumerator MouseEvents_CanReceiveOnMouseEnterAndMouseExit([ValueSource(n
120106
[Category("MouseEvents")]
121107
public IEnumerator MouseEvents_CanReceiveOnMouseOver([ValueSource(nameof(_testDevicesNoTouch))] Type pointerType)
122108
{
123-
var pointer = (Pointer)InputSystem.s_Manager.AddDevice(pointerType);
124-
InputSystem.AddDevice(pointer);
125-
126-
var gameObject = SetUpScene();
109+
var gameObject = SetUpScene(pointerType, out var pointer);
127110
gameObject.AddComponent<OnMousEventTestTwo>();
128111
var vec = Camera.main.WorldToScreenPoint(gameObject.transform.position);
129112
Set(pointer, new Vector2(vec.x, vec.y), false, false);

0 commit comments

Comments
 (0)