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 . Pad
32+ {
33+ [ TestFixture ]
34+ [ Category ( "InputStateManager.Pad.DPad.PressRelease" ) ]
35+ public partial class PadTests
36+ {
37+ [ Test ]
38+ public void DPadPressTriggers ( )
39+ {
40+ providerMock . SetupSequence ( o => o . GetState ( 0 ) )
41+ . Returns ( GetDpadS ( ButtonState . Pressed ) ) ;
42+ input . Update ( ) ;
43+ Assert . IsTrue ( input . Pad ( ) . Is . DPad . Press ( InputStateManager . Inputs . Pad . DPadDirection . UP ) ) ;
44+ }
45+
46+ [ Test ]
47+ public void DPadPressIsResetWhenKeyIsReleased ( )
48+ {
49+ providerMock . SetupSequence ( o => o . GetState ( 0 ) )
50+ . Returns ( GetDpadS ( ButtonState . Pressed ) )
51+ . Returns ( IdleState ) ;
52+ input . Update ( ) ;
53+ Assert . IsTrue ( input . Pad ( ) . Is . DPad . Press ( InputStateManager . Inputs . Pad . DPadDirection . UP ) ) ;
54+ input . Update ( ) ;
55+ Assert . IsFalse ( input . Pad ( ) . Is . DPad . Press ( InputStateManager . Inputs . Pad . DPadDirection . UP ) ) ;
56+ }
57+
58+ [ Test ]
59+ public void DPadPressIsResetWhenKeyIsStillDown ( )
60+ {
61+ providerMock . SetupSequence ( o => o . GetState ( 0 ) )
62+ . Returns ( GetDpadS ( ButtonState . Pressed ) )
63+ . Returns ( GetDpadS ( ButtonState . Pressed ) ) ;
64+ input . Update ( ) ;
65+ Assert . IsTrue ( input . Pad ( ) . Is . DPad . Press ( InputStateManager . Inputs . Pad . DPadDirection . UP ) ) ;
66+ input . Update ( ) ;
67+ Assert . IsFalse ( input . Pad ( ) . Is . DPad . Press ( InputStateManager . Inputs . Pad . DPadDirection . UP ) ) ;
68+ }
69+
70+ [ Test ]
71+ public void DPadReleaseTriggers ( )
72+ {
73+ providerMock . SetupSequence ( o => o . GetState ( 0 ) )
74+ . Returns ( GetDpadS ( ButtonState . Pressed ) )
75+ . Returns ( GetDpadS ( ButtonState . Pressed ) )
76+ . Returns ( IdleState ) ;
77+ input . Update ( ) ;
78+ Assert . IsFalse ( input . Pad ( ) . Is . DPad . Release ( InputStateManager . Inputs . Pad . DPadDirection . UP ) ) ;
79+ input . Update ( ) ;
80+ Assert . IsFalse ( input . Pad ( ) . Is . DPad . Release ( InputStateManager . Inputs . Pad . DPadDirection . UP ) ) ;
81+ input . Update ( ) ;
82+ Assert . IsTrue ( input . Pad ( ) . Is . DPad . Release ( InputStateManager . Inputs . Pad . DPadDirection . UP ) ) ;
83+ }
84+
85+ [ Test ]
86+ public void DPadReleaseIsResetProperly ( )
87+ {
88+ providerMock . SetupSequence ( o => o . GetState ( 0 ) )
89+ . Returns ( GetDpadS ( ButtonState . Pressed ) )
90+ . Returns ( IdleState )
91+ . Returns ( IdleState ) ;
92+ input . Update ( ) ;
93+ Assert . IsFalse ( input . Pad ( ) . Is . DPad . Release ( InputStateManager . Inputs . Pad . DPadDirection . UP ) ) ;
94+ input . Update ( ) ;
95+ Assert . IsTrue ( input . Pad ( ) . Is . DPad . Release ( InputStateManager . Inputs . Pad . DPadDirection . UP ) ) ;
96+ input . Update ( ) ;
97+ Assert . IsFalse ( input . Pad ( ) . Is . DPad . Press ( InputStateManager . Inputs . Pad . DPadDirection . UP ) ) ;
98+ }
99+
100+ [ Test ]
101+ public void DPadPressAndReleaseWorksWithSeveralKeys ( )
102+ {
103+ providerMock . SetupSequence ( o => o . GetState ( 0 ) )
104+ . Returns ( GetDpadM ( ButtonState . Pressed , ButtonState . Pressed ) )
105+ . Returns ( GetDpadS ( ButtonState . Pressed ) ) ;
106+ input . Update ( ) ;
107+ Assert . IsTrue ( input . Pad ( ) . Is . DPad . Press ( InputStateManager . Inputs . Pad . DPadDirection . UP ,
108+ InputStateManager . Inputs . Pad . DPadDirection . DOWN ) ) ;
109+ Assert . IsFalse ( input . Pad ( ) . Is . DPad . Release ( InputStateManager . Inputs . Pad . DPadDirection . UP ,
110+ InputStateManager . Inputs . Pad . DPadDirection . DOWN ) ) ;
111+ input . Update ( ) ;
112+ Assert . IsFalse ( input . Pad ( ) . Is . DPad . Press ( InputStateManager . Inputs . Pad . DPadDirection . UP ,
113+ InputStateManager . Inputs . Pad . DPadDirection . DOWN ) ) ;
114+ Assert . IsFalse ( input . Pad ( ) . Is . DPad . Release ( InputStateManager . Inputs . Pad . DPadDirection . UP ,
115+ InputStateManager . Inputs . Pad . DPadDirection . DOWN ) ) ;
116+ input . Update ( ) ;
117+ Assert . IsFalse ( input . Pad ( ) . Is . DPad . Press ( InputStateManager . Inputs . Pad . DPadDirection . UP ,
118+ InputStateManager . Inputs . Pad . DPadDirection . DOWN ) ) ;
119+ // A and B were not released at once.
120+ Assert . IsFalse ( input . Pad ( ) . Is . DPad . Release ( InputStateManager . Inputs . Pad . DPadDirection . UP ,
121+ InputStateManager . Inputs . Pad . DPadDirection . DOWN ) ) ;
122+ }
123+
124+ [ Test ]
125+ public void DPadOnePressAndOneReleaseWorksWithSeveralKeys ( )
126+ {
127+ providerMock . SetupSequence ( o => o . GetState ( 0 ) )
128+ . Returns ( GetDpadS ( ButtonState . Pressed ) )
129+ . Returns ( GetDpadM ( ButtonState . Pressed , ButtonState . Pressed ) )
130+ . Returns ( GetDpadS ( ButtonState . Pressed ) ) ;
131+ input . Update ( ) ;
132+ Assert . IsTrue ( input . Pad ( ) . Is . DPad . OnePress ( InputStateManager . Inputs . Pad . DPadDirection . UP ,
133+ InputStateManager . Inputs . Pad . DPadDirection . DOWN ) ) ;
134+ Assert . IsFalse ( input . Pad ( ) . Is . DPad . OneRelease ( InputStateManager . Inputs . Pad . DPadDirection . UP ,
135+ InputStateManager . Inputs . Pad . DPadDirection . DOWN ) ) ;
136+ input . Update ( ) ;
137+ Assert . IsTrue ( input . Pad ( ) . Is . DPad . OnePress ( InputStateManager . Inputs . Pad . DPadDirection . UP ,
138+ InputStateManager . Inputs . Pad . DPadDirection . DOWN ) ) ;
139+ Assert . IsFalse ( input . Pad ( ) . Is . DPad . OneRelease ( InputStateManager . Inputs . Pad . DPadDirection . UP ,
140+ InputStateManager . Inputs . Pad . DPadDirection . DOWN ) ) ;
141+ input . Update ( ) ;
142+ Assert . IsFalse ( input . Pad ( ) . Is . DPad . OnePress ( InputStateManager . Inputs . Pad . DPadDirection . UP ,
143+ InputStateManager . Inputs . Pad . DPadDirection . DOWN ) ) ;
144+ Assert . IsTrue ( input . Pad ( ) . Is . DPad . OneRelease ( InputStateManager . Inputs . Pad . DPadDirection . UP ,
145+ InputStateManager . Inputs . Pad . DPadDirection . DOWN ) ) ;
146+ input . Update ( ) ;
147+ Assert . IsFalse ( input . Pad ( ) . Is . DPad . OnePress ( InputStateManager . Inputs . Pad . DPadDirection . UP ,
148+ InputStateManager . Inputs . Pad . DPadDirection . DOWN ) ) ;
149+ Assert . IsTrue ( input . Pad ( ) . Is . DPad . OneRelease ( InputStateManager . Inputs . Pad . DPadDirection . UP ,
150+ InputStateManager . Inputs . Pad . DPadDirection . DOWN ) ) ;
151+ }
152+ }
153+ }
0 commit comments