Esempio n. 1
0
        public void TestAcceptAndCancelFromKeyboard()
        {
            Screen             screen = new Screen(100.0f, 100.0f);
            CommandTestControl test   = new CommandTestControl();

            screen.Desktop.Children.Add(test);
            screen.FocusedControl = test;

            screen.InjectKeyPress(Keys.Escape);
            Assert.AreEqual(Command.Cancel, test.LastCommand);

            screen.InjectKeyPress(Keys.Enter);
            Assert.AreEqual(Command.Accept, test.LastCommand);
        }
Esempio n. 2
0
        public void TestInjectKeyPress()
        {
            Screen screen = new Screen();
            KeyboardTestControl control = new KeyboardTestControl();

            screen.Desktop.Children.Add(control);

            screen.InjectKeyPress(Keys.A);
            Assert.AreEqual(1, control.HeldKeyCount);
        }
Esempio n. 3
0
        public void TestMouseWheelWithActivatedControl()
        {
            Screen           screen  = new Screen(100.0f, 100.0f);
            MouseTestControl control = new MouseTestControl();

            control.Bounds = new UniRectangle(10.0f, 10.0f, 80.0f, 80.0f);
            screen.Desktop.Children.Add(control);

            screen.InjectKeyPress(Keys.A);
            screen.InjectMouseWheel(12.34f);
            Assert.AreEqual(12.34f, control.MouseWheelTicks);
        }
Esempio n. 4
0
        public void TestMousePressWithActivatedControl()
        {
            Screen           screen = new Screen(100.0f, 100.0f);
            MouseTestControl child  = new MouseTestControl();

            child.Bounds = new UniRectangle(55.0f, 10.0f, 35.0f, 80.0f);
            screen.Desktop.Children.Add(child);

            screen.InjectKeyPress(Keys.A);

            screen.InjectMousePress(MouseButtons.Left);
            Assert.AreEqual(MouseButtons.Left, child.HeldMouseButtons);
        }
Esempio n. 5
0
        public void TestFocusSwitching()
        {
            Screen screen = new Screen(100.0f, 100.0f);

            Controls.Desktop.ButtonControl center = new Controls.Desktop.ButtonControl();
            center.Bounds = new UniRectangle(40, 40, 20, 20);
            Controls.Desktop.ButtonControl left = new Controls.Desktop.ButtonControl();
            left.Bounds = new UniRectangle(10, 51, 20, 20);
            Controls.Desktop.ButtonControl right = new Controls.Desktop.ButtonControl();
            right.Bounds = new UniRectangle(70, 29, 20, 20);
            Controls.Desktop.ButtonControl up = new Controls.Desktop.ButtonControl();
            up.Bounds = new UniRectangle(29, 10, 20, 20);
            Controls.Desktop.ButtonControl down = new Controls.Desktop.ButtonControl();
            down.Bounds = new UniRectangle(51, 70, 20, 20);

            screen.Desktop.Children.Add(center);
            screen.Desktop.Children.Add(left);
            screen.Desktop.Children.Add(right);
            screen.Desktop.Children.Add(up);
            screen.Desktop.Children.Add(down);

            screen.FocusedControl = center;
            screen.InjectKeyPress(Keys.Down);
            Assert.AreSame(down, screen.FocusedControl);

            screen.FocusedControl = center;
            screen.InjectKeyPress(Keys.Up);
            Assert.AreSame(up, screen.FocusedControl);

            screen.FocusedControl = center;
            screen.InjectKeyPress(Keys.Left);
            Assert.AreSame(left, screen.FocusedControl);

            screen.FocusedControl = center;
            screen.InjectKeyPress(Keys.Right);
            Assert.AreSame(right, screen.FocusedControl);
        }
Esempio n. 6
0
        public void TestKeyPressWithFocusedControl()
        {
            Screen screen = new Screen(100.0f, 100.0f);
            KeyboardTestControl child1 = new KeyboardTestControl();
            KeyboardTestControl child2 = new KeyboardTestControl();

            screen.Desktop.Children.Add(child1);
            screen.Desktop.Children.Add(child2);

            screen.FocusedControl = child2;

            screen.InjectKeyPress(Keys.A);
            Assert.AreEqual(0, child1.HeldKeyCount);
            Assert.AreEqual(1, child2.HeldKeyCount);
            screen.InjectKeyRelease(Keys.A);
            Assert.AreEqual(0, child1.HeldKeyCount);
            Assert.AreEqual(0, child2.HeldKeyCount);
        }
Esempio n. 7
0
        public void TestFocusSwitchingWithUnfocusableControl()
        {
            Screen screen = new Screen(100.0f, 100.0f);

            Controls.Desktop.ButtonControl one = new Controls.Desktop.ButtonControl();
            one.Bounds = new UniRectangle(40, 10, 20, 20);
            Controls.Control two = new Controls.Control();
            two.Bounds = new UniRectangle(40, 40, 20, 20);
            Controls.Desktop.ButtonControl three = new Controls.Desktop.ButtonControl();
            three.Bounds = new UniRectangle(40, 70, 20, 20);

            screen.Desktop.Children.Add(one);
            screen.Desktop.Children.Add(two);
            screen.Desktop.Children.Add(three);

            screen.FocusedControl = one;
            screen.InjectKeyPress(Keys.Down);
            screen.InjectKeyRelease(Keys.Down);
            Assert.AreSame(three, screen.FocusedControl);
        }
Esempio n. 8
0
        public void TestKeyPressWithActivatedControl()
        {
            Screen screen = new Screen(100.0f, 100.0f);
            KeyboardTestControl child1 = new KeyboardTestControl();
            KeyboardTestControl child2 = new KeyboardTestControl();

            child2.Bounds = new UniRectangle(10.0f, 10.0f, 80.0f, 80.0f);
            screen.Desktop.Children.Add(child1);
            screen.Desktop.Children.Add(child2);

            // Click on child 2
            screen.InjectMouseMove(50.0f, 50.0f);
            screen.InjectMousePress(MouseButtons.Left);

            // Now child 2 should be receiving the input instead of child 1
            screen.InjectKeyPress(Keys.A);
            Assert.AreEqual(0, child1.HeldKeyCount);
            Assert.AreEqual(1, child2.HeldKeyCount);
            screen.InjectKeyRelease(Keys.A);
            Assert.AreEqual(0, child1.HeldKeyCount);
            Assert.AreEqual(0, child2.HeldKeyCount);
        }
Esempio n. 9
0
    public void TestAcceptAndCancelFromKeyboard() {
      Screen screen = new Screen(100.0f, 100.0f);
      CommandTestControl test = new CommandTestControl();
      screen.Desktop.Children.Add(test);
      screen.FocusedControl = test;

      screen.InjectKeyPress(Keys.Escape);
      Assert.AreEqual(Command.Cancel, test.LastCommand);

      screen.InjectKeyPress(Keys.Enter);
      Assert.AreEqual(Command.Accept, test.LastCommand);
    }
Esempio n. 10
0
    public void TestFocusSwitching() {
      Screen screen = new Screen(100.0f, 100.0f);
      Controls.Desktop.ButtonControl center = new Controls.Desktop.ButtonControl();
      center.Bounds = new UniRectangle(40, 40, 20, 20);
      Controls.Desktop.ButtonControl left = new Controls.Desktop.ButtonControl();
      left.Bounds = new UniRectangle(10, 51, 20, 20);
      Controls.Desktop.ButtonControl right = new Controls.Desktop.ButtonControl();
      right.Bounds = new UniRectangle(70, 29, 20, 20);
      Controls.Desktop.ButtonControl up = new Controls.Desktop.ButtonControl();
      up.Bounds = new UniRectangle(29, 10, 20, 20);
      Controls.Desktop.ButtonControl down = new Controls.Desktop.ButtonControl();
      down.Bounds = new UniRectangle(51, 70, 20, 20);

      screen.Desktop.Children.Add(center);
      screen.Desktop.Children.Add(left);
      screen.Desktop.Children.Add(right);
      screen.Desktop.Children.Add(up);
      screen.Desktop.Children.Add(down);

      screen.FocusedControl = center;
      screen.InjectKeyPress(Keys.Down);
      Assert.AreSame(down, screen.FocusedControl);

      screen.FocusedControl = center;
      screen.InjectKeyPress(Keys.Up);
      Assert.AreSame(up, screen.FocusedControl);

      screen.FocusedControl = center;
      screen.InjectKeyPress(Keys.Left);
      Assert.AreSame(left, screen.FocusedControl);

      screen.FocusedControl = center;
      screen.InjectKeyPress(Keys.Right);
      Assert.AreSame(right, screen.FocusedControl);
    }
Esempio n. 11
0
    public void TestFocusSwitchingWithUnfocusableControl() {
      Screen screen = new Screen(100.0f, 100.0f);
      Controls.Desktop.ButtonControl one = new Controls.Desktop.ButtonControl();
      one.Bounds = new UniRectangle(40, 10, 20, 20);
      Controls.Control two = new Controls.Control();
      two.Bounds = new UniRectangle(40, 40, 20, 20);
      Controls.Desktop.ButtonControl three = new Controls.Desktop.ButtonControl();
      three.Bounds = new UniRectangle(40, 70, 20, 20);

      screen.Desktop.Children.Add(one);
      screen.Desktop.Children.Add(two);
      screen.Desktop.Children.Add(three);

      screen.FocusedControl = one;
      screen.InjectKeyPress(Keys.Down);
      screen.InjectKeyRelease(Keys.Down);
      Assert.AreSame(three, screen.FocusedControl);
    }
Esempio n. 12
0
    public void TestMouseWheelWithActivatedControl() {
      Screen screen = new Screen(100.0f, 100.0f);
      MouseTestControl control = new MouseTestControl();
      control.Bounds = new UniRectangle(10.0f, 10.0f, 80.0f, 80.0f);
      screen.Desktop.Children.Add(control);

      screen.InjectKeyPress(Keys.A);
      screen.InjectMouseWheel(12.34f);
      Assert.AreEqual(12.34f, control.MouseWheelTicks);
    }
Esempio n. 13
0
    public void TestMousePressWithActivatedControl() {
      Screen screen = new Screen(100.0f, 100.0f);
      MouseTestControl child = new MouseTestControl();
      child.Bounds = new UniRectangle(55.0f, 10.0f, 35.0f, 80.0f);
      screen.Desktop.Children.Add(child);

      screen.InjectKeyPress(Keys.A);

      screen.InjectMousePress(MouseButtons.Left);
      Assert.AreEqual(MouseButtons.Left, child.HeldMouseButtons);
    }
Esempio n. 14
0
    public void TestKeyPressWithFocusedControl() {
      Screen screen = new Screen(100.0f, 100.0f);
      KeyboardTestControl child1 = new KeyboardTestControl();
      KeyboardTestControl child2 = new KeyboardTestControl();
      screen.Desktop.Children.Add(child1);
      screen.Desktop.Children.Add(child2);

      screen.FocusedControl = child2;

      screen.InjectKeyPress(Keys.A);
      Assert.AreEqual(0, child1.HeldKeyCount);
      Assert.AreEqual(1, child2.HeldKeyCount);
      screen.InjectKeyRelease(Keys.A);
      Assert.AreEqual(0, child1.HeldKeyCount);
      Assert.AreEqual(0, child2.HeldKeyCount);
    }
Esempio n. 15
0
    public void TestKeyPressWithActivatedControl() {
      Screen screen = new Screen(100.0f, 100.0f);
      KeyboardTestControl child1 = new KeyboardTestControl();
      KeyboardTestControl child2 = new KeyboardTestControl();
      child2.Bounds = new UniRectangle(10.0f, 10.0f, 80.0f, 80.0f);
      screen.Desktop.Children.Add(child1);
      screen.Desktop.Children.Add(child2);

      // Click on child 2
      screen.InjectMouseMove(50.0f, 50.0f);
      screen.InjectMousePress(MouseButtons.Left);

      // Now child 2 should be receiving the input instead of child 1
      screen.InjectKeyPress(Keys.A);
      Assert.AreEqual(0, child1.HeldKeyCount);
      Assert.AreEqual(1, child2.HeldKeyCount);
      screen.InjectKeyRelease(Keys.A);
      Assert.AreEqual(0, child1.HeldKeyCount);
      Assert.AreEqual(0, child2.HeldKeyCount);
    }
Esempio n. 16
0
    public void TestInjectKeyPress() {
      Screen screen = new Screen();
      KeyboardTestControl control = new KeyboardTestControl();
      screen.Desktop.Children.Add(control);

      screen.InjectKeyPress(Keys.A);
      Assert.AreEqual(1, control.HeldKeyCount);
    }