Beispiel #1
0
 public void State2MustBypassInputToStrokeWatcher_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) => { })
         };
         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>());
                 var S2 = S1.S2;
                 S2.Input(Helper.Convert(b as DSL.Def.AcceptableInIfButtonClause), new Point(0, 0));
                 S2.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)
                 }));
             }
         }
     }
 }
Beispiel #2
0
        public void Transition2_4_RRTest()
        {
            var countDown = new CountdownEvent(1);

            foreach (var a in TestDef.Constant.DoubleTriggerButtons)
            {
                countDown.Reset();
                var gestureDef = new List <IfButtonGestureDefinition>()
                {
                    new IfButtonGestureDefinition(
                        (ctx) => { return(true); },
                        a as DSL.Def.AcceptableInIfButtonClause,
                        (ctx) => { Assert.Fail(); },
                        (ctx) => { Assert.Fail(); },
                        (ctx) => { countDown.Signal(); })
                };
                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), new List <OnButtonGestureDefinition>(), gestureDef);
                    var S2  = S1.S2;
                    var res = S2.Reset();
                    Assert.IsTrue(res is State0);
                    Assert.IsTrue(Global.IgnoreNext.Contains(Helper.Convert(a as DSL.Def.AcceptableInOnClause).GetPair()));
                    Assert.IsTrue(countDown.Wait(50));
                }
            }
        }
 public void Transition0_1_B_RRTest()
 {
     foreach (var a in TestDef.Constant.DoubleTriggerButtons)
     {
         var gestureDef = new List <GestureDefinition>()
         {
             new OnButtonWithIfButtonGestureDefinition(
                 (ctx) => { return(true); },
                 a as DSL.Def.AcceptableInOnClause,
                 DSL.Def.Constant.WheelUp,
                 (ctx) => { Assert.Fail(); },
                 (ctx) => { Assert.Fail(); },
                 (ctx) => { Assert.Fail(); })
         };
         using (var Global = new StateGlobal())
         {
             var S0 = new State0(Global, gestureDef);
             foreach (var b in TestDef.Constant.Buttons)
             {
                 var res = S0.Input(Helper.Convert(b as DSL.Def.AcceptableInIfButtonClause), new Point());
                 if (a == b)
                 {
                     Assert.IsTrue(res.NextState is State1);
                     Assert.IsTrue(gestureDef.SequenceEqual(((State1)res.NextState).T0[Def.Constant.WheelUp]));
                 }
                 else
                 {
                     Assert.IsTrue(res.NextState is State0);
                 }
             }
         }
     }
 }
 public void Transition3_0_RRTest()
 {
     using (var countDown = new CountdownEvent(2))
     {
         foreach (var a in TestDef.Constant.DoubleTriggerButtons)
         {
             foreach (var b in TestDef.Constant.DoubleTriggerButtons)
             {
                 var gestureDefA = new List <IfButtonGestureDefinition>()
                 {
                     new IfButtonGestureDefinition(
                         (ctx) => { return(true); },
                         a as DSL.Def.AcceptableInIfButtonClause,
                         (ctx) => { Assert.Fail(); },
                         (ctx) => { Assert.Fail(); },
                         (ctx) => { Assert.Fail(); })
                 };
                 var gestureDefB = new List <OnButtonWithIfButtonGestureDefinition>()
                 {
                     new OnButtonWithIfButtonGestureDefinition(
                         (ctx) => { return(true); },
                         a as DSL.Def.AcceptableInOnClause,
                         b as DSL.Def.AcceptableInIfButtonClause,
                         (ctx) => { Assert.Fail(); },
                         (ctx) => { countDown.Signal(); },
                         (ctx) => { countDown.Signal(); })
                 };
                 foreach (var c in TestDef.Constant.DoubleTriggerButtons)
                 {
                     if (a == c)
                     {
                         continue;
                     }
                     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), gestureDefB, gestureDefA);
                         var S2  = S1.S2;
                         var S3  = new State3(Global, S0, S2, ctx, Helper.Convert(a as DSL.Def.AcceptableInOnClause), Helper.Convert(b as DSL.Def.AcceptableInOnClause), S2.T3, gestureDefB);
                         var ev  = Helper.Convert(c as DSL.Def.AcceptableInOnClause).GetPair();
                         var res = S3.Input((Def.Event.IEvent)ev, new Point());
                         if (b == c)
                         {
                             Assert.IsTrue(res.NextState is State2);
                             Assert.IsTrue(Global.IgnoreNext.Count() == 0);
                             Assert.IsTrue(countDown.Wait(50));
                         }
                         else
                         {
                             Assert.IsTrue(res.NextState is State3);
                             Assert.IsTrue(Global.IgnoreNext.Count() == 0);
                             Assert.IsFalse(countDown.Wait(50));
                         }
                     }
                 }
             }
         }
     }
 }
Beispiel #5
0
 public static StateGlobal Instance()
 {
     if (_instance == null)
     {
         _instance = new StateGlobal();
     }
     return(_instance);
 }
 public void Transition0_2_Test()
 {
     using (var Global = new StateGlobal())
     {
         var S0  = new State0(Global, new List <GestureDefinition>());
         var res = S0.Reset();
         Assert.IsTrue(res is State0);
     }
 }
Beispiel #7
0
 public void RestorePrimaryButtonClickTest()
 {
     using (var Global = new StateGlobal())
     {
         var S0 = new State0(new StateGlobal(), new List <GestureDefinition>());
         {
             var S1 = new State1(Global, S0, ctx, Def.Constant.LeftButtonDown, new List <OnButtonGestureDefinition>(), new List <IfButtonGestureDefinition>());
             mouseEvents.Clear();
             Assert.AreEqual(mouseEvents.Count, 0);
             S1.RestorePrimaryButtonClickEvent()();
             Assert.AreEqual(mouseEvents.Count, 2);
             Assert.AreEqual(mouseEvents[0].Item1, LowLevelMouseHook.Event.WM_LBUTTONDOWN);
             Assert.AreEqual(mouseEvents[1].Item1, LowLevelMouseHook.Event.WM_LBUTTONUP);
         }
         {
             var S1 = new State1(Global, S0, ctx, Def.Constant.MiddleButtonDown, new List <OnButtonGestureDefinition>(), new List <IfButtonGestureDefinition>());
             mouseEvents.Clear();
             Assert.AreEqual(mouseEvents.Count, 0);
             S1.RestorePrimaryButtonClickEvent()();
             Assert.AreEqual(mouseEvents.Count, 2);
             Assert.AreEqual(mouseEvents[0].Item1, LowLevelMouseHook.Event.WM_MBUTTONDOWN);
             Assert.AreEqual(mouseEvents[1].Item1, LowLevelMouseHook.Event.WM_MBUTTONUP);
         }
         {
             var S1 = new State1(Global, S0, ctx, Def.Constant.RightButtonDown, new List <OnButtonGestureDefinition>(), new List <IfButtonGestureDefinition>());
             mouseEvents.Clear();
             Assert.AreEqual(mouseEvents.Count, 0);
             S1.RestorePrimaryButtonClickEvent()();
             Assert.AreEqual(mouseEvents.Count, 2);
             Assert.AreEqual(mouseEvents[0].Item1, LowLevelMouseHook.Event.WM_RBUTTONDOWN);
             Assert.AreEqual(mouseEvents[1].Item1, LowLevelMouseHook.Event.WM_RBUTTONUP);
         }
         {
             var S1 = new State1(Global, S0, ctx, Def.Constant.X1ButtonDown, new List <OnButtonGestureDefinition>(), new List <IfButtonGestureDefinition>());
             mouseEvents.Clear();
             Assert.AreEqual(mouseEvents.Count, 0);
             S1.RestorePrimaryButtonClickEvent()();
             Assert.AreEqual(mouseEvents.Count, 2);
             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);
         }
         {
             var S1 = new State1(Global, S0, ctx, Def.Constant.X2ButtonDown, new List <OnButtonGestureDefinition>(), new List <IfButtonGestureDefinition>());
             mouseEvents.Clear();
             Assert.AreEqual(mouseEvents.Count, 0);
             S1.RestorePrimaryButtonClickEvent()();
             Assert.AreEqual(mouseEvents.Count, 2);
             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);
         }
     }
 }
Beispiel #8
0
 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));
                     }
                 }
             }
         }
     }
 }
Beispiel #9
0
 public override void INIT(int id)
 {
     base.INIT(id);
     iGold         = 0;
     iThirst       = 10;
     iTired        = 10;
     iBankMoney    = 0;
     eLocation     = MAGADATA.LocationType.HOME;
     mStateMachine = new StateMachine <Miner>(this);
     mStateMachine.SetCurrentState(StateHome.Instance());
     mStateMachine.SetGlobalState(StateGlobal.Instance());
 }
Beispiel #10
0
        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);
            }
        }
Beispiel #11
0
 public void Transition1_5_RRTest()
 {
     using (var countDown = new CountdownEvent(1))
     {
         foreach (var a in TestDef.Constant.DoubleTriggerButtons)
         {
             mouseEvents.Clear();
             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), new List <OnButtonGestureDefinition>(), new List <IfButtonGestureDefinition>());
                 var res = S1.Cancel();
                 Global.UserActionTaskFactory.StartNew(() =>
                 {
                     countDown.Signal();
                 });
                 countDown.Wait(50);
                 Assert.AreEqual(mouseEvents.Count, 1);
                 if (a == DSL.Def.Constant.LeftButton)
                 {
                     Assert.AreEqual(mouseEvents[0].Item1, LowLevelMouseHook.Event.WM_LBUTTONDOWN);
                 }
                 else if (a == DSL.Def.Constant.MiddleButton)
                 {
                     Assert.AreEqual(mouseEvents[0].Item1, LowLevelMouseHook.Event.WM_MBUTTONDOWN);
                 }
                 else if (a == DSL.Def.Constant.RightButton)
                 {
                     Assert.AreEqual(mouseEvents[0].Item1, LowLevelMouseHook.Event.WM_RBUTTONDOWN);
                 }
                 else if (a == DSL.Def.Constant.X1Button)
                 {
                     Assert.AreEqual(mouseEvents[0].Item1, LowLevelMouseHook.Event.WM_XBUTTONDOWN);
                     Assert.IsTrue(mouseEvents[0].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.IsTrue(res is State0);
             }
         }
     }
 }
Beispiel #12
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));
                     }
                 }
             }
         }
     }
 }
Beispiel #13
0
 public void Transition2_0_RRTest()
 {
     using (var countDown = new CountdownEvent(1))
     {
         foreach (var a in TestDef.Constant.SingleTriggerButtons)
         {
             var gestureDef = new List <OnButtonGestureDefinition>()
             {
                 new OnButtonWithIfButtonGestureDefinition(
                     (ctx) => { return(true); },
                     DSL.Def.Constant.RightButton,
                     a as DSL.Def.AcceptableInIfButtonClause,
                     null,
                     (ctx) => { countDown.Signal(); },
                     null)
             };
             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 S2  = S1.S2;
                     var ev  = Helper.Convert(b as DSL.Def.AcceptableInIfButtonClause);
                     var res = S2.Input(ev, new Point());
                     Assert.IsTrue(res.NextState is State2);
                     if (a == b)
                     {
                         Assert.IsTrue(countDown.Wait(50));
                     }
                     else
                     {
                         Assert.IsFalse(countDown.Wait(50));
                     }
                 }
             }
         }
     }
 }
Beispiel #14
0
 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 Transition0_1_A_RRTest()
 {
     using (var countDown = new CountdownEvent(1))
     {
         foreach (var a in TestDef.Constant.DoubleTriggerButtons)
         {
             var gestureDef = new List <GestureDefinition>()
             {
                 new IfButtonGestureDefinition(
                     (ctx) => { return(true); },
                     a as DSL.Def.AcceptableInIfButtonClause,
                     (ctx) => { countDown.Signal(); },
                     (ctx) => { Assert.Fail(); },
                     (ctx) => { Assert.Fail(); })
             };
             using (var Global = new StateGlobal())
             {
                 var S0 = new State0(Global, gestureDef);
                 foreach (var b in TestDef.Constant.Buttons)
                 {
                     countDown.Reset();
                     var res = S0.Input(Helper.Convert(b as DSL.Def.AcceptableInIfButtonClause), new Point());
                     if (a == b)
                     {
                         Assert.IsTrue(res.NextState is State1);
                         Assert.AreEqual(gestureDef[0], ((State1)res.NextState).T3.ToList()[0]);
                         Assert.IsTrue(countDown.Wait(50));
                     }
                     else
                     {
                         Assert.IsTrue(res.NextState is State0);
                         Assert.IsFalse(countDown.Wait(50));
                     }
                 }
             }
         }
     }
 }
Beispiel #16
0
 public void Transition2_1_RRTest()
 {
     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,
                 null,
                 (ctx) => { },
                 null)
         };
         foreach (var b in TestDef.Constant.Buttons)
         {
             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 S2  = S1.S2;
                 var ev  = Helper.Convert(b as DSL.Def.AcceptableInIfButtonClause);
                 var res = S2.Input(ev, new Point());
                 if (a == b)
                 {
                     Assert.IsTrue(res.NextState is State3);
                     Assert.IsTrue(S2.T1[(Def.Event.IDoubleActionSet)ev].SequenceEqual(((State3)res.NextState).T1));
                 }
                 else
                 {
                     Assert.IsTrue(res.NextState is State2);
                 }
             }
         }
     }
 }
Beispiel #17
0
 private StateGlobal(StateGlobal state)
 {
 }