public void State1MustBypassInputToStrokeWatcher_RRTest() { foreach (var a in TestDef.Constant.DoubleTriggerButtons) { var gestureDef = new List <OnButtonGestureDefinition>() { new OnButtonWithIfStrokeGestureDefinition( (ctx) => { return(true); }, a as DSL.Def.AcceptableInOnClause, new Def.Stroke(Def.Direction.Down), (ctx) => { Assert.Fail(); }) }; foreach (var b in TestDef.Constant.Buttons) { using (var Global = new StateGlobal()) { Global.StrokeWatcher.Dispose(); Global.StrokeWatcher = new StrokeWatcherMock(); var S0 = new State0(Global, new List <GestureDefinition>()); var S1 = new State1(Global, S0, ctx, Helper.Convert(a as DSL.Def.AcceptableInOnClause), gestureDef, new List <IfButtonGestureDefinition>()); S1.Input(Helper.Convert(b as DSL.Def.AcceptableInIfButtonClause), new Point(0, 0)); S1.Input(Def.Constant.Move, new Point(100, 100)); Console.WriteLine(((StrokeWatcherMock)Global.StrokeWatcher).queue.Count()); Assert.IsTrue(((StrokeWatcherMock)Global.StrokeWatcher).queue.SequenceEqual(new List <Point>() { new Point(0, 0), new Point(100, 100) })); } } } }
public void Transition1_2_RRTest() { using (var countDown = new CountdownEvent(2)) { foreach (var a in TestDef.Constant.DoubleTriggerButtons) { var gestureDefA = new List <OnButtonGestureDefinition>() { new OnButtonWithIfStrokeGestureDefinition( (ctx) => { return(true); }, a as DSL.Def.AcceptableInOnClause, new Def.Stroke(new List <Def.Direction>() { Def.Direction.Down }), (ctx) => { countDown.Signal(); }) }; var gestureDefB = new List <IfButtonGestureDefinition>() { new IfButtonGestureDefinition( (ctx) => { return(true); }, a as DSL.Def.AcceptableInIfButtonClause, (ctx) => { Assert.Fail(); }, (ctx) => { Assert.Fail(); }, (ctx) => { countDown.Signal(); }) }; foreach (var b in TestDef.Constant.DoubleTriggerButtons) { countDown.Reset(); using (var Global = new StateGlobal()) { var S0 = new State0(Global, new List <GestureDefinition>()); var S1 = new State1(Global, S0, ctx, Helper.Convert(a as DSL.Def.AcceptableInOnClause), gestureDefA, gestureDefB); Global.StrokeWatcher.strokes.Add(new Stroke.Stroke( Global.Config.Gesture.StrokeDirectionChangeThreshold, Global.Config.Gesture.StrokeExtensionThreshold, Def.Direction.Down)); var ev = Helper.Convert(b as DSL.Def.AcceptableInOnClause).GetPair(); var res = S1.Input((Def.Event.IEvent)ev, new Point()); if (a == b) { Assert.IsTrue(res.NextState is State0); Assert.IsTrue(countDown.Wait(50)); } else { Assert.IsTrue(res.NextState is State1); Assert.IsFalse(countDown.Wait(50)); } } } } } }
public void InputMustResetIgnoreListWhenAPairOfTriggerInIgnoreListGivenTest() { using (var Global = new StateGlobal()) { var S0 = new State0(Global, new List <GestureDefinition>()); var S1 = new State1(Global, S0, ctx, Def.Constant.LeftButtonDown, new List <OnButtonGestureDefinition>(), new List <IfButtonGestureDefinition>()); Global.IgnoreNext.Add(Def.Constant.RightButtonUp); Assert.AreEqual(Global.IgnoreNext.Count, 1); var res = S1.Input(Def.Constant.RightButtonDown, new Point()); Assert.IsFalse(res.Event.IsConsumed); Assert.AreEqual(Global.IgnoreNext.Count, 0); } }
public void Transition1_1_RRTest() { using (var countDown = new CountdownEvent(1)) { foreach (var a in TestDef.Constant.DoubleTriggerButtons) { var gestureDef = new List <OnButtonGestureDefinition>() { new OnButtonWithIfButtonGestureDefinition( (ctx) => { return(true); }, DSL.Def.Constant.RightButton, a as DSL.Def.AcceptableInIfButtonClause, (ctx) => { countDown.Signal(); }, (ctx) => { Assert.Fail(); }, (ctx) => { Assert.Fail(); }) }; foreach (var b in TestDef.Constant.Buttons) { countDown.Reset(); using (var Global = new StateGlobal()) { var S0 = new State0(Global, new List <GestureDefinition>()); var S1 = new State1(Global, S0, ctx, Def.Constant.RightButtonDown, gestureDef, new List <IfButtonGestureDefinition>()); var ev = Helper.Convert(b as DSL.Def.AcceptableInIfButtonClause); var res = S1.Input(ev, new Point()); if (a == b) { Assert.IsTrue(res.NextState is State3); Assert.IsTrue(S1.T1[(Def.Event.IDoubleActionSet)ev].SequenceEqual(((State3)res.NextState).T1)); Assert.IsTrue(countDown.Wait(50)); } else { Assert.IsTrue(res.NextState is State1); Assert.IsFalse(countDown.Wait(50)); } } } } } }
public void Transition1_3_RRTest() { using (var countDown = new CountdownEvent(2)) { foreach (var a in TestDef.Constant.DoubleTriggerButtons) { var gestureDef = new List <IfButtonGestureDefinition>() { new IfButtonGestureDefinition( (ctx) => { return(true); }, a as DSL.Def.AcceptableInIfButtonClause, (ctx) => { Assert.Fail(); }, (ctx) => { countDown.Signal(); }, (ctx) => { countDown.Signal(); }) }; foreach (var b in TestDef.Constant.DoubleTriggerButtons) { countDown.Reset(); using (var Global = new StateGlobal()) { var S0 = new State0(new StateGlobal(), gestureDef); var S1 = new State1(Global, S0, ctx, Helper.Convert(a as DSL.Def.AcceptableInOnClause), new List <OnButtonGestureDefinition>(), gestureDef); var ev = Helper.Convert(b as DSL.Def.AcceptableInOnClause).GetPair(); var res = S1.Input((Def.Event.IEvent)ev, new Point()); if (a == b) { Assert.IsTrue(res.NextState is State0); Assert.IsTrue(countDown.Wait(50)); } else { Assert.IsTrue(res.NextState is State1); Assert.IsFalse(countDown.Wait(50)); } } } } } }
public void Transition1_4_RRTest() { using (var countDown = new CountdownEvent(1)) { foreach (var a in TestDef.Constant.DoubleTriggerButtons) { foreach (var b in TestDef.Constant.DoubleTriggerButtons) { mouseEvents.Clear(); countDown.Reset(); using (var Global = new StateGlobal()) { var S0 = new State0(new StateGlobal(), new List <GestureDefinition>()); var S1 = new State1(Global, S0, ctx, Helper.Convert(a as DSL.Def.AcceptableInOnClause), new List <OnButtonGestureDefinition>(), new List <IfButtonGestureDefinition>()); var ev = Helper.Convert(b as DSL.Def.AcceptableInOnClause).GetPair(); var res = S1.Input((Def.Event.IEvent)ev, new Point()); Global.UserActionTaskFactory.StartNew(() => { countDown.Signal(); }); countDown.Wait(50); if (a == b) { Assert.IsTrue(res.NextState is State0); Assert.AreEqual(mouseEvents.Count, 2); if (a == DSL.Def.Constant.LeftButton) { Assert.AreEqual(mouseEvents[0].Item1, LowLevelMouseHook.Event.WM_LBUTTONDOWN); Assert.AreEqual(mouseEvents[1].Item1, LowLevelMouseHook.Event.WM_LBUTTONUP); } else if (a == DSL.Def.Constant.MiddleButton) { Assert.AreEqual(mouseEvents[0].Item1, LowLevelMouseHook.Event.WM_MBUTTONDOWN); Assert.AreEqual(mouseEvents[1].Item1, LowLevelMouseHook.Event.WM_MBUTTONUP); } else if (a == DSL.Def.Constant.RightButton) { Assert.AreEqual(mouseEvents[0].Item1, LowLevelMouseHook.Event.WM_RBUTTONDOWN); Assert.AreEqual(mouseEvents[1].Item1, LowLevelMouseHook.Event.WM_RBUTTONUP); } else if (a == DSL.Def.Constant.X1Button) { Assert.AreEqual(mouseEvents[0].Item1, LowLevelMouseHook.Event.WM_XBUTTONDOWN); Assert.IsTrue(mouseEvents[0].Item2.mouseData.asXButton.isXButton1); Assert.AreEqual(mouseEvents[1].Item1, LowLevelMouseHook.Event.WM_XBUTTONUP); Assert.IsTrue(mouseEvents[1].Item2.mouseData.asXButton.isXButton1); } else if (a == DSL.Def.Constant.X2Button) { Assert.AreEqual(mouseEvents[0].Item1, LowLevelMouseHook.Event.WM_XBUTTONDOWN); Assert.IsTrue(mouseEvents[0].Item2.mouseData.asXButton.isXButton2); Assert.AreEqual(mouseEvents[1].Item1, LowLevelMouseHook.Event.WM_XBUTTONUP); Assert.IsTrue(mouseEvents[1].Item2.mouseData.asXButton.isXButton2); } else { throw new InvalidOperationException(); } } else { Assert.IsTrue(res.NextState is State1); Assert.AreEqual(mouseEvents.Count, 0); } } } } } }