Skip to content

Commit 0c24be7

Browse files
committed
Adds pad-test structure and test for connected property
1 parent 9d091d5 commit 0c24be7

File tree

3 files changed

+111
-1
lines changed

3 files changed

+111
-1
lines changed

NUnitTests/KeyTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
namespace NUnitTests
3535
{
3636
[TestFixture]
37-
[Category("InputStateManager")]
37+
[Category("InputStateManager.Key")]
3838
public class KeyTests
3939
{
4040
private InputManager input;

NUnitTests/NUnitTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
<Reference Include="System.Xml" />
6161
</ItemGroup>
6262
<ItemGroup>
63+
<Compile Include="PadTests.cs" />
6364
<Compile Include="KeyTests.cs" />
6465
<Compile Include="Properties\AssemblyInfo.cs" />
6566
</ItemGroup>

NUnitTests/PadTests.cs

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
// ***************************************************************************
2+
// This is free and unencumbered software released into the public domain.
3+
//
4+
// Anyone is free to copy, modify, publish, use, compile, sell, or
5+
// distribute this software, either in source code form or as a compiled
6+
// binary, for any purpose, commercial or non-commercial, and by any
7+
// means.
8+
//
9+
// In jurisdictions that recognize copyright laws, the author or authors
10+
// of this software dedicate any and all copyright interest in the
11+
// software to the public domain. We make this dedication for the benefit
12+
// of the public at large and to the detriment of our heirs and
13+
// successors. We intend this dedication to be an overt act of
14+
// relinquishment in perpetuity of all present and future rights to this
15+
// software under copyright law.
16+
//
17+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18+
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20+
// IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21+
// OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22+
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23+
// OTHER DEALINGS IN THE SOFTWARE.
24+
//
25+
// For more information, please refer to <http://unlicense.org>
26+
// ***************************************************************************
27+
28+
using InputStateManager;
29+
using InputStateManager.Inputs.InputProviders.Interfaces;
30+
using Microsoft.Xna.Framework;
31+
using Microsoft.Xna.Framework.Input;
32+
using Moq;
33+
using NUnit.Framework;
34+
35+
namespace NUnitTests
36+
{
37+
[TestFixture]
38+
[Category("InputStateManager.Pad")]
39+
public class PadTests
40+
{
41+
private InputManager input;
42+
private Mock<IPadInputProvider> providerMock;
43+
44+
[SetUp]
45+
public void Setup()
46+
{
47+
providerMock = new Mock<IPadInputProvider>();
48+
input = new InputManager(null, null, providerMock.Object, null);
49+
}
50+
51+
private static GamePadState IdleState => new GamePadState(new GamePadThumbSticks(Vector2.Zero, Vector2.Zero),
52+
new GamePadTriggers(0f, 0f), new GamePadButtons(0),
53+
new GamePadDPad(ButtonState.Released, ButtonState.Released, ButtonState.Released, ButtonState.Released));
54+
55+
[Test]
56+
public void OnlyOneGamepadIsConnected()
57+
{
58+
providerMock.SetupSequence(o => o.GetState(0))
59+
.Returns(IdleState)
60+
.Returns(GamePadState.Default)
61+
.Returns(GamePadState.Default)
62+
.Returns(GamePadState.Default)
63+
.Returns(IdleState);
64+
providerMock.SetupSequence(o => o.GetState(1))
65+
.Returns(GamePadState.Default)
66+
.Returns(IdleState)
67+
.Returns(GamePadState.Default)
68+
.Returns(GamePadState.Default)
69+
.Returns(IdleState);
70+
providerMock.SetupSequence(o => o.GetState(2))
71+
.Returns(GamePadState.Default)
72+
.Returns(GamePadState.Default)
73+
.Returns(IdleState)
74+
.Returns(GamePadState.Default)
75+
.Returns(IdleState);
76+
providerMock.SetupSequence(o => o.GetState(3))
77+
.Returns(GamePadState.Default)
78+
.Returns(GamePadState.Default)
79+
.Returns(GamePadState.Default)
80+
.Returns(IdleState)
81+
.Returns(IdleState);
82+
input.Update();
83+
Assert.IsTrue(input.Pad.Is.Connected());
84+
Assert.IsFalse(input.Pad.Is.Connected(PlayerIndex.Two));
85+
Assert.IsFalse(input.Pad.Is.Connected(PlayerIndex.Three));
86+
Assert.IsFalse(input.Pad.Is.Connected(PlayerIndex.Four));
87+
input.Update();
88+
Assert.IsFalse(input.Pad.Is.Connected());
89+
Assert.IsTrue(input.Pad.Is.Connected(PlayerIndex.Two));
90+
Assert.IsFalse(input.Pad.Is.Connected(PlayerIndex.Three));
91+
Assert.IsFalse(input.Pad.Is.Connected(PlayerIndex.Four));
92+
input.Update();
93+
Assert.IsFalse(input.Pad.Is.Connected());
94+
Assert.IsFalse(input.Pad.Is.Connected(PlayerIndex.Two));
95+
Assert.IsTrue(input.Pad.Is.Connected(PlayerIndex.Three));
96+
Assert.IsFalse(input.Pad.Is.Connected(PlayerIndex.Four));
97+
input.Update();
98+
Assert.IsFalse(input.Pad.Is.Connected());
99+
Assert.IsFalse(input.Pad.Is.Connected(PlayerIndex.Two));
100+
Assert.IsFalse(input.Pad.Is.Connected(PlayerIndex.Three));
101+
Assert.IsTrue(input.Pad.Is.Connected(PlayerIndex.Four));
102+
input.Update();
103+
Assert.IsTrue(input.Pad.Is.Connected());
104+
Assert.IsTrue(input.Pad.Is.Connected(PlayerIndex.Two));
105+
Assert.IsTrue(input.Pad.Is.Connected(PlayerIndex.Three));
106+
Assert.IsTrue(input.Pad.Is.Connected(PlayerIndex.Four));
107+
}
108+
}
109+
}

0 commit comments

Comments
 (0)