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+ }
0 commit comments