Пример #1
0
        public void TranslateAcceleratorTest()
        {
            TestPage testPage = new TestPage();
            Mocks.TestHostingForm hostingForm = new PropertyPageBaseTest.Mocks.TestHostingForm();
            using (hostingForm)
            {
                hostingForm.CreateControl();
                RECT hostingRectangle;
                hostingRectangle.left = 0;
                hostingRectangle.top = 0;
                hostingRectangle.right = 100;
                hostingRectangle.bottom = 100;
                testPage.Activate(hostingForm.Handle, new RECT[] { hostingRectangle } , 0);
                TestIPageView pageView = testPage.MyPageView as TestIPageView;
                pageView.sampleChildHwnd = new IntPtr(10);
                pageView.outLParam = new IntPtr(11);
                pageView.outWParam = new IntPtr(12);

                MSG[] recognizedAcceleratorMessage = new MSG[] { new MSG() };
                recognizedAcceleratorMessage[0].hwnd = pageView.sampleChildHwnd;
                recognizedAcceleratorMessage[0].message = 1;
                recognizedAcceleratorMessage[0].wParam = new IntPtr(2);
                recognizedAcceleratorMessage[0].lParam = new IntPtr(3);

                int hr = testPage.TranslateAccelerator(recognizedAcceleratorMessage);
                Assert.AreEqual(VSConstants.S_OK, hr);
                Assert.AreEqual(pageView.outLParam, recognizedAcceleratorMessage[0].lParam);
                Assert.AreEqual(pageView.outWParam, recognizedAcceleratorMessage[0].wParam);

                MSG[] unrecognizedAcceleratorMessage = new MSG[] { new MSG() };
                unrecognizedAcceleratorMessage[0].hwnd = new IntPtr(100);
                unrecognizedAcceleratorMessage[0].message = 1;
                unrecognizedAcceleratorMessage[0].wParam = new IntPtr(2);
                unrecognizedAcceleratorMessage[0].lParam = new IntPtr(3);

                hr = testPage.TranslateAccelerator(unrecognizedAcceleratorMessage);
                Assert.AreEqual(VSConstants.S_FALSE, hr);
                Assert.AreEqual(new IntPtr(2), unrecognizedAcceleratorMessage[0].wParam);
                Assert.AreEqual(new IntPtr(3), unrecognizedAcceleratorMessage[0].lParam);
            }
        }