コード例 #1
0
        public void handle_pov_button_release()
        {
            var isEventCalled = false;
            var joystick      = new TestJoystick_BasicQueue(dataBufferSize: 2);
            var map           = CreateTestHotasTestMapWithPOV();

            var activationList = new Dictionary <int, ModeActivationItem>();
            var modeProfiles   = new Dictionary <int, ObservableCollection <IHotasBaseMap> >();

            modeProfiles.Add(1, map);

            var queue = new HOTASQueue(Substitute.For <IKeyboard>());

            queue.Listen(joystick, modeProfiles, activationList);

            var mre = new ManualResetEventSlim();

            queue.ButtonReleased += (sender, e) => { isEventCalled = true; mre.Set(); };
            Assert.False(isEventCalled);
            joystick.TestData[0] = new JoystickUpdate()
            {
                RawOffset = (int)JoystickOffset.POV1, Sequence = 0, Timestamp = 0, Value = (int)JoystickOffsetValues.PointOfViewPositionValues.POVNorthEast
            };
            joystick.TestData[1] = new JoystickUpdate()
            {
                RawOffset = (int)JoystickOffset.POV1, Sequence = 0, Timestamp = 0, Value = (int)JoystickOffsetValues.PointOfViewPositionValues.Released
            };
            mre.Wait(5000);
            Assert.True(isEventCalled);
        }
コード例 #2
0
        public void mode_profile_selected()
        {
            var isEventCalled = false;
            var joystick      = new TestJoystick_BasicQueue(dataBufferSize: 1);
            var map           = CreateTestHotasTestMapWithShiftMode();

            var activationList = new Dictionary <int, ModeActivationItem>();
            var modeProfiles   = new Dictionary <int, ObservableCollection <IHotasBaseMap> >();

            modeProfiles.Add(1, map);

            var queue = new HOTASQueue(Substitute.For <IKeyboard>());

            queue.Listen(joystick, modeProfiles, activationList);

            var mre = new ManualResetEventSlim();

            queue.ModeProfileSelected += (sender, e) => { isEventCalled = true; mre.Set(); };
            Assert.False(isEventCalled);
            joystick.TestData[0] = new JoystickUpdate()
            {
                RawOffset = (int)JoystickOffset.Button1, Sequence = 0, Timestamp = 0, Value = (int)JoystickOffsetValues.ButtonState.ButtonPressed
            };
            mre.Wait(5000);
            Assert.True(isEventCalled);
        }
コード例 #3
0
        public void axis_changed_causes_keypress_up()
        {
            var isEventCalled = false;
            var joystick      = new TestJoystick_BasicQueue(dataBufferSize: 2);
            var map           = CreateTestHotasTestMapWithAxis();

            var activationList = new Dictionary <int, ModeActivationItem>();
            var modeProfiles   = new Dictionary <int, ObservableCollection <IHotasBaseMap> >();

            modeProfiles.Add(1, map);

            var queue = new HOTASQueue(Substitute.For <IKeyboard>());

            queue.Listen(joystick, modeProfiles, activationList);

            var mre = new ManualResetEventSlim();

            queue.KeystrokeUpSent += (sender, e) => { isEventCalled = true; mre.Set(); };
            Assert.False(isEventCalled);
            joystick.TestData[0] = new JoystickUpdate()
            {
                RawOffset = (int)JoystickOffset.X, Sequence = 0, Timestamp = 0, Value = 4000
            };
            joystick.TestData[1] = new JoystickUpdate()
            {
                RawOffset = (int)JoystickOffset.X, Sequence = 0, Timestamp = 0, Value = 6000
            };
            mre.Wait(5000);
            Assert.True(isEventCalled);
        }
コード例 #4
0
        public void macro_start()
        {
            var isMacroStartedEventCalled = false;
            var isKeyDownEventCalled      = false;
            var isKeyUpEventCalled        = false;
            var joystick = new TestJoystick_BasicQueue(dataBufferSize: 1);
            var map      = CreateTestHotasTestMapWithButton(timeInMilliseconds: 1);

            var subKeyboard = Substitute.For <IKeyboard>();

            subKeyboard.KeyDownRepeatDelay.Returns(35);

            var activationList = new Dictionary <int, ModeActivationItem>();
            var modeProfiles   = new Dictionary <int, ObservableCollection <IHotasBaseMap> >();

            modeProfiles.Add(1, map);

            var queue = new HOTASQueue(subKeyboard);

            queue.Listen(joystick, modeProfiles, activationList);

            var mreMacro   = new ManualResetEventSlim();
            var mreKeyDown = new ManualResetEventSlim();
            var mreKeyUp   = new ManualResetEventSlim();

            queue.MacroStarted      += (sender, e) => { isMacroStartedEventCalled = true; mreMacro.Set(); };
            queue.KeystrokeDownSent += (sender, e) => { isKeyDownEventCalled = true; mreKeyDown.Set(); };
            queue.KeystrokeUpSent   += (sender, e) => { isKeyUpEventCalled = true; mreKeyUp.Set(); };

            Assert.False(isMacroStartedEventCalled);
            joystick.TestData[0] = new JoystickUpdate()
            {
                RawOffset = (int)JoystickOffset.Button1, Sequence = 0, Timestamp = 0, Value = (int)JoystickOffsetValues.ButtonState.ButtonPressed
            };

            mreMacro.Wait(5000);
            mreKeyDown.Wait(5000);
            mreKeyUp.Wait(5000);

            Assert.True(isMacroStartedEventCalled);
            Assert.True(isKeyDownEventCalled);
            Assert.True(isKeyUpEventCalled);

            subKeyboard.Received().SendKeyPress(Arg.Any <int>(), Arg.Any <bool>(), Arg.Any <bool>());
        }
コード例 #5
0
        public void stop_loop()
        {
            var isEventCalled = false;
            var joystick      = new TestJoystick_BasicQueue(dataBufferSize: 1);
            var map           = CreateTestHotasTestMapWithButton();

            var activationList = new Dictionary <int, ModeActivationItem>();
            var modeProfiles   = new Dictionary <int, ObservableCollection <IHotasBaseMap> >();

            modeProfiles.Add(1, map);

            var queue = new HOTASQueue(Substitute.For <IKeyboard>());

            queue.Listen(joystick, modeProfiles, activationList);

            var mre = new ManualResetEventSlim();

            queue.KeystrokeDownSent += (sender, e) => { isEventCalled = true; mre.Set(); };

            //setup baseline test to prove it's actually running
            Assert.False(isEventCalled);
            joystick.TestData[0] = new JoystickUpdate()
            {
                RawOffset = (int)JoystickOffset.Button1, Sequence = 0, Timestamp = 0, Value = (int)JoystickOffsetValues.ButtonState.ButtonPressed
            };
            mre.Wait(5000);
            Assert.True(isEventCalled);

            //test that we stop the loop and no events come through
            isEventCalled = false;
            mre.Reset();
            queue.Stop();

            joystick.TestData    = new JoystickUpdate[1];
            joystick.TestData[0] = new JoystickUpdate()
            {
                RawOffset = (int)JoystickOffset.Button1, Sequence = 0, Timestamp = 0, Value = (int)JoystickOffsetValues.ButtonState.ButtonPressed
            };
            mre.Wait(5000);
            Assert.False(isEventCalled);
        }
コード例 #6
0
        public void force_button_press()
        {
            var isEventCalled = false;
            var joystick      = new TestJoystick_BasicQueue(dataBufferSize: 1);
            var map           = CreateTestHotasTestMapWithButton();

            var activationList = new Dictionary <int, ModeActivationItem>();
            var modeProfiles   = new Dictionary <int, ObservableCollection <IHotasBaseMap> >();

            modeProfiles.Add(1, map);

            var queue = new HOTASQueue(Substitute.For <IKeyboard>());

            queue.Listen(joystick, modeProfiles, activationList);

            Assert.False(isEventCalled);

            queue.ButtonPressed += (sender, e) => { isEventCalled = true; };
            queue.ForceButtonPress(JoystickOffset.Button1, true);

            Assert.True(isEventCalled);
        }
コード例 #7
0
        public void lost_connection_to_device()
        {
            var isEventCalled = false;
            var joystick      = new TestJoystick_BasicQueue(dataBufferSize: 1);
            var map           = CreateTestHotasTestMapWithButton();

            var activationList = new Dictionary <int, ModeActivationItem>();
            var modeProfiles   = new Dictionary <int, ObservableCollection <IHotasBaseMap> >();

            modeProfiles.Add(1, map);

            var queue = new HOTASQueue(Substitute.For <IKeyboard>());

            queue.Listen(joystick, modeProfiles, activationList);

            var mre = new ManualResetEventSlim();

            queue.LostConnectionToDevice += (sender, e) => { isEventCalled = true; mre.Set(); };
            Assert.False(isEventCalled);
            joystick.TestData = null;
            mre.Wait(5000);
            Assert.True(isEventCalled);
        }
コード例 #8
0
        public void test_one_shot()
        {
            var isFirstKeyDownPressed = false;
            var isFirstKeyUpPressed   = false;

            var isSecondKeyOutOfOrder = false;


            var joystick = new TestJoystick_BasicQueue(dataBufferSize: 1);
            var map      = CreateTestHotasTestMapWithButton(timeInMilliseconds: 1);

            ((HOTASButton)map[0]).IsOneShot = true;

            var subKeyboard = Substitute.For <IKeyboard>();

            subKeyboard.KeyDownRepeatDelay.Returns(35);

            var activationList = new Dictionary <int, ModeActivationItem>();
            var modeProfiles   = new Dictionary <int, ObservableCollection <IHotasBaseMap> >();

            modeProfiles.Add(1, map);

            var queue = new HOTASQueue(subKeyboard);

            queue.Listen(joystick, modeProfiles, activationList);

            var mreKeyDown = new ManualResetEventSlim();
            var mreKeyUp   = new ManualResetEventSlim();

            queue.KeystrokeDownSent += (sender, e) =>
            {
                if (e.ScanCode == 28 && isFirstKeyDownPressed == false)
                {
                    isFirstKeyDownPressed = true;
                }

                if (e.ScanCode == 29 && isFirstKeyDownPressed == false)
                {
                    isSecondKeyOutOfOrder = true;
                    mreKeyDown.Set();
                }
            };

            queue.KeystrokeUpSent += (sender, e) =>
            {
                if (e.ScanCode == 28 && e.IsKeyUp && isFirstKeyDownPressed)
                {
                    isFirstKeyUpPressed = true;
                }

                if (e.ScanCode == 29 && isFirstKeyUpPressed == false)
                {
                    isSecondKeyOutOfOrder = true;
                    mreKeyUp.Set();
                }
            };

            joystick.TestData[0] = new JoystickUpdate()
            {
                RawOffset = (int)JoystickOffset.Button1, Sequence = 0, Timestamp = 0, Value = (int)JoystickOffsetValues.ButtonState.ButtonPressed
            };

            mreKeyDown.Wait(5000);
            mreKeyUp.Wait(5000);

            Assert.False(isSecondKeyOutOfOrder);
            Assert.True(isFirstKeyDownPressed);
            Assert.True(isFirstKeyUpPressed);

            subKeyboard.Received().SendKeyPress(Arg.Any <int>(), Arg.Any <bool>(), Arg.Any <bool>());
        }
コード例 #9
0
        public void button_pressed_use_inherited_parent()
        {
            var isEventCalled  = false;
            var actualButtonId = 0;
            var actualScanCode = 0;

            var joystick = new TestJoystick_BasicQueue(dataBufferSize: 1);

            var activationList = new Dictionary <int, ModeActivationItem>();

            activationList.Add(1, new ModeActivationItem()
            {
                Mode = 1
            });
            activationList.Add(2, new ModeActivationItem()
            {
                Mode = 2, InheritFromMode = 1
            });

            var mode1map = CreateTestHotasTestMapWithButton();

            mode1map.Add(new HOTASButton()
            {
                MapId = (int)JoystickOffset.Button2, ActionCatalogItem = new ActionCatalogItem()
                {
                    Actions = new ObservableCollection <ButtonAction>()
                    {
                        new ButtonAction()
                        {
                            ScanCode = 1
                        }, new ButtonAction()
                        {
                            ScanCode = 1, IsKeyUp = true
                        }
                    }
                }
            });
            var mode2map     = CreateTestHotasTestMapWithButton();
            var modeProfiles = new Dictionary <int, ObservableCollection <IHotasBaseMap> >();

            modeProfiles.Add(1, mode1map);
            modeProfiles.Add(2, mode2map);

            var queue = new HOTASQueue(Substitute.For <IKeyboard>());

            queue.Listen(joystick, modeProfiles, activationList);

            //inherited key should be active
            queue.SetMode(2);

            var mre = new ManualResetEventSlim();

            queue.KeystrokeDownSent += (sender, e) =>
            {
                isEventCalled  = true;
                actualButtonId = e.MapId;
                actualScanCode = e.ScanCode;
                mre.Set();
            };

            Assert.False(isEventCalled);

            joystick.TestData[0] = new JoystickUpdate()
            {
                RawOffset = (int)JoystickOffset.Button2, Sequence = 0, Timestamp = 0, Value = (int)JoystickOffsetValues.ButtonState.ButtonPressed
            };
            mre.Wait(5000);

            Assert.True(isEventCalled);
            Assert.Equal((int)JoystickOffset.Button2, actualButtonId);
            Assert.Equal(1, actualScanCode);

            //inherited key should not be active
            activationList[2].InheritFromMode = 0;

            isEventCalled  = false;
            actualButtonId = 0;
            actualScanCode = 0;
            mre.Reset();

            queue.ButtonPressed += (sender, e) => { isEventCalled = true; actualButtonId = e.ButtonId; mre.Set(); };

            joystick.TestData[0] = new JoystickUpdate()
            {
                RawOffset = (int)JoystickOffset.Button2, Sequence = 0, Timestamp = 0, Value = (int)JoystickOffsetValues.ButtonState.ButtonPressed
            };
            mre.Wait(5000);
            Assert.True(isEventCalled);
            Assert.Equal(49, actualButtonId);
            Assert.Equal(0, actualScanCode);

            joystick.TestData[0] = new JoystickUpdate()
            {
                RawOffset = (int)JoystickOffset.Button1, Sequence = 0, Timestamp = 0, Value = (int)JoystickOffsetValues.ButtonState.ButtonReleased
            };
            mre.Reset();
            mre.Wait(5000);

            joystick.TestData[0] = new JoystickUpdate()
            {
                RawOffset = (int)JoystickOffset.Button2, Sequence = 0, Timestamp = 0, Value = (int)JoystickOffsetValues.ButtonState.ButtonReleased
            };
            mre.Reset();
            mre.Wait(5000);
        }