Skip to content

Commit b5d35a9

Browse files
committed
Restructures unit-tests (folders, partial classes)
1 parent 59199d2 commit b5d35a9

16 files changed

+1436
-1104
lines changed

NUnitTests/NUnitTests.csproj

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,18 @@
6060
<Reference Include="System.Xml" />
6161
</ItemGroup>
6262
<ItemGroup>
63-
<Compile Include="Tests\TouchTests.cs" />
64-
<Compile Include="Tests\MouseTests.cs" />
65-
<Compile Include="Tests\PadTests.cs" />
66-
<Compile Include="Tests\KeyTests.cs" />
63+
<Compile Include="Tests\Key\KeyTests.Others.cs" />
64+
<Compile Include="Tests\Key\KeyTests.Was.cs" />
65+
<Compile Include="Tests\Key\KeyTests.PressRelease.cs" />
66+
<Compile Include="Tests\Mouse\MouseTests.Was.cs" />
67+
<Compile Include="Tests\Mouse\MouseTests.PressRelease.cs" />
68+
<Compile Include="Tests\Pad\PadTests.Others.cs" />
69+
<Compile Include="Tests\Pad\PadTests.Was.cs" />
70+
<Compile Include="Tests\Pad\PadTests.PressRelease.cs" />
71+
<Compile Include="Tests\Touch\TouchTests.cs" />
72+
<Compile Include="Tests\Mouse\MouseTests.UpDown.cs" />
73+
<Compile Include="Tests\Pad\PadTests.UpDown.cs" />
74+
<Compile Include="Tests\Key\KeyTests.UpDown.cs" />
6775
<Compile Include="Properties\AssemblyInfo.cs" />
6876
</ItemGroup>
6977
<ItemGroup>
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
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 Microsoft.Xna.Framework.Input;
29+
using NUnit.Framework;
30+
31+
namespace NUnitTests.Tests.Key
32+
{
33+
[TestFixture]
34+
[Category("InputStateManager.Key.Others")]
35+
public partial class KeyTests
36+
{
37+
[Test]
38+
public void AltPressIsTriggeredAndReleasedWithLeftAndRightAlt()
39+
{
40+
providerMock.SetupSequence(o => o.GetState())
41+
.Returns(new KeyboardState(Keys.LeftAlt))
42+
.Returns(new KeyboardState(Keys.RightAlt))
43+
.Returns(new KeyboardState(Keys.LeftAlt, Keys.RightAlt))
44+
.Returns(new KeyboardState());
45+
input.Update();
46+
Assert.IsTrue(input.Key.Is.AltPress);
47+
Assert.IsTrue(input.Key.Is.AltDown);
48+
input.Update();
49+
Assert.IsTrue(input.Key.Is.AltPress);
50+
input.Update();
51+
Assert.IsTrue(input.Key.Is.AltPress);
52+
input.Update();
53+
Assert.IsFalse(input.Key.Is.AltPress);
54+
Assert.IsTrue(input.Key.Is.AltRelease);
55+
Assert.IsTrue(input.Key.Is.AltUp);
56+
}
57+
58+
[Test]
59+
public void CtrlPressIsTriggeredAndReleasedWithLeftAndRightCtrl()
60+
{
61+
providerMock.SetupSequence(o => o.GetState())
62+
.Returns(new KeyboardState(Keys.LeftControl))
63+
.Returns(new KeyboardState(Keys.RightControl))
64+
.Returns(new KeyboardState(Keys.LeftControl, Keys.RightControl))
65+
.Returns(new KeyboardState());
66+
input.Update();
67+
Assert.IsTrue(input.Key.Is.CtrlPress);
68+
Assert.IsTrue(input.Key.Is.CtrlDown);
69+
input.Update();
70+
Assert.IsTrue(input.Key.Is.CtrlPress);
71+
input.Update();
72+
Assert.IsTrue(input.Key.Is.CtrlPress);
73+
input.Update();
74+
Assert.IsFalse(input.Key.Is.CtrlPress);
75+
Assert.IsTrue(input.Key.Is.CtrlRelease);
76+
Assert.IsTrue(input.Key.Is.CtrlUp);
77+
}
78+
79+
[Test]
80+
public void ShiftPressIsTriggeredAndReleasedWithLeftAndRightShift()
81+
{
82+
providerMock.SetupSequence(o => o.GetState())
83+
.Returns(new KeyboardState(Keys.LeftShift))
84+
.Returns(new KeyboardState(Keys.RightShift))
85+
.Returns(new KeyboardState(Keys.LeftShift, Keys.RightShift))
86+
.Returns(new KeyboardState());
87+
input.Update();
88+
Assert.IsTrue(input.Key.Is.ShiftPress);
89+
Assert.IsTrue(input.Key.Is.ShiftDown);
90+
input.Update();
91+
Assert.IsTrue(input.Key.Is.ShiftPress);
92+
input.Update();
93+
Assert.IsTrue(input.Key.Is.ShiftPress);
94+
input.Update();
95+
Assert.IsFalse(input.Key.Is.ShiftPress);
96+
Assert.IsTrue(input.Key.Is.ShiftRelease);
97+
Assert.IsTrue(input.Key.Is.ShiftUp);
98+
}
99+
100+
[Test]
101+
public void WindowsPressIsTriggeredAndReleasedWithLeftAndRightWindows()
102+
{
103+
providerMock.SetupSequence(o => o.GetState())
104+
.Returns(new KeyboardState(Keys.LeftWindows))
105+
.Returns(new KeyboardState(Keys.RightWindows))
106+
.Returns(new KeyboardState(Keys.LeftWindows, Keys.RightWindows))
107+
.Returns(new KeyboardState());
108+
input.Update();
109+
Assert.IsTrue(input.Key.Is.WindowsPress);
110+
Assert.IsTrue(input.Key.Is.WindowsDown);
111+
input.Update();
112+
Assert.IsTrue(input.Key.Is.WindowsPress);
113+
input.Update();
114+
Assert.IsTrue(input.Key.Is.WindowsPress);
115+
input.Update();
116+
Assert.IsFalse(input.Key.Is.WindowsPress);
117+
Assert.IsTrue(input.Key.Is.WindowsRelease);
118+
Assert.IsTrue(input.Key.Is.WindowsUp);
119+
}
120+
121+
[Test]
122+
public void CapslockPressIsTriggeredAndReleased()
123+
{
124+
providerMock.SetupSequence(o => o.GetState())
125+
.Returns(new KeyboardState(new Keys[] { }, true))
126+
.Returns(new KeyboardState(new Keys[] { }, true))
127+
.Returns(new KeyboardState());
128+
input.Update();
129+
Assert.IsTrue(input.Key.Is.CapsLockStateEnter);
130+
Assert.IsTrue(input.Key.Is.CapsLockStateOn);
131+
input.Update();
132+
Assert.IsFalse(input.Key.Is.CapsLockStateEnter);
133+
Assert.IsTrue(input.Key.Is.CapsLockStateOn);
134+
input.Update();
135+
Assert.IsFalse(input.Key.Is.CapsLockStateEnter);
136+
Assert.IsTrue(input.Key.Is.CapsLockStateExit);
137+
Assert.IsTrue(input.Key.Is.CapsLockStateOff);
138+
}
139+
140+
[Test]
141+
public void NumlockPressIsTriggeredAndReleased()
142+
{
143+
providerMock.SetupSequence(o => o.GetState())
144+
.Returns(new KeyboardState(new Keys[] { }, false, true))
145+
.Returns(new KeyboardState(new Keys[] { }, false, true))
146+
.Returns(new KeyboardState());
147+
input.Update();
148+
Assert.IsTrue(input.Key.Is.NumLockStateEnter);
149+
Assert.IsTrue(input.Key.Is.NumLockStateOn);
150+
input.Update();
151+
Assert.IsFalse(input.Key.Is.NumLockStateEnter);
152+
Assert.IsTrue(input.Key.Is.NumLockStateOn);
153+
input.Update();
154+
Assert.IsFalse(input.Key.Is.NumLockStateEnter);
155+
Assert.IsTrue(input.Key.Is.NumLockStateExit);
156+
Assert.IsTrue(input.Key.Is.NumLockStateOff);
157+
}
158+
}
159+
}
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
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 Microsoft.Xna.Framework.Input;
29+
using NUnit.Framework;
30+
31+
namespace NUnitTests.Tests.Key
32+
{
33+
[TestFixture]
34+
[Category("InputStateManager.Key.PressRelease")]
35+
public partial class KeyTests
36+
{
37+
[Test]
38+
public void KeyPressTriggers()
39+
{
40+
providerMock.SetupSequence(o => o.GetState())
41+
.Returns(new KeyboardState(Keys.A));
42+
input.Update();
43+
Assert.IsTrue(input.Key.Is.Press(Keys.A));
44+
}
45+
46+
[Test]
47+
public void KeyPressIsResetWhenKeyIsReleased()
48+
{
49+
providerMock.SetupSequence(o => o.GetState())
50+
.Returns(new KeyboardState(Keys.A))
51+
.Returns(new KeyboardState());
52+
input.Update();
53+
Assert.IsTrue(input.Key.Is.Press(Keys.A));
54+
input.Update();
55+
Assert.IsFalse(input.Key.Is.Press(Keys.A));
56+
}
57+
58+
[Test]
59+
public void KeyPressIsResetWhenKeyIsStillDown()
60+
{
61+
providerMock.SetupSequence(o => o.GetState())
62+
.Returns(new KeyboardState(Keys.A))
63+
.Returns(new KeyboardState(Keys.A));
64+
input.Update();
65+
Assert.IsTrue(input.Key.Is.Press(Keys.A));
66+
input.Update();
67+
Assert.IsFalse(input.Key.Is.Press(Keys.A));
68+
}
69+
70+
[Test]
71+
public void KeyReleaseTriggers()
72+
{
73+
providerMock.SetupSequence(o => o.GetState())
74+
.Returns(new KeyboardState(Keys.A))
75+
.Returns(new KeyboardState(Keys.A))
76+
.Returns(new KeyboardState());
77+
input.Update();
78+
Assert.IsFalse(input.Key.Is.Release(Keys.A));
79+
input.Update();
80+
Assert.IsFalse(input.Key.Is.Release(Keys.A));
81+
input.Update();
82+
Assert.IsTrue(input.Key.Is.Release(Keys.A));
83+
}
84+
85+
[Test]
86+
public void KeyReleaseIsResetProperly()
87+
{
88+
providerMock.SetupSequence(o => o.GetState())
89+
.Returns(new KeyboardState(Keys.A))
90+
.Returns(new KeyboardState())
91+
.Returns(new KeyboardState());
92+
input.Update();
93+
Assert.IsFalse(input.Key.Is.Release(Keys.A));
94+
input.Update();
95+
Assert.IsTrue(input.Key.Is.Release(Keys.A));
96+
input.Update();
97+
Assert.IsFalse(input.Key.Is.Press(Keys.A));
98+
}
99+
100+
[Test]
101+
public void PressAndReleaseWorksWithSeveralKeys()
102+
{
103+
providerMock.SetupSequence(o => o.GetState())
104+
.Returns(new KeyboardState(Keys.A, Keys.B))
105+
.Returns(new KeyboardState(Keys.A));
106+
input.Update();
107+
Assert.IsTrue(input.Key.Is.Press(Keys.A, Keys.B));
108+
Assert.IsFalse(input.Key.Is.Release(Keys.A, Keys.B));
109+
input.Update();
110+
Assert.IsFalse(input.Key.Is.Press(Keys.A, Keys.B));
111+
Assert.IsFalse(input.Key.Is.Release(Keys.A, Keys.B));
112+
input.Update();
113+
Assert.IsFalse(input.Key.Is.Press(Keys.A, Keys.B));
114+
// A and B were not released at once.
115+
Assert.IsFalse(input.Key.Is.Release(Keys.A, Keys.B));
116+
}
117+
118+
[Test]
119+
public void OnePressAndOneReleaseWorksWithSeveralKeys()
120+
{
121+
providerMock.SetupSequence(o => o.GetState())
122+
.Returns(new KeyboardState(Keys.A))
123+
.Returns(new KeyboardState(Keys.A, Keys.B))
124+
.Returns(new KeyboardState(Keys.A));
125+
input.Update();
126+
Assert.IsTrue(input.Key.Is.OnePress(Keys.A, Keys.B));
127+
Assert.IsFalse(input.Key.Is.OneRelease(Keys.A, Keys.B));
128+
input.Update();
129+
Assert.IsTrue(input.Key.Is.OnePress(Keys.A, Keys.B));
130+
Assert.IsFalse(input.Key.Is.OneRelease(Keys.A, Keys.B));
131+
input.Update();
132+
Assert.IsFalse(input.Key.Is.OnePress(Keys.A, Keys.B));
133+
Assert.IsTrue(input.Key.Is.OneRelease(Keys.A, Keys.B));
134+
input.Update();
135+
Assert.IsFalse(input.Key.Is.OnePress(Keys.A, Keys.B));
136+
Assert.IsTrue(input.Key.Is.OneRelease(Keys.A, Keys.B));
137+
}
138+
}
139+
}

0 commit comments

Comments
 (0)