예제 #1
0
        public void TestProcessKeyMessage_WM_CHAR()
        {
            TextBoxPoker tb = new TextBoxPoker();
            DataGridMock dg = new DataGridMock();
            Message      m;

            dg.Controls.Add(tb);

            tb.SetDataGrid(dg);

            tb.IsInEditOrNavigateMode = true;

            /* test Enter key behavior */
            m        = new Message();
            m.Msg    = 0x0102 /* WM_CHAR */;
            m.WParam = (IntPtr)Keys.Enter;

            bool rv = tb.DoProcessKeyMessage(ref m);

            Assert.AreEqual(0x0102, m.Msg, "1");
            Assert.AreEqual(Keys.Enter, (Keys)m.WParam.ToInt32(), "2");
            Assert.IsTrue(rv, "3");
            Assert.IsTrue(tb.IsInEditOrNavigateMode, "4");
        }
예제 #2
0
		public void TestProcessKeyMessage_WM_KEYDOWN ()
		{
			TextBoxPoker tb = new TextBoxPoker ();
			DataGridMock dg = new DataGridMock ();
			Message m;
			bool rv;

			dg.Controls.Add (tb);
			tb.SetDataGrid (dg);

			/* test F2 key behavior */
			tb.IsInEditOrNavigateMode = false;
			tb.Text = "hello world";
			tb.SelectionStart = 0;
			tb.SelectionLength = 5;

			m = new Message ();
			m.Msg = 0x0100 /* WM_KEYDOWN */;
			m.WParam = (IntPtr)Keys.F2;

			rv = tb.DoProcessKeyMessage (ref m);
			Assert.AreEqual (0x0100, m.Msg, "1");
			Assert.AreEqual (Keys.F2, (Keys)m.WParam.ToInt32(), "2");
			Assert.IsTrue  (rv, "3");
			Assert.IsFalse (tb.IsInEditOrNavigateMode, "4");

			Assert.AreEqual (0, tb.SelectionLength, "5");
			Assert.AreEqual (tb.Text.Length, tb.SelectionStart, "6");
			Assert.IsFalse (tb.ProcessKeyPreviewCalled, "7");
			Assert.IsFalse (tb.ProcessKeyEventArgsCalled, "8");
			tb.ProcessKeyPreviewCalled = false;
			tb.ProcessKeyEventArgsCalled = false;

			/* test enter behavior */
			tb.IsInEditOrNavigateMode = true;
			m = new Message ();
			m.Msg = 0x0100 /* WM_KEYDOWN */;
			m.WParam = (IntPtr)Keys.Enter;

			rv = tb.DoProcessKeyMessage (ref m);
			Assert.AreEqual (0x0100, m.Msg, "9");
			Assert.AreEqual (Keys.Enter, (Keys)m.WParam.ToInt32(), "10");
			Assert.IsFalse  (rv, "11");
			Assert.IsTrue (tb.IsInEditOrNavigateMode, "12");
			Assert.IsTrue (tb.ProcessKeyPreviewCalled, "13");
			Assert.IsFalse (tb.ProcessKeyPreviewReturnValue, "14");
			Assert.IsFalse (tb.ProcessKeyEventArgsCalled, "15");
			tb.ProcessKeyPreviewCalled = false;
			tb.ProcessKeyEventArgsCalled = false;

			/* test left behavior (within the string) */
			tb.IsInEditOrNavigateMode = true;
			tb.Text = "hello world";
			tb.SelectionStart = 5;
			tb.SelectionLength = 0;

			m = new Message ();
			m.Msg = 0x0100 /* WM_KEYDOWN */;
			m.WParam = (IntPtr)Keys.Left;

			rv = tb.DoProcessKeyMessage (ref m);
			Assert.AreEqual (0x0100, m.Msg, "16");
			Assert.AreEqual (Keys.Left, (Keys)m.WParam.ToInt32(), "17");
			Assert.IsFalse  (rv, "18");
			Assert.IsTrue (tb.IsInEditOrNavigateMode, "19");
			Assert.IsFalse (tb.ProcessKeyPreviewCalled, "20");
			Assert.IsTrue (tb.ProcessKeyEventArgsCalled, "21");
			Assert.IsFalse (tb.ProcessKeyEventArgsReturnValue, "21.5");
			tb.ProcessKeyPreviewCalled = false;
			tb.ProcessKeyEventArgsCalled = false;

			/* test left behavior (at the left-most position) */
			tb.IsInEditOrNavigateMode = true;
			tb.Text = "hello world";
			tb.SelectionStart = 0;
			tb.SelectionLength = 0;

			m = new Message ();
			m.Msg = 0x0100 /* WM_KEYDOWN */;
			m.WParam = (IntPtr)Keys.Left;

			rv = tb.DoProcessKeyMessage (ref m);
			Assert.AreEqual (0x0100, m.Msg, "22");
			Assert.AreEqual (Keys.Left, (Keys)m.WParam.ToInt32(), "23");
			Assert.IsFalse  (rv, "24");
			Assert.IsTrue (tb.IsInEditOrNavigateMode, "25");
			Assert.IsTrue (tb.ProcessKeyPreviewCalled, "26");
			Assert.IsFalse (tb.ProcessKeyPreviewReturnValue, "26");
			Assert.IsFalse (tb.ProcessKeyEventArgsCalled, "27");
			tb.ProcessKeyPreviewCalled = false;
			tb.ProcessKeyEventArgsCalled = false;

			/* test right behavior (within the string) */
			tb.IsInEditOrNavigateMode = true;
			tb.Text = "hello world";
			tb.SelectionStart = 5;
			tb.SelectionLength = 0;

			m = new Message ();
			m.Msg = 0x0100 /* WM_KEYDOWN */;
			m.WParam = (IntPtr)Keys.Right;

			rv = tb.DoProcessKeyMessage (ref m);
			Assert.AreEqual (0x0100, m.Msg, "28");
			Assert.AreEqual (Keys.Right, (Keys)m.WParam.ToInt32(), "29");
			Assert.IsFalse  (rv, "30");
			Assert.IsTrue (tb.IsInEditOrNavigateMode, "31");
			Assert.IsFalse (tb.ProcessKeyPreviewCalled, "32");
			Assert.IsTrue (tb.ProcessKeyEventArgsCalled, "33");
			Assert.IsFalse (tb.ProcessKeyEventArgsReturnValue, "33.5");
			tb.ProcessKeyPreviewCalled = false;
			tb.ProcessKeyEventArgsCalled = false;

			/* test right behavior (at the left-most position) */
			tb.IsInEditOrNavigateMode = true;
			tb.Text = "hello world";
			tb.SelectionStart = tb.Text.Length;
			tb.SelectionLength = 0;

			m = new Message ();
			m.Msg = 0x0100 /* WM_KEYDOWN */;
			m.WParam = (IntPtr)Keys.Right;

			rv = tb.DoProcessKeyMessage (ref m);
			Assert.AreEqual (0x0100, m.Msg, "34");
			Assert.AreEqual (Keys.Right, (Keys)m.WParam.ToInt32(), "35");
			Assert.IsFalse  (rv, "36");
			Assert.IsTrue (tb.IsInEditOrNavigateMode, "37");
			Assert.IsTrue (tb.ProcessKeyPreviewCalled, "38");
			Assert.IsFalse (tb.ProcessKeyPreviewReturnValue, "39");
			Assert.IsFalse (tb.ProcessKeyEventArgsCalled, "40");
			tb.ProcessKeyPreviewCalled = false;
			tb.ProcessKeyEventArgsCalled = false;

			/* test Tab behavior */
			tb.IsInEditOrNavigateMode = false;
			m = new Message ();
			m.Msg = 0x0100 /* WM_KEYDOWN */;
			m.WParam = (IntPtr)Keys.Tab;

			rv = tb.DoProcessKeyMessage (ref m);
			Assert.AreEqual (0x0100, m.Msg, "41");
			Assert.AreEqual (Keys.Tab, (Keys)m.WParam.ToInt32(), "42");
			Assert.IsFalse  (rv, "43");
			Assert.IsFalse (tb.IsInEditOrNavigateMode, "44");
			Assert.IsFalse (tb.ProcessKeyPreviewCalled, "45");
			Assert.IsTrue (tb.ProcessKeyEventArgsCalled, "46");
			Assert.IsFalse (tb.ProcessKeyEventArgsReturnValue, "46.5");
			tb.ProcessKeyPreviewCalled = false;
			tb.ProcessKeyEventArgsCalled = false;

			/* test Up behavior */
			tb.IsInEditOrNavigateMode = false;
			m = new Message ();
			m.Msg = 0x0100 /* WM_KEYDOWN */;
			m.WParam = (IntPtr)Keys.Up;

			rv = tb.DoProcessKeyMessage (ref m);
			Assert.AreEqual (0x0100, m.Msg, "47");
			Assert.AreEqual (Keys.Up, (Keys)m.WParam.ToInt32(), "48");
			Assert.IsFalse  (rv, "49");
			Assert.IsFalse (tb.IsInEditOrNavigateMode, "50");
			Assert.IsTrue (tb.ProcessKeyPreviewCalled, "51");
			Assert.IsFalse (tb.ProcessKeyPreviewReturnValue, "52");
			Assert.IsFalse (tb.ProcessKeyEventArgsCalled, "53");
			tb.ProcessKeyPreviewCalled = false;
			tb.ProcessKeyEventArgsCalled = false;

			/* test Down behavior */
			tb.IsInEditOrNavigateMode = false;
			m = new Message ();
			m.Msg = 0x0100 /* WM_KEYDOWN */;
			m.WParam = (IntPtr)Keys.Down;

			rv = tb.DoProcessKeyMessage (ref m);
			Assert.AreEqual (0x0100, m.Msg, "54");
			Assert.AreEqual (Keys.Down, (Keys)m.WParam.ToInt32(), "55");
			Assert.IsFalse  (rv, "56");
			Assert.IsFalse (tb.IsInEditOrNavigateMode, "57");
			Assert.IsTrue (tb.ProcessKeyPreviewCalled, "58");
			Assert.IsFalse (tb.ProcessKeyPreviewReturnValue, "59");
			Assert.IsFalse (tb.ProcessKeyEventArgsCalled, "60");
			tb.ProcessKeyPreviewCalled = false;
			tb.ProcessKeyEventArgsCalled = false;
		}
예제 #3
0
		public void TestProcessKeyMessage_WM_CHAR ()
		{
			TextBoxPoker tb = new TextBoxPoker ();
			DataGridMock dg = new DataGridMock ();
			Message m;

			dg.Controls.Add (tb);

			tb.SetDataGrid (dg);

			tb.IsInEditOrNavigateMode = true;

			/* test Enter key behavior */
			m = new Message ();
			m.Msg = 0x0102 /* WM_CHAR */;
			m.WParam = (IntPtr)Keys.Enter;

			bool rv = tb.DoProcessKeyMessage (ref m);
			Assert.AreEqual (0x0102, m.Msg, "1");
			Assert.AreEqual (Keys.Enter, (Keys)m.WParam.ToInt32(), "2");
			Assert.IsTrue  (rv, "3");
			Assert.IsTrue (tb.IsInEditOrNavigateMode, "4");
		}
예제 #4
0
        public void TestProcessKeyMessage_WM_KEYDOWN()
        {
            TextBoxPoker tb = new TextBoxPoker();
            DataGridMock dg = new DataGridMock();
            Message      m;
            bool         rv;

            dg.Controls.Add(tb);
            tb.SetDataGrid(dg);

            /* test F2 key behavior */
            tb.IsInEditOrNavigateMode = false;
            tb.Text            = "hello world";
            tb.SelectionStart  = 0;
            tb.SelectionLength = 5;

            m        = new Message();
            m.Msg    = 0x0100 /* WM_KEYDOWN */;
            m.WParam = (IntPtr)Keys.F2;

            rv = tb.DoProcessKeyMessage(ref m);
            Assert.AreEqual(0x0100, m.Msg, "1");
            Assert.AreEqual(Keys.F2, (Keys)m.WParam.ToInt32(), "2");
            Assert.IsTrue(rv, "3");
            Assert.IsFalse(tb.IsInEditOrNavigateMode, "4");

            Assert.AreEqual(0, tb.SelectionLength, "5");
            Assert.AreEqual(tb.Text.Length, tb.SelectionStart, "6");
            Assert.IsFalse(tb.ProcessKeyPreviewCalled, "7");
            Assert.IsFalse(tb.ProcessKeyEventArgsCalled, "8");
            tb.ProcessKeyPreviewCalled   = false;
            tb.ProcessKeyEventArgsCalled = false;

            /* test enter behavior */
            tb.IsInEditOrNavigateMode = true;
            m        = new Message();
            m.Msg    = 0x0100 /* WM_KEYDOWN */;
            m.WParam = (IntPtr)Keys.Enter;

            rv = tb.DoProcessKeyMessage(ref m);
            Assert.AreEqual(0x0100, m.Msg, "9");
            Assert.AreEqual(Keys.Enter, (Keys)m.WParam.ToInt32(), "10");
            Assert.IsFalse(rv, "11");
            Assert.IsTrue(tb.IsInEditOrNavigateMode, "12");
            Assert.IsTrue(tb.ProcessKeyPreviewCalled, "13");
            Assert.IsFalse(tb.ProcessKeyPreviewReturnValue, "14");
            Assert.IsFalse(tb.ProcessKeyEventArgsCalled, "15");
            tb.ProcessKeyPreviewCalled   = false;
            tb.ProcessKeyEventArgsCalled = false;

            /* test left behavior (within the string) */
            tb.IsInEditOrNavigateMode = true;
            tb.Text            = "hello world";
            tb.SelectionStart  = 5;
            tb.SelectionLength = 0;

            m        = new Message();
            m.Msg    = 0x0100 /* WM_KEYDOWN */;
            m.WParam = (IntPtr)Keys.Left;

            rv = tb.DoProcessKeyMessage(ref m);
            Assert.AreEqual(0x0100, m.Msg, "16");
            Assert.AreEqual(Keys.Left, (Keys)m.WParam.ToInt32(), "17");
            Assert.IsFalse(rv, "18");
            Assert.IsTrue(tb.IsInEditOrNavigateMode, "19");
            Assert.IsFalse(tb.ProcessKeyPreviewCalled, "20");
            Assert.IsTrue(tb.ProcessKeyEventArgsCalled, "21");
            Assert.IsFalse(tb.ProcessKeyEventArgsReturnValue, "21.5");
            tb.ProcessKeyPreviewCalled   = false;
            tb.ProcessKeyEventArgsCalled = false;

            /* test left behavior (at the left-most position) */
            tb.IsInEditOrNavigateMode = true;
            tb.Text            = "hello world";
            tb.SelectionStart  = 0;
            tb.SelectionLength = 0;

            m        = new Message();
            m.Msg    = 0x0100 /* WM_KEYDOWN */;
            m.WParam = (IntPtr)Keys.Left;

            rv = tb.DoProcessKeyMessage(ref m);
            Assert.AreEqual(0x0100, m.Msg, "22");
            Assert.AreEqual(Keys.Left, (Keys)m.WParam.ToInt32(), "23");
            Assert.IsFalse(rv, "24");
            Assert.IsTrue(tb.IsInEditOrNavigateMode, "25");
            Assert.IsTrue(tb.ProcessKeyPreviewCalled, "26");
            Assert.IsFalse(tb.ProcessKeyPreviewReturnValue, "26");
            Assert.IsFalse(tb.ProcessKeyEventArgsCalled, "27");
            tb.ProcessKeyPreviewCalled   = false;
            tb.ProcessKeyEventArgsCalled = false;

            /* test right behavior (within the string) */
            tb.IsInEditOrNavigateMode = true;
            tb.Text            = "hello world";
            tb.SelectionStart  = 5;
            tb.SelectionLength = 0;

            m        = new Message();
            m.Msg    = 0x0100 /* WM_KEYDOWN */;
            m.WParam = (IntPtr)Keys.Right;

            rv = tb.DoProcessKeyMessage(ref m);
            Assert.AreEqual(0x0100, m.Msg, "28");
            Assert.AreEqual(Keys.Right, (Keys)m.WParam.ToInt32(), "29");
            Assert.IsFalse(rv, "30");
            Assert.IsTrue(tb.IsInEditOrNavigateMode, "31");
            Assert.IsFalse(tb.ProcessKeyPreviewCalled, "32");
            Assert.IsTrue(tb.ProcessKeyEventArgsCalled, "33");
            Assert.IsFalse(tb.ProcessKeyEventArgsReturnValue, "33.5");
            tb.ProcessKeyPreviewCalled   = false;
            tb.ProcessKeyEventArgsCalled = false;

            /* test right behavior (at the left-most position) */
            tb.IsInEditOrNavigateMode = true;
            tb.Text            = "hello world";
            tb.SelectionStart  = tb.Text.Length;
            tb.SelectionLength = 0;

            m        = new Message();
            m.Msg    = 0x0100 /* WM_KEYDOWN */;
            m.WParam = (IntPtr)Keys.Right;

            rv = tb.DoProcessKeyMessage(ref m);
            Assert.AreEqual(0x0100, m.Msg, "34");
            Assert.AreEqual(Keys.Right, (Keys)m.WParam.ToInt32(), "35");
            Assert.IsFalse(rv, "36");
            Assert.IsTrue(tb.IsInEditOrNavigateMode, "37");
            Assert.IsTrue(tb.ProcessKeyPreviewCalled, "38");
            Assert.IsFalse(tb.ProcessKeyPreviewReturnValue, "39");
            Assert.IsFalse(tb.ProcessKeyEventArgsCalled, "40");
            tb.ProcessKeyPreviewCalled   = false;
            tb.ProcessKeyEventArgsCalled = false;

            /* test Tab behavior */
            tb.IsInEditOrNavigateMode = false;
            m        = new Message();
            m.Msg    = 0x0100 /* WM_KEYDOWN */;
            m.WParam = (IntPtr)Keys.Tab;

            rv = tb.DoProcessKeyMessage(ref m);
            Assert.AreEqual(0x0100, m.Msg, "41");
            Assert.AreEqual(Keys.Tab, (Keys)m.WParam.ToInt32(), "42");
            Assert.IsFalse(rv, "43");
            Assert.IsFalse(tb.IsInEditOrNavigateMode, "44");
            Assert.IsFalse(tb.ProcessKeyPreviewCalled, "45");
            Assert.IsTrue(tb.ProcessKeyEventArgsCalled, "46");
            Assert.IsFalse(tb.ProcessKeyEventArgsReturnValue, "46.5");
            tb.ProcessKeyPreviewCalled   = false;
            tb.ProcessKeyEventArgsCalled = false;

            /* test Up behavior */
            tb.IsInEditOrNavigateMode = false;
            m        = new Message();
            m.Msg    = 0x0100 /* WM_KEYDOWN */;
            m.WParam = (IntPtr)Keys.Up;

            rv = tb.DoProcessKeyMessage(ref m);
            Assert.AreEqual(0x0100, m.Msg, "47");
            Assert.AreEqual(Keys.Up, (Keys)m.WParam.ToInt32(), "48");
            Assert.IsFalse(rv, "49");
            Assert.IsFalse(tb.IsInEditOrNavigateMode, "50");
            Assert.IsTrue(tb.ProcessKeyPreviewCalled, "51");
            Assert.IsFalse(tb.ProcessKeyPreviewReturnValue, "52");
            Assert.IsFalse(tb.ProcessKeyEventArgsCalled, "53");
            tb.ProcessKeyPreviewCalled   = false;
            tb.ProcessKeyEventArgsCalled = false;

            /* test Down behavior */
            tb.IsInEditOrNavigateMode = false;
            m        = new Message();
            m.Msg    = 0x0100 /* WM_KEYDOWN */;
            m.WParam = (IntPtr)Keys.Down;

            rv = tb.DoProcessKeyMessage(ref m);
            Assert.AreEqual(0x0100, m.Msg, "54");
            Assert.AreEqual(Keys.Down, (Keys)m.WParam.ToInt32(), "55");
            Assert.IsFalse(rv, "56");
            Assert.IsFalse(tb.IsInEditOrNavigateMode, "57");
            Assert.IsTrue(tb.ProcessKeyPreviewCalled, "58");
            Assert.IsFalse(tb.ProcessKeyPreviewReturnValue, "59");
            Assert.IsFalse(tb.ProcessKeyEventArgsCalled, "60");
            tb.ProcessKeyPreviewCalled   = false;
            tb.ProcessKeyEventArgsCalled = false;
        }